Skip to content

Commit 5b8ec68

Browse files
Merge pull request #3 from angular-package/0.0.x
1.0.0
2 parents 0798a00 + 1bc6002 commit 5b8ec68

File tree

6 files changed

+119
-55
lines changed

6 files changed

+119
-55
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](http://keepachangelog.com/)
6+
and this project adheres to [Semantic Versioning](http://semver.org/).
7+
8+
## [1.0.0] - 2022-02-02
9+
10+
### [1.0.0] Changed
11+
12+
- Changed the parameters default values of `isWrapped()` instance method to private `#opening` and `#closing`. [44bd1f5]
13+
- Changed the default values of the `opening` and `closing` parameters in the static `unwrap()` method by removing them. [d8d0f4b]
14+
- Changed the default value for the generic type variable `Text` of the `isWrapper()` static method to `string`. [d8d0f4b]
15+
- Changed the `toStringTag` name from the `wrapper` to `Wrapper`. [d8d0f4b]
16+
- Changed the `toStringTag` name from the `wrap` to `Wrap`. [4049e2e]
17+
18+
[44bd1f5]: https://github.com/angular-package/wrapper/commit/44bd1f54d82700440012caa5414a02ff8687ffb2
19+
[d8d0f4b]: https://github.com/angular-package/wrapper/commit/d8d0f4bb029395a2de180fc38246a9ea81d7eb58
20+
[4049e2e]: https://github.com/angular-package/wrapper/commit/4049e2ea09104ac155bf7b385789b40ca7b923c1

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "@angular-package/wrapper",
3-
"version": "0.0.1",
3+
"version": "1.0.0",
44
"description": "Wrap the text with the opening and closing chars.",
55
"author": "Angular Package <contact@angular-package.dev> (https://angular-package.dev)",
6-
"homepage": "https://github.com/angular-package/wrapper#readme",
6+
"homepage": "https://wrapper.angular-package.dev/",
77
"dependencies": {
88
"tslib": "^2.3.0"
99
},
@@ -30,4 +30,4 @@
3030
"url": "https://github.com/angular-package/wrapper/issues"
3131
},
3232
"license": "MIT"
33-
}
33+
}

src/lib/wrap.class.ts

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
2-
* The `Wrap` object represents the immutable text wrapped by the opening and closing chars. It is designed to preserve the names of the
3-
* opening, text and closing.
2+
* The `Wrap` object is based on the `String` object and represents the immutable primitive value of the text wrapped by the opening and
3+
* closing chars. It is designed to preserve the type names of the supplied opening, text, and closing chars by using the generic type
4+
* variables.
45
*/
56
export class Wrap<
67
Opening extends string = string,
@@ -42,7 +43,7 @@ export class Wrap<
4243
* @angularpackage
4344
*/
4445
public get [Symbol.toStringTag](): string {
45-
return 'wrap';
46+
return 'Wrap';
4647
}
4748
//#endregion instance public accessors.
4849

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

5556
/**
56-
* Private property of text of a generic type variable `Text`.
57+
* Private property of the opening chars of a generic type variable `Opening`.
5758
*/
58-
#text: Text;
59+
#opening: Opening;
5960

6061
/**
61-
* Private property of the opening chars of a generic type variable `Opening`.
62+
* Private property of text of a generic type variable `Text`.
6263
*/
63-
#opening: Opening;
64-
//#endregion instance private properties.
64+
#text: Text;
65+
//#endregion instance private properties.
6566

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

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

187190
/**
188-
* Checks whether the primitive value of a specified object has the opening chars or given opening chars. An empty `string` indicates
189-
* `undefined`.
190-
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the beginning.
191-
* @returns The return value is a `boolean` indicating whether the primitive value has the opening chars.
191+
* Checks whether the primitive value of a specified object has the opening chars or given `opening` chars. If given `opening` chars in
192+
* the constructor are the empty `string`, the method returns `false`.
193+
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the **beginning**.
194+
* @returns The return value is a `boolean` indicating whether the primitive value has the opening chars or given `opening` chars.
192195
* @angularpackage
193196
*/
194197
public hasOpening(opening?: string): boolean {
@@ -202,7 +205,7 @@ export class Wrap<
202205
* 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
203206
* optionally equal to the given `text`.
204207
* @param text Optional text of `string` type to check whether it's equal to the text of the `Wrap` object.
205-
* @returns The return value is a `boolean` indicating whether the text is defined and equal to the optionally given text.
208+
* @returns The return value is a `boolean` indicating whether the text is defined and optionally equal to the given text.
206209
* @angularpackage
207210
*/
208211
public hasText(text?: string): boolean {
@@ -213,16 +216,20 @@ export class Wrap<
213216
}
214217

215218
/**
216-
* The method checks whether the primitive value of the specified object is wrapped by the opening and closing chars of an instance or
217-
* given opening and closing chars.
218-
* @param opening Optional opening chars of a `string` type to check if the text contains them at the beginning.
219-
* @param closing Optional closing chars of a `string` type to check if the text contains them at the end.
220-
* @returns The return value is a `boolean` indicating whether the object has both opening and closing chars.
219+
* The method checks whether the primitive value of the specified `object` is wrapped by the opening and closing chars of an instance or
220+
* given `opening` and `closing` chars. If given `opening` or `closing` chars in the constructor are the empty `string`, the method
221+
* returns `false`.
222+
* @param opening Optional opening chars of a `string` type to check if the primitive value contains them at the beginning. The default
223+
* value is picked from the private `#opening` property of an instance.
224+
* @param closing Optional closing chars of a `string` type to check if the primitive value contains them at the end. The default value is
225+
* picked from the private `#closing` property of an instance.
226+
* @returns The return value is a `boolean` indicating whether the object has both opening and closing chars or given `opening` and
227+
* `closing` chars.
221228
* @angularpackage
222229
*/
223230
public isWrapped(
224-
opening: string = this.opening,
225-
closing: string = this.closing
231+
opening: string = this.#opening,
232+
closing: string = this.#closing
226233
): boolean {
227234
return this.hasOpening(opening) && this.hasClosing(closing);
228235
}

src/lib/wrapper.class.ts

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class Wrapper<
1717
* `typeOf()` function of `@angular-package/type`.
1818
*/
1919
public get [Symbol.toStringTag](): string {
20-
return 'wrapper';
20+
return 'Wrapper';
2121
}
2222
//#endregion instance accessors.
2323

@@ -43,7 +43,7 @@ export class Wrapper<
4343
}
4444

4545
/**
46-
* 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.
46+
* 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`.
4747
* @param value The value of any type to test against the `Wrapper` instance.
4848
* @param opening Optional opening chars of generic type variable `Opening` to check if the given `value` contains.
4949
* @param closing Optional closing chars of generic type variable `Closing` to check if the given `value` contains.
@@ -55,7 +55,7 @@ export class Wrapper<
5555
public static isWrapper<
5656
Opening extends string,
5757
Closing extends string,
58-
Text extends string = ''
58+
Text extends string = string
5959
>(
6060
value: any,
6161
opening?: Opening,
@@ -70,11 +70,12 @@ export class Wrapper<
7070
}
7171

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

9091
/**
91-
* Replaces the opening chars in a given `text` with a given replacement value at the beginning of the text.
92+
* Replaces given `opening` chars with a given replacement value at the beginning of the given `text`.
9293
* @param text The text of `string` type in which the given `opening` chars are replaced by a given replacement value.
9394
* @param opening The opening chars of the `string` to replace by a given replacement value at the beginning of the given `text`.
94-
* @param replaceValue Replacement value for the `opening` characters in the given `text`.
95-
* @returns The return value is the text of `string` type with a replaced opening chars by a given replacement value.
95+
* @param replaceValue The replacement value of a string type for the given `opening` characters in the given `text`.
96+
* @returns The return value is the given `text` of `string` type with a replaced `opening` chars by a given replacement value or the
97+
* specified `text` unchanged if it does not contain the given `opening` chars.
9698
* @angularpackage
9799
*/
98100
public static replaceOpening(
@@ -106,14 +108,15 @@ export class Wrapper<
106108
}
107109

108110
/**
109-
* The method returns the text without the given `opening` and `closing` chars.
111+
* The method returns the given `text` without the given `opening` and `closing` chars.
110112
* @param text The text of the `string` from which given opening and closing chars are removed.
111113
* @param opening The opening chars of the `string` to be removed in the given `text`.
112114
* @param closing The closing chars of the `string` to be removed in the given `text`.
113-
* @returns The return value is the text of string type without the given opening and closing chars.
115+
* @returns The return value is the given `text` of `string` type without the given `opening` and `closing` chars or unchanged `text` if
116+
* it does not contain the given `opening` and `closing` chars.
114117
* @angularpackage
115118
*/
116-
public static unwrap(text: string, opening = '', closing = ''): string {
119+
public static unwrap(text: string, opening: string, closing: string): string {
117120
return (
118121
(text = this.replaceClosing(text, closing, '')),
119122
(text = this.replaceOpening(text, opening, '')),
@@ -162,7 +165,7 @@ export class Wrapper<
162165
* The replacement succeeds if the closing characters exist at the end of the text.
163166
* @param text The text of `string` type in which the closing chars are replaced by given replacement value.
164167
* @param replaceValue The value of `string` type as a replacement for the closing chars at the end of the given `text`.
165-
* @returns The return value is the text of `string` type with replaced closing chars by given replacement value.
168+
* @returns The return value is the given `text` of `string` type with replaced closing chars by given replacement value.
166169
* @angularpackage
167170
*/
168171
public replaceClosingIn(text: string, replaceValue: string): string {
@@ -174,7 +177,7 @@ export class Wrapper<
174177
* The replacement succeeds if the opening characters exist at the beginning of the text.
175178
* @param text The text of `string` type in which the opening chars are replaced by given replacement value.
176179
* @param replaceValue The value of `string` type as a replacement for the opening chars at the beginning of the given `text`.
177-
* @returns The return value is the text of `string` type with replaced opening chars by given replacement value.
180+
* @returns The return value is the given `text` of `string` type with replaced opening chars by given replacement value.
178181
* @angularpackage
179182
*/
180183
public replaceOpeningIn(text: string, replaceValue: string): string {
@@ -183,7 +186,7 @@ export class Wrapper<
183186

184187
/**
185188
* Returns given `text` without the opening and closing chars of the `Wrapper` object.
186-
* @param text The text of a `string` type to unwrap with the opening and closing chars of the `Wrapper` object.
189+
* @param text The text of a `string` type to unwrap from the opening and closing chars of the `Wrapper` object.
187190
* @returns The return value is the text of `string` type unwrapped from the opening and closing chars of the `Wrapper` object.
188191
* @angularpackage
189192
*/
@@ -210,7 +213,7 @@ export class Wrapper<
210213
* Replaces the opening chars of the `Wrapper` object in the text of the `Wrapper` object with the given `opening` chars. The replacement
211214
* succeeds if the opening characters exist at the beginning of the text.
212215
* @param opening The opening chars of `string` to replace in the text(part of the primitive value).
213-
* @returns The return value is the text of string type with replaced opening chars.
216+
* @returns The return value is the text of `string` type with replaced opening chars.
214217
* @angularpackage
215218
*/
216219
public textReplaceOpening(opening: string): string {
@@ -276,8 +279,8 @@ export class Wrapper<
276279
}
277280

278281
/**
279-
* The method returns the primitive value of a specified `Wrapper` object with text unwrapped from its opening and closing chars or given
280-
* `opening` and `closing` chars.
282+
* The method returns the primitive value of a specified `Wrapper` object with text unwrapped from the opening and closing chars of the
283+
* `Wrapper` instance or given `opening` and `closing` chars.
281284
* @param opening Optional opening chars of `string` type to remove from the beginning of the text of the `Wrapper` instance. By default,
282285
* its value is equal to the opening chars of the `Wrapper` instance.
283286
* @param closing Optional closing chars of `string` type to remove from the end of the text of the `Wrapper` instance. By default, its
@@ -299,10 +302,11 @@ export class Wrapper<
299302
* The method wraps the primitive value of a specified `Wrapper` object by its opening and closing chars or given `opening` and `closing`
300303
* chars.
301304
* @param opening Optional opening chars of a generic type variable `CustomOpening` to wrap the primitive value of the `Wrapper` instance.
302-
* By default, its value is equal to the closing chars of the `Wrapper` instance.
305+
* By default, its value is equal to the opening chars of the `Wrapper` instance.
303306
* @param closing Optional closing chars of a generic type variable `CustomClosing` to wrap the primitive value of the `Wrapper` instance.
304307
* By default, its value is equal to the closing chars of the `Wrapper` instance.
305-
* @returns The return value is a primitive value wrapped by the given opening and closing chars or from the `Wrapper` instance.
308+
* @returns The return value is a primitive value wrapped by the opening and closing chars of the `Wrapper` instance or the given
309+
* `opening` and `closing` chars.
306310
* @angularpackage
307311
*/
308312
public wrap<
@@ -316,9 +320,10 @@ export class Wrapper<
316320
}
317321

318322
/**
319-
* Wraps given text with the wrap, the opening, and closing chars of the `Wrapper` object.
323+
* The method wraps the given `text` with the wrap, the `opening`, and `closing` chars of the `Wrapper` object.
320324
* @param text The text of generic type variable `CustomText` to wrap by the opening and closing chars of the `Wrapper` instance.
321-
* @returns The return value is the text wrapped by the opening and closing chars of the `Wrapper` object of the generic type `Wrapped`.
325+
* @returns The return value is the given `text` wrapped by the opening and closing chars of the `Wrapper` object of the generic type
326+
* `Wrapped`.
322327
* @angularpackage
323328
*/
324329
public wrapOn<CustomText extends string = ''>(

0 commit comments

Comments
 (0)