Skip to content
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
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Change Log

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.0.0] - 2022-02-02

### [1.0.0] Changed

- Changed the parameters default values of `isWrapped()` instance method to private `#opening` and `#closing`. [44bd1f5]
- Changed the default values of the `opening` and `closing` parameters in the static `unwrap()` method by removing them. [d8d0f4b]
- Changed the default value for the generic type variable `Text` of the `isWrapper()` static method to `string`. [d8d0f4b]
- Changed the `toStringTag` name from the `wrapper` to `Wrapper`. [d8d0f4b]
- Changed the `toStringTag` name from the `wrap` to `Wrap`. [4049e2e]

[44bd1f5]: https://github.com/angular-package/wrapper/commit/44bd1f54d82700440012caa5414a02ff8687ffb2
[d8d0f4b]: https://github.com/angular-package/wrapper/commit/d8d0f4bb029395a2de180fc38246a9ea81d7eb58
[4049e2e]: https://github.com/angular-package/wrapper/commit/4049e2ea09104ac155bf7b385789b40ca7b923c1
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "@angular-package/wrapper",
"version": "0.0.1",
"version": "1.0.0",
"description": "Wrap the text with the opening and closing chars.",
"author": "Angular Package <[email protected]> (https://angular-package.dev)",
"homepage": "https://github.com/angular-package/wrapper#readme",
"homepage": "https://wrapper.angular-package.dev/",
"dependencies": {
"tslib": "^2.3.0"
},
Expand All @@ -30,4 +30,4 @@
"url": "https://github.com/angular-package/wrapper/issues"
},
"license": "MIT"
}
}
59 changes: 33 additions & 26 deletions src/lib/wrap.class.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* 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.
* The `Wrap` object is based on the `String` object and represents the immutable primitive value of the text wrapped by the opening and
* closing chars. It is designed to preserve the type names of the supplied opening, text, and closing chars by using the generic type
* variables.
*/
export class Wrap<
Opening extends string = string,
Expand Down Expand Up @@ -42,7 +43,7 @@ export class Wrap<
* @angularpackage
*/
public get [Symbol.toStringTag](): string {
return 'wrap';
return 'Wrap';
}
//#endregion instance public accessors.

Expand All @@ -53,15 +54,15 @@ export class Wrap<
#closing: Closing;

/**
* Private property of text of a generic type variable `Text`.
* Private property of the opening chars of a generic type variable `Opening`.
*/
#text: Text;
#opening: Opening;

/**
* Private property of the opening chars of a generic type variable `Opening`.
* Private property of text of a generic type variable `Text`.
*/
#opening: Opening;
//#endregion instance private properties.
#text: Text;
//#endregion instance private properties.

//#region static public methods.
/**
Expand Down Expand Up @@ -129,8 +130,10 @@ export class Wrap<
//#region constructor.
/**
* Creates a new `Wrap` instance of the opening and closing chars and optional text to wrap.
* @param opening Opening characters of the generic type variable `Opening` placed before the given `text`.
* @param closing Closing characters of the generic type variable `Closing` placed after the given `text`.
* @param opening Opening characters of the generic type variable `Opening` placed before the given `text`. An empty `string` indicates
* that for the `hasOpening()` and `isWrapped()` methods, the opening chars are `undefined`, returning `false`.
* @param closing Closing characters of the generic type variable `Closing` placed after the given `text`. An empty `string` indicates
* that for the `hasClosing()` and `isWrapped()` methods, the closing chars are `undefined`, returning `false`.
* @param text An optional text placed between the given `opening` and `closing` chars on the template `${Opening}${Text}${Closing}`.
* @angularpackage
*/
Expand Down Expand Up @@ -171,10 +174,10 @@ export class Wrap<
}

/**
* Checks whether the primitive value of a specified object has the closing chars or given closing chars. An empty `string` indicates
* `undefined`.
* @param closing Optional closing chars of a `string` type to check whether the primitive value contains them at the end.
* @returns The return value is a `boolean` indicating whether the primitive value has the closing chars.
* Checks whether the primitive value of a specified object has the closing chars or given `closing` chars. If given `closing` chars in
* the constructor are the empty `string`, the method returns `false`.
* @param closing Optional closing chars of a `string` type to check whether the primitive value contains them at the **end**.
* @returns The return value is a `boolean` indicating whether the primitive value has the closing chars or given closing chars.
* @angularpackage
*/
public hasClosing(closing?: string): boolean {
Expand All @@ -185,10 +188,10 @@ export class Wrap<
}

/**
* Checks whether the primitive value of a specified object has the opening chars or given opening chars. An empty `string` indicates
* `undefined`.
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the beginning.
* @returns The return value is a `boolean` indicating whether the primitive value has the opening chars.
* Checks whether the primitive value of a specified object has the opening chars or given `opening` chars. If given `opening` chars in
* the constructor are the empty `string`, the method returns `false`.
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the **beginning**.
* @returns The return value is a `boolean` indicating whether the primitive value has the opening chars or given `opening` chars.
* @angularpackage
*/
public hasOpening(opening?: string): boolean {
Expand All @@ -202,7 +205,7 @@ export class Wrap<
* The method checks whether the text of a specified `Wrap` object is defined, which means it's a `string` of at least one char and
* optionally equal to the given `text`.
* @param text Optional text of `string` type to check whether it's equal to the text of the `Wrap` object.
* @returns The return value is a `boolean` indicating whether the text is defined and equal to the optionally given text.
* @returns The return value is a `boolean` indicating whether the text is defined and optionally equal to the given text.
* @angularpackage
*/
public hasText(text?: string): boolean {
Expand All @@ -213,16 +216,20 @@ export class Wrap<
}

/**
* The method checks whether the primitive value of the specified object is wrapped by the opening and closing chars of an instance or
* given opening and closing chars.
* @param opening Optional opening chars of a `string` type to check if the text contains them at the beginning.
* @param closing Optional closing chars of a `string` type to check if the text contains them at the end.
* @returns The return value is a `boolean` indicating whether the object has both opening and closing chars.
* The method checks whether the primitive value of the specified `object` is wrapped by the opening and closing chars of an instance or
* given `opening` and `closing` chars. If given `opening` or `closing` chars in the constructor are the empty `string`, the method
* returns `false`.
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the beginning. The default
* value is picked from the private `#opening` property of an instance.
* @param closing Optional closing chars of a `string` type to check if the primitive value contains them at the end. The default value is
* picked from the private `#closing` property of an instance.
* @returns The return value is a `boolean` indicating whether the object has both opening and closing chars or given `opening` and
* `closing` chars.
* @angularpackage
*/
public isWrapped(
opening: string = this.opening,
closing: string = this.closing
opening: string = this.#opening,
closing: string = this.#closing
): boolean {
return this.hasOpening(opening) && this.hasClosing(closing);
}
Expand Down
49 changes: 27 additions & 22 deletions src/lib/wrapper.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class Wrapper<
* `typeOf()` function of `@angular-package/type`.
*/
public get [Symbol.toStringTag](): string {
return 'wrapper';
return 'Wrapper';
}
//#endregion instance accessors.

Expand All @@ -43,7 +43,7 @@ export class Wrapper<
}

/**
* The method checks if the value of any type is an instance of the `Wrapper` of any, or the given opening, closing chars, and text.
* The method checks if the value of any type is an instance of the `Wrapper` of any, or the given `opening`, `closing` chars, and `text`.
* @param value The value of any type to test against the `Wrapper` instance.
* @param opening Optional opening chars of generic type variable `Opening` to check if the given `value` contains.
* @param closing Optional closing chars of generic type variable `Closing` to check if the given `value` contains.
Expand All @@ -55,7 +55,7 @@ export class Wrapper<
public static isWrapper<
Opening extends string,
Closing extends string,
Text extends string = ''
Text extends string = string
>(
value: any,
opening?: Opening,
Expand All @@ -70,11 +70,12 @@ export class Wrapper<
}

/**
* Replaces the closing chars in a given `text` with a given replacement value at the end of the text.
* Replaces given `closing` chars with a given replacement value at the end of the given `text`.
* @param text The text of `string` type in which given `closing` characters are replaced by a given replacement value.
* @param closing The closing chars of the `string` to replace by a given replacement value at the end of the given `text`.
* @param replaceValue Replacement value for the given `closing` characters in the given `text`.
* @returns The return value is the text of `string` type with a replaced closing chars by a given replacement value.
* @param replaceValue The replacement value of a string type for the given `closing` characters in the given `text`.
* @returns The return value is the given `text` of `string` type with a replaced `closing` chars by a given replacement value or the
* specified `text` unchanged if it does not contain the given `closing` chars.
* @angularpackage
*/
public static replaceClosing(
Expand All @@ -88,11 +89,12 @@ export class Wrapper<
}

/**
* Replaces the opening chars in a given `text` with a given replacement value at the beginning of the text.
* Replaces given `opening` chars with a given replacement value at the beginning of the given `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`.
* @returns The return value is the text of `string` type with a replaced opening chars by a given replacement value.
* @param replaceValue The replacement value of a string type for the given `opening` characters in the given `text`.
* @returns The return value is the given `text` of `string` type with a replaced `opening` chars by a given replacement value or the
* specified `text` unchanged if it does not contain the given `opening` chars.
* @angularpackage
*/
public static replaceOpening(
Expand All @@ -106,14 +108,15 @@ export class Wrapper<
}

/**
* The method returns the text without the given `opening` and `closing` chars.
* The method returns the given `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`.
* @returns The return value is the text of string type without the given opening and closing chars.
* @returns The return value is the given `text` of `string` type without the given `opening` and `closing` chars or unchanged `text` if
* it does not contain the given `opening` and `closing` chars.
* @angularpackage
*/
public static unwrap(text: string, opening = '', closing = ''): string {
public static unwrap(text: string, opening: string, closing: string): string {
return (
(text = this.replaceClosing(text, closing, '')),
(text = this.replaceOpening(text, opening, '')),
Expand Down Expand Up @@ -162,7 +165,7 @@ export class Wrapper<
* The replacement succeeds if the closing characters exist at the end of the text.
* @param text The text of `string` type in which the closing chars are replaced by given replacement value.
* @param replaceValue The value of `string` type as a replacement for the closing chars at the end of the given `text`.
* @returns The return value is the text of `string` type with replaced closing chars by given replacement value.
* @returns The return value is the given `text` of `string` type with replaced closing chars by given replacement value.
* @angularpackage
*/
public replaceClosingIn(text: string, replaceValue: string): string {
Expand All @@ -174,7 +177,7 @@ export class Wrapper<
* The replacement succeeds if the opening characters exist at the beginning of the text.
* @param text The text of `string` type in which the opening chars are replaced by given replacement value.
* @param replaceValue The value of `string` type as a replacement for the opening chars at the beginning of the given `text`.
* @returns The return value is the text of `string` type with replaced opening chars by given replacement value.
* @returns The return value is the given `text` of `string` type with replaced opening chars by given replacement value.
* @angularpackage
*/
public replaceOpeningIn(text: string, replaceValue: string): string {
Expand All @@ -183,7 +186,7 @@ export class Wrapper<

/**
* Returns given `text` without the opening and closing chars of the `Wrapper` object.
* @param text The text of a `string` type to unwrap with the opening and closing chars of the `Wrapper` object.
* @param text The text of a `string` type to unwrap from the opening and closing chars of the `Wrapper` object.
* @returns The return value is the text of `string` type unwrapped from the opening and closing chars of the `Wrapper` object.
* @angularpackage
*/
Expand All @@ -210,7 +213,7 @@ export class Wrapper<
* Replaces the opening chars of the `Wrapper` object in the text of the `Wrapper` object with the given `opening` chars. The replacement
* succeeds if the opening characters exist at the beginning of the text.
* @param opening The opening chars of `string` to replace in the text(part of the primitive value).
* @returns The return value is the text of string type with replaced opening chars.
* @returns The return value is the text of `string` type with replaced opening chars.
* @angularpackage
*/
public textReplaceOpening(opening: string): string {
Expand Down Expand Up @@ -276,8 +279,8 @@ export class Wrapper<
}

/**
* The method returns the primitive value of a specified `Wrapper` object with text unwrapped from its opening and closing chars or given
* `opening` and `closing` chars.
* The method returns the primitive value of a specified `Wrapper` object with text unwrapped from the opening and closing chars of the
* `Wrapper` instance or given `opening` and `closing` chars.
* @param opening Optional opening chars of `string` type to remove from the beginning of the text of the `Wrapper` instance. By default,
* its value is equal to the opening chars of the `Wrapper` instance.
* @param closing Optional closing chars of `string` type to remove from the end of the text of the `Wrapper` instance. By default, its
Expand All @@ -299,10 +302,11 @@ export class Wrapper<
* The method wraps the primitive value of a specified `Wrapper` object by its opening and closing chars or given `opening` and `closing`
* chars.
* @param opening Optional opening chars of a generic type variable `CustomOpening` to wrap the primitive value of the `Wrapper` instance.
* By default, its value is equal to the closing chars of the `Wrapper` instance.
* By default, its value is equal to the opening chars of the `Wrapper` instance.
* @param closing Optional closing chars of a generic type variable `CustomClosing` to wrap the primitive value of the `Wrapper` instance.
* By default, its value is equal to the closing chars of the `Wrapper` instance.
* @returns The return value is a primitive value wrapped by the given opening and closing chars or from the `Wrapper` instance.
* @returns The return value is a primitive value wrapped by the opening and closing chars of the `Wrapper` instance or the given
* `opening` and `closing` chars.
* @angularpackage
*/
public wrap<
Expand All @@ -316,9 +320,10 @@ export class Wrapper<
}

/**
* Wraps given text with the wrap, the opening, and closing chars of the `Wrapper` object.
* The method wraps the given `text` with the wrap, the `opening`, and `closing` chars of the `Wrapper` object.
* @param text The text of generic type variable `CustomText` to wrap by the opening and closing chars of the `Wrapper` instance.
* @returns The return value is the text wrapped by the opening and closing chars of the `Wrapper` object of the generic type `Wrapped`.
* @returns The return value is the given `text` wrapped by the opening and closing chars of the `Wrapper` object of the generic type
* `Wrapped`.
* @angularpackage
*/
public wrapOn<CustomText extends string = ''>(
Expand Down
Loading