Skip to content

Commit e91547e

Browse files
refactor(Wrapper): change method name from the textWrap to rewrap.
1 parent 88f2425 commit e91547e

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

src/lib/wrapper.class.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,19 @@ export class Wrapper<
187187
);
188188
}
189189

190+
/**
191+
* The method returns the text of the `Wrapper` object wrapped by the given `opening` and `closing` chars.
192+
* @param opening The opening chars of a generic type variable `TextOpening` to wrap the text of the `Wrapper` instance.
193+
* @param closing The closing chars of a generic type variable `TextClosing` to wrap the text of the `Wrapper` instance.
194+
* @returns The return value is the text wrapped by given `opening` and closing `chars` of generic type `Wrapped`.
195+
*/
196+
public rewrap<TextOpening extends string, TextClosing extends string>(
197+
opening: TextOpening,
198+
closing: TextClosing
199+
): Wrapped<TextOpening, Text, TextClosing> {
200+
return new Wrap(opening, closing, this.text).valueOf();
201+
}
202+
190203
/**
191204
* Replaces the closing chars of the `Wrapper` object in the text of the `Wrapper` object with the given `closing` chars.
192205
* The replacement succeeds if the closing characters exist at the end of the text.
@@ -223,19 +236,6 @@ export class Wrapper<
223236
return Wrapper.unwrap(this.text, opening, closing);
224237
}
225238

226-
/**
227-
* The method returns the text of the `Wrapper` object wrapped by the given `opening` and `closing` chars.
228-
* @param opening The opening chars of a generic type variable `TextOpening` to wrap the text of the `Wrapper` instance.
229-
* @param closing The closing chars of a generic type variable `TextClosing` to wrap the text of the `Wrapper` instance.
230-
* @returns The return value is the text wrapped by given `opening` and closing `chars` of generic type `Wrapped`.
231-
*/
232-
public textWrap<TextOpening extends string, TextClosing extends string>(
233-
opening: TextOpening,
234-
closing: TextClosing
235-
): Wrapped<TextOpening, Text, TextClosing> {
236-
return new Wrap(opening, closing, this.text).valueOf();
237-
}
238-
239239
/**
240240
* Returns an `array` consisting of the opening chars, text, and closing chars.
241241
* @returns The return value is a read-only `array` consisting of the opening chars, text, and closing chars.
@@ -324,7 +324,7 @@ export class Wrapper<
324324
opening: TextOpening,
325325
closing: TextClosing
326326
): Wrapped<Opening, Wrapped<TextOpening, Text, TextClosing>, Closing> {
327-
return `${this.opening}${this.textWrap(opening, closing)}${this.closing}`;
327+
return `${this.opening}${this.rewrap(opening, closing)}${this.closing}`;
328328
}
329329
//#endregion instance public methods.
330330
}

src/test/wrap.spec.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { Wrap } from "../lib";
2+
3+
console.group(`Wrap`);
4+
5+
// Initialize.
6+
const htmlTag = new Wrap('<', '>', 'div');
7+
8+
// The `Wrap` object.
9+
console.log(htmlTag); // Output: Wrap {'<div>', #closing: '>', #opening: '<', #text: 'div'}
10+
11+
console.log(htmlTag.valueOf()); // Output: <div>
12+
13+
// Initialize.
14+
const bbCode = new Wrap('[', ']', 'quote');
15+
16+
console.log(bbCode); // Output: Wrap {'[quote]', #closing: ']', #opening: '[', #text: 'quote'}
17+
18+
console.log(bbCode.valueOf()); // Output: [quote]
19+
20+
console.groupEnd();

src/test/wrapper.spec.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { Wrapper } from "../lib";
2+
3+
console.group(`Wrapper`);
4+
5+
// Initialize.
6+
const htmlTag = new Wrapper(
7+
'<',
8+
'>',
9+
'div'
10+
);
11+
12+
// The `Wrap` object.
13+
console.log(htmlTag); // Output: Wrapper {'<div>', #closing: '>', #opening: '<', #text: 'div'}
14+
15+
console.log(htmlTag.valueOf()); // Output: <div>
16+
17+
// Initialize.
18+
const bbCode = new Wrapper('[', ']', 'quote');
19+
20+
console.log(bbCode); // Output: Wrapper {'[quote]', #closing: ']', #opening: '[', #text: 'quote'}
21+
22+
// Wrap the valueOf [quote]
23+
console.log(bbCode.wrap()); // Output: [[quote]]
24+
25+
// Wrap the valueOf [quote] with the specified `opening` and `closing` chars.
26+
console.log(bbCode.wrap(`(`, `)`)); // Output: ([quote])
27+
28+
// Wrap the specified text with the `opening` and `closing` chars.
29+
console.log(bbCode.wrapOn(`/italic`)); // Output: [/italic]
30+
31+
// Replace the `opening` and `closing` chars.
32+
console.log(bbCode.rewrap(`(`, `)`)); // Output: (quote)
33+
34+
// Wraps the `text` inside.
35+
console.log(bbCode.wrapText(`(`, `)`)); // Output: [(quote)]
36+
37+
// Returns the primitive value.
38+
console.log(bbCode.valueOf()); // Output: [quote]
39+
40+
console.groupEnd();

0 commit comments

Comments
 (0)