diff --git a/package.json b/package.json index b44d5cb..a79dcf2 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,12 @@ "description": "Wrap the text with the opening and closing chars.", "author": "Angular Package (https://angular-package.dev)", "homepage": "https://github.com/angular-package/wrapper#readme", - "peerDependencies": { - "@angular-package/type": "^5.0.0" - }, "dependencies": { "tslib": "^2.3.0" }, "devDependencies": { - "@angular-package/testing": "^2.0.0" + "@angular-package/testing": "^2.0.0", + "@angular-package/type": "^5.0.0" }, "publishConfig": { "access": "public", diff --git a/src/lib/wrap.class.ts b/src/lib/wrap.class.ts index 836c08f..be59ee6 100644 --- a/src/lib/wrap.class.ts +++ b/src/lib/wrap.class.ts @@ -1,9 +1,3 @@ -// @angular-package/type. -import { - isStringLength, - isStringType, - isInstance, -} from '@angular-package/type'; /** * The `Wrap` object represents the immutable text wrapped by the opening and closing chars. It is designed to preserve the names of the * opening, text and closing. @@ -79,8 +73,10 @@ export class Wrap< */ public static hasClosing(text: string, closing: string): boolean { return ( - isStringLength(text, { min: 1 }) && - isStringLength(closing, { min: 1 }) && + typeof text === 'string' && + text.length >= 1 && + typeof closing === 'string' && + closing.length >= 1 && text.slice(-closing.length) === closing ); } @@ -94,8 +90,10 @@ export class Wrap< */ public static hasOpening(text: string, opening: string): boolean { return ( - isStringLength(text, { min: 1 }) && - isStringLength(opening, { min: 1 }) && + typeof text === 'string' && + text.length >= 1 && + typeof opening === 'string' && + opening.length >= 1 && text.slice(0, opening.length) === opening ); } @@ -120,10 +118,10 @@ export class Wrap< closing?: Closing, text?: Text ): value is Wrap { - return isInstance(value, this) - ? (isStringType(opening) ? opening === value.opening : true) && - (isStringType(closing) ? closing === value.closing : true) && - (isStringType(text) ? text === value.text : true) + return typeof value === 'object' && value instanceof this + ? (typeof opening === 'string' ? opening === value.opening : true) && + (typeof closing === 'string' ? closing === value.closing : true) && + (typeof text === 'string' ? text === value.text : true) : false; } //#endregion static public methods. @@ -181,8 +179,8 @@ export class Wrap< */ public hasClosing(closing?: string): boolean { return ( - isStringLength(this.#closing, { min: 1 }) && - (isStringType(closing) ? this.#closing === closing : true) + this.#closing.length >= 1 && + (typeof closing === 'string' ? this.#closing === closing : true) ); } @@ -195,8 +193,8 @@ export class Wrap< */ public hasOpening(opening?: string): boolean { return ( - isStringLength(this.#opening, { min: 1 }) && - (isStringType(opening) ? this.#opening === opening : true) + this.#opening.length >= 1 && + (typeof opening === 'string' ? this.#opening === opening : true) ); } @@ -209,8 +207,8 @@ export class Wrap< */ public hasText(text?: string): boolean { return ( - isStringLength(this.#text, { min: 1 }) && - (isStringType(text) ? this.#text === text : true) + this.#text.length >= 1 && + (typeof text === 'string' ? this.#text === text : true) ); } diff --git a/src/lib/wrapper.class.ts b/src/lib/wrapper.class.ts index a4a8b94..e104897 100644 --- a/src/lib/wrapper.class.ts +++ b/src/lib/wrapper.class.ts @@ -1,12 +1,10 @@ -// @angular-package/type. -import { isInstance } from '@angular-package/type'; // Class. import { Wrap } from './wrap.class'; // Type. import { Wrapped } from '../type/wrapped.type'; /** * The `Wrapper` is an extension of the `Wrap` object, which means it represents the immutable wrap of the opening and closing with the - * additional ability to use it to wrap. + * additional ability to use it to wrap strings. */ export class Wrapper< Opening extends string = string, @@ -65,7 +63,9 @@ export class Wrapper< text?: Text ): value is Wrapper { return ( - isInstance(value, this) && super.isWrap(value, opening, closing, text) + typeof value === 'object' && + value instanceof this && + super.isWrap(value, opening, closing, text) ); } @@ -88,7 +88,7 @@ export class Wrapper< } /** - * Replaces the opening chars in a given `text` with a given replacement value at the end of the text. + * Replaces the opening chars in a given `text` with a given replacement value at the beginning of the text. * @param text The text of `string` type in which the given `opening` chars are replaced by a given replacement value. * @param opening The opening chars of the `string` to replace by a given replacement value at the beginning of the given `text`. * @param replaceValue Replacement value for the `opening` characters in the given `text`. @@ -106,7 +106,7 @@ export class Wrapper< } /** - * The method returns the text without the given opening and closing chars. + * The method returns the text without the given `opening` and `closing` chars. * @param text The text of the `string` from which given opening and closing chars are removed. * @param opening The opening chars of the `string` to be removed in the given `text`. * @param closing The closing chars of the `string` to be removed in the given `text`.