Skip to content

Commit 0798a00

Browse files
Merge pull request #2 from angular-package/0.0.x
0.0.x
2 parents 174530d + a8d13c6 commit 0798a00

File tree

3 files changed

+26
-30
lines changed

3 files changed

+26
-30
lines changed

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
"description": "Wrap the text with the opening and closing chars.",
55
"author": "Angular Package <contact@angular-package.dev> (https://angular-package.dev)",
66
"homepage": "https://github.com/angular-package/wrapper#readme",
7-
"peerDependencies": {
8-
"@angular-package/type": "^5.0.0"
9-
},
107
"dependencies": {
118
"tslib": "^2.3.0"
129
},
1310
"devDependencies": {
14-
"@angular-package/testing": "^2.0.0"
11+
"@angular-package/testing": "^2.0.0",
12+
"@angular-package/type": "^5.0.0"
1513
},
1614
"publishConfig": {
1715
"access": "public",

src/lib/wrap.class.ts

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
// @angular-package/type.
2-
import {
3-
isStringLength,
4-
isStringType,
5-
isInstance,
6-
} from '@angular-package/type';
71
/**
82
* The `Wrap` object represents the immutable text wrapped by the opening and closing chars. It is designed to preserve the names of the
93
* opening, text and closing.
@@ -79,8 +73,10 @@ export class Wrap<
7973
*/
8074
public static hasClosing(text: string, closing: string): boolean {
8175
return (
82-
isStringLength(text, { min: 1 }) &&
83-
isStringLength(closing, { min: 1 }) &&
76+
typeof text === 'string' &&
77+
text.length >= 1 &&
78+
typeof closing === 'string' &&
79+
closing.length >= 1 &&
8480
text.slice(-closing.length) === closing
8581
);
8682
}
@@ -94,8 +90,10 @@ export class Wrap<
9490
*/
9591
public static hasOpening(text: string, opening: string): boolean {
9692
return (
97-
isStringLength(text, { min: 1 }) &&
98-
isStringLength(opening, { min: 1 }) &&
93+
typeof text === 'string' &&
94+
text.length >= 1 &&
95+
typeof opening === 'string' &&
96+
opening.length >= 1 &&
9997
text.slice(0, opening.length) === opening
10098
);
10199
}
@@ -120,10 +118,10 @@ export class Wrap<
120118
closing?: Closing,
121119
text?: Text
122120
): value is Wrap<Opening, Text, Closing> {
123-
return isInstance(value, this)
124-
? (isStringType(opening) ? opening === value.opening : true) &&
125-
(isStringType(closing) ? closing === value.closing : true) &&
126-
(isStringType(text) ? text === value.text : true)
121+
return typeof value === 'object' && value instanceof this
122+
? (typeof opening === 'string' ? opening === value.opening : true) &&
123+
(typeof closing === 'string' ? closing === value.closing : true) &&
124+
(typeof text === 'string' ? text === value.text : true)
127125
: false;
128126
}
129127
//#endregion static public methods.
@@ -181,8 +179,8 @@ export class Wrap<
181179
*/
182180
public hasClosing(closing?: string): boolean {
183181
return (
184-
isStringLength(this.#closing, { min: 1 }) &&
185-
(isStringType(closing) ? this.#closing === closing : true)
182+
this.#closing.length >= 1 &&
183+
(typeof closing === 'string' ? this.#closing === closing : true)
186184
);
187185
}
188186

@@ -195,8 +193,8 @@ export class Wrap<
195193
*/
196194
public hasOpening(opening?: string): boolean {
197195
return (
198-
isStringLength(this.#opening, { min: 1 }) &&
199-
(isStringType(opening) ? this.#opening === opening : true)
196+
this.#opening.length >= 1 &&
197+
(typeof opening === 'string' ? this.#opening === opening : true)
200198
);
201199
}
202200

@@ -209,8 +207,8 @@ export class Wrap<
209207
*/
210208
public hasText(text?: string): boolean {
211209
return (
212-
isStringLength(this.#text, { min: 1 }) &&
213-
(isStringType(text) ? this.#text === text : true)
210+
this.#text.length >= 1 &&
211+
(typeof text === 'string' ? this.#text === text : true)
214212
);
215213
}
216214

src/lib/wrapper.class.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
// @angular-package/type.
2-
import { isInstance } from '@angular-package/type';
31
// Class.
42
import { Wrap } from './wrap.class';
53
// Type.
64
import { Wrapped } from '../type/wrapped.type';
75
/**
86
* The `Wrapper` is an extension of the `Wrap` object, which means it represents the immutable wrap of the opening and closing with the
9-
* additional ability to use it to wrap.
7+
* additional ability to use it to wrap strings.
108
*/
119
export class Wrapper<
1210
Opening extends string = string,
@@ -65,7 +63,9 @@ export class Wrapper<
6563
text?: Text
6664
): value is Wrapper<Opening, Text, Closing> {
6765
return (
68-
isInstance(value, this) && super.isWrap(value, opening, closing, text)
66+
typeof value === 'object' &&
67+
value instanceof this &&
68+
super.isWrap(value, opening, closing, text)
6969
);
7070
}
7171

@@ -88,7 +88,7 @@ export class Wrapper<
8888
}
8989

9090
/**
91-
* Replaces the opening chars in a given `text` with a given replacement value at the end of the text.
91+
* Replaces the opening chars in a given `text` with a given replacement value at the beginning of the text.
9292
* @param text The text of `string` type in which the given `opening` chars are replaced by a given replacement value.
9393
* @param opening The opening chars of the `string` to replace by a given replacement value at the beginning of the given `text`.
9494
* @param replaceValue Replacement value for the `opening` characters in the given `text`.
@@ -106,7 +106,7 @@ export class Wrapper<
106106
}
107107

108108
/**
109-
* The method returns the text without the given opening and closing chars.
109+
* The method returns the text without the given `opening` and `closing` chars.
110110
* @param text The text of the `string` from which given opening and closing chars are removed.
111111
* @param opening The opening chars of the `string` to be removed in the given `text`.
112112
* @param closing The closing chars of the `string` to be removed in the given `text`.

0 commit comments

Comments
 (0)