Skip to content

Commit 85f034f

Browse files
refactor: change the filter to pattern.
1 parent 2a35bf8 commit 85f034f

File tree

3 files changed

+38
-38
lines changed

3 files changed

+38
-38
lines changed

src/lib/affix.abstract.ts

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,86 +10,86 @@ import { Value } from '@typescript-package/core';
1010
*/
1111
export abstract class Affix<Value extends string = string> extends Value<Value> {
1212
/**
13-
* @description Defines the affix sanitized by specified filter.
13+
* @description Defines the affix sanitized by specified pattern.
1414
* @public
1515
* @static
1616
* @template {string} [Value=string]
17-
* @param {Value} value A value of generic type variable `Value` constrained by the `string` type to be sanitized with the `filter`.
18-
* @param {RegExp} [filter=Affix.filter] The filter of `RegExp` to sanitize the `affix`. Defaults to static `Affix.filter`.
19-
* @returns {Value} The returned value is an affix of a generic type variable `Value`, optionally sanitized by the `filter`.
17+
* @param {Value} value A value of generic type variable `Value` constrained by the `string` type to be sanitized with the `pattern`.
18+
* @param {RegExp} [pattern=Affix.pattern] The pattern of `RegExp` to sanitize the `affix`. Defaults to static `Affix.pattern`.
19+
* @returns {Value} The returned value is an affix of a generic type variable `Value`, optionally sanitized by the `pattern`.
2020
*/
2121
public static sanitize<Value extends string = string>(
2222
value: Value,
23-
filter: RegExp = Affix.filter,
23+
pattern: RegExp = Affix.pattern,
2424
): Value {
25-
return value.replace(filter, '') as Value;
25+
return value.replace(pattern, '') as Value;
2626
}
2727

2828
/**
29-
* @description The default filter pattern used to sanitize the affix, which removes characters that are not part of the valid characters for the affix.
29+
* @description The default pattern pattern used to sanitize the affix, which removes characters that are not part of the valid characters for the affix.
3030
* @public
3131
* @static
3232
* @type {RegExp}
3333
*/
34-
public static filter: RegExp = /[^a-zA-Z0-9$_]/g;
34+
public static pattern: RegExp = /[^a-zA-Z0-9$_]/g;
3535

3636
/**
37-
* @description Returns the privately stored filter of `RegExp` type to sanitize the affix.
37+
* @description Returns the privately stored pattern of `RegExp` type to sanitize the affix.
3838
* @public
3939
* @readonly
4040
* @type {RegExp}
4141
*/
42-
public get filter(): RegExp {
43-
return this.#filter;
42+
public get pattern() {
43+
return this.#pattern;
4444
}
4545

4646
/**
47-
* @description Privately stored filter of `RegExp` to sanitize the affix.
47+
* @description Privately stored pattern of `RegExp` to sanitize the affix.
4848
* @type {RegExp}
4949
*/
50-
#filter = Affix.filter;
50+
#pattern = Affix.pattern;
5151

5252
/**
5353
* Creates an instance of child class.
5454
* @constructor
5555
* @param {?Value} [value] An optional initial affix of generic type variable `Value` constrained by `string` type.
56-
* @param {?RegExp} [filter] The filter of `RegExp` to sanitize the affix.
56+
* @param {?RegExp} [pattern] The pattern of `RegExp` to sanitize the affix.
5757
*/
58-
constructor(value?: Value, filter?: RegExp) {
58+
constructor(value?: Value, pattern?: RegExp) {
5959
super(value || '' as Value);
60-
filter instanceof RegExp && (this.#filter = filter);
60+
pattern instanceof RegExp && (this.#pattern = pattern);
6161
typeof value !== 'undefined' && this.set(value);
6262
}
6363

6464
/**
65-
* @description Returns the affix, optionally sanitized by the `filter`.
65+
* @description Returns the affix, optionally sanitized by the `pattern`.
6666
* @public
67-
* @param {?RegExp} [filter] The filter of `RegExp` to sanitize privately stored affix.
68-
* @returns {string} Returns privately stored `#affix` of `string` type optionally sanitized by the `filter`.
67+
* @param {?RegExp} [pattern] The pattern of `RegExp` to sanitize privately stored affix.
68+
* @returns {string} Returns privately stored `#affix` of `string` type optionally sanitized by the `pattern`.
6969
*/
70-
public get(filter?: RegExp) {
71-
return Affix.sanitize(this.value, filter);
70+
public get(pattern?: RegExp) {
71+
return Affix.sanitize(this.value, pattern);
7272
}
7373

7474
/**
7575
* @description Sets and stores privately sanitized affix of generic type variable `Value` constrained by `string` type.
7676
* @private
7777
* @param {Value} value The `affix` of generic type variable `Value`.
78-
* @param {RegExp} [filter=this.#filter] The filter of `RegExp` to sanitize the `affix`. Defaults to privately stored `#filter`.
78+
* @param {RegExp} [pattern=this.#pattern] The pattern of `RegExp` to sanitize the `affix`. Defaults to privately stored `#pattern`.
7979
* @returns {this} The returned value is current instance for method chaining.
8080
*/
81-
public set(value: Value, filter: RegExp = this.#filter): this {
82-
typeof value === 'string' && (super.setValue(Affix.sanitize(value, filter) as Value));
81+
public set(value: Value, pattern: RegExp = this.#pattern): this {
82+
typeof value === 'string' && (super.setValue(Affix.sanitize(value, pattern) as Value));
8383
return this;
8484
}
8585

8686
/**
87-
* @description Sets the filter to sanitize the affix.
87+
* @description Sets the pattern to sanitize the affix.
8888
* @public
89-
* @param {RegExp} filter The filter of `RegExp` to sanitize the affix.
89+
* @param {RegExp} pattern The pattern of `RegExp` to sanitize the affix.
9090
*/
91-
public setFilter(filter: RegExp): this {
92-
filter instanceof RegExp && (this.#filter = filter);
91+
public setPattern(pattern: RegExp): this {
92+
pattern instanceof RegExp && (this.#pattern = pattern);
9393
return this;
9494
}
9595
}

src/lib/prefix.class.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import { Affix } from "./affix.abstract";
99
*/
1010
export class Prefix<Value extends string = string> extends Affix<Value> {
1111
/**
12-
* @description Sanitizes the prefix with a `filter`.
12+
* @description Sanitizes the prefix with a `pattern`.
1313
* @public
1414
* @param {string} value
15-
* @param {RegExp} [filter=Prefix.filter]
15+
* @param {RegExp} [pattern=Prefix.pattern]
1616
* @returns {string}
1717
*/
1818
public static override sanitize<Value extends string = string>(
1919
value: Value,
20-
filter: RegExp = Prefix.filter
20+
pattern: RegExp = Prefix.pattern
2121
): Value {
22-
return value.replace(filter, '') as Value;
22+
return value.replace(pattern, '') as Value;
2323
}
2424

2525
/**
@@ -28,5 +28,5 @@ export class Prefix<Value extends string = string> extends Affix<Value> {
2828
* @static
2929
* @type {RegExp}
3030
*/
31-
public static override filter: RegExp = super.filter;
31+
public static override pattern: RegExp = super.pattern;
3232
}

src/lib/suffix.class.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ import { Affix } from "./affix.abstract";
99
*/
1010
export class Suffix<Value extends string = string> extends Affix<Value> {
1111
/**
12-
* @description Sanitizes the suffix with a `filter`.
12+
* @description Sanitizes the suffix with a `pattern`.
1313
* @public
1414
* @param {string} value
15-
* @param {RegExp} [filter=Suffix.filter]
15+
* @param {RegExp} [pattern=Suffix.pattern]
1616
* @returns {string}
1717
*/
1818
public static override sanitize<Value extends string = string>(
1919
value: Value,
20-
filter: RegExp = Suffix.filter
20+
pattern: RegExp = Suffix.pattern
2121
): Value {
22-
return value.replace(filter, '') as Value;
22+
return value.replace(pattern, '') as Value;
2323
}
2424

2525
/**
@@ -28,5 +28,5 @@ export class Suffix<Value extends string = string> extends Affix<Value> {
2828
* @static
2929
* @type {RegExp}
3030
*/
31-
public static override filter: RegExp = super.filter;
31+
public static override pattern: RegExp = super.pattern;
3232
}

0 commit comments

Comments
 (0)