Skip to content

0.0.x #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
"description": "Wrap the text with the opening and closing chars.",
"author": "Angular Package <contact@angular-package.dev> (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",
Expand Down
38 changes: 18 additions & 20 deletions src/lib/wrap.class.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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
);
}
Expand All @@ -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
);
}
Expand All @@ -120,10 +118,10 @@ export class Wrap<
closing?: Closing,
text?: Text
): value is Wrap<Opening, Text, Closing> {
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.
Expand Down Expand Up @@ -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)
);
}

Expand All @@ -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)
);
}

Expand All @@ -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)
);
}

Expand Down
12 changes: 6 additions & 6 deletions src/lib/wrapper.class.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -65,7 +63,9 @@ export class Wrapper<
text?: Text
): value is Wrapper<Opening, Text, Closing> {
return (
isInstance(value, this) && super.isWrap(value, opening, closing, text)
typeof value === 'object' &&
value instanceof this &&
super.isWrap(value, opening, closing, text)
);
}

Expand All @@ -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`.
Expand All @@ -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`.
Expand Down