@pawells/typescript-common 1.4.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -12
- package/build/array/array-contains.d.ts +3 -0
- package/build/array/array-contains.d.ts.map +1 -1
- package/build/array/array-contains.js +4 -0
- package/build/array/array-contains.js.map +1 -1
- package/build/array/array-count-by.d.ts +2 -0
- package/build/array/array-count-by.d.ts.map +1 -1
- package/build/array/array-count-by.js +4 -1
- package/build/array/array-count-by.js.map +1 -1
- package/build/array/array-difference.d.ts +20 -9
- package/build/array/array-difference.d.ts.map +1 -1
- package/build/array/array-difference.js +25 -8
- package/build/array/array-difference.js.map +1 -1
- package/build/array/array-filter.d.ts +2 -0
- package/build/array/array-filter.d.ts.map +1 -1
- package/build/array/array-filter.js +4 -1
- package/build/array/array-filter.js.map +1 -1
- package/build/array/array-group-by.d.ts +2 -0
- package/build/array/array-group-by.d.ts.map +1 -1
- package/build/array/array-group-by.js +4 -1
- package/build/array/array-group-by.js.map +1 -1
- package/build/array/array-intersection.d.ts +20 -9
- package/build/array/array-intersection.d.ts.map +1 -1
- package/build/array/array-intersection.js +30 -12
- package/build/array/array-intersection.js.map +1 -1
- package/build/array/array-partition.d.ts +2 -0
- package/build/array/array-partition.d.ts.map +1 -1
- package/build/array/array-partition.js +4 -1
- package/build/array/array-partition.js.map +1 -1
- package/build/array/array-sample.d.ts +2 -2
- package/build/array/array-sample.d.ts.map +1 -1
- package/build/array/array-sample.js +2 -10
- package/build/array/array-sample.js.map +1 -1
- package/build/array/assert.d.ts +22 -18
- package/build/array/assert.d.ts.map +1 -1
- package/build/array/assert.js +27 -23
- package/build/array/assert.js.map +1 -1
- package/build/array/types.d.ts +11 -0
- package/build/array/types.d.ts.map +1 -1
- package/build/array/unique.d.ts +2 -0
- package/build/array/unique.d.ts.map +1 -1
- package/build/array/unique.js +4 -1
- package/build/array/unique.js.map +1 -1
- package/build/asserts/generic.d.ts +9 -0
- package/build/asserts/generic.d.ts.map +1 -1
- package/build/asserts/generic.js +30 -8
- package/build/asserts/generic.js.map +1 -1
- package/build/asserts/utils.d.ts +32 -0
- package/build/asserts/utils.d.ts.map +1 -1
- package/build/asserts/utils.js +79 -0
- package/build/asserts/utils.js.map +1 -1
- package/build/boolean/assert.d.ts.map +1 -1
- package/build/boolean/assert.js +2 -5
- package/build/boolean/assert.js.map +1 -1
- package/build/function/compose.d.ts +3 -2
- package/build/function/compose.d.ts.map +1 -1
- package/build/function/compose.js.map +1 -1
- package/build/function/debounce.d.ts +2 -1
- package/build/function/debounce.d.ts.map +1 -1
- package/build/function/debounce.js.map +1 -1
- package/build/function/once.d.ts +1 -0
- package/build/function/once.d.ts.map +1 -1
- package/build/function/once.js +1 -0
- package/build/function/once.js.map +1 -1
- package/build/function/throttle.d.ts +2 -1
- package/build/function/throttle.d.ts.map +1 -1
- package/build/function/throttle.js.map +1 -1
- package/build/index.d.ts +2 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build/number/assert.d.ts.map +1 -1
- package/build/number/assert.js +38 -42
- package/build/number/assert.js.map +1 -1
- package/build/object/clone.d.ts.map +1 -1
- package/build/object/clone.js +3 -0
- package/build/object/clone.js.map +1 -1
- package/build/object/equals.d.ts +1 -1
- package/build/object/equals.d.ts.map +1 -1
- package/build/object/equals.js +14 -7
- package/build/object/equals.js.map +1 -1
- package/build/object/filter-cached.js.map +1 -1
- package/build/object/filter.d.ts +1 -1
- package/build/object/filter.d.ts.map +1 -1
- package/build/object/filter.js +26 -65
- package/build/object/filter.js.map +1 -1
- package/build/object/hash.d.ts +1 -1
- package/build/object/hash.d.ts.map +1 -1
- package/build/object/hash.js +1 -0
- package/build/object/hash.js.map +1 -1
- package/build/object/property-paths.d.ts +2 -2
- package/build/object/property-paths.d.ts.map +1 -1
- package/build/object/property-paths.js +7 -2
- package/build/object/property-paths.js.map +1 -1
- package/build/object/security-utils.d.ts +2 -2
- package/build/object/security-utils.d.ts.map +1 -1
- package/build/object/security-utils.js.map +1 -1
- package/build/object/types.d.ts +1 -1
- package/build/object/types.d.ts.map +1 -1
- package/build/string/assert.d.ts.map +1 -1
- package/build/string/assert.js +3 -9
- package/build/string/assert.js.map +1 -1
- package/build/string/case-conversion.d.ts +53 -24
- package/build/string/case-conversion.d.ts.map +1 -1
- package/build/string/case-conversion.js +59 -29
- package/build/string/case-conversion.js.map +1 -1
- package/build/string/comparison.d.ts +20 -0
- package/build/string/comparison.d.ts.map +1 -0
- package/build/string/comparison.js +25 -0
- package/build/string/comparison.js.map +1 -0
- package/build/string/formatting.d.ts +35 -22
- package/build/string/formatting.d.ts.map +1 -1
- package/build/string/formatting.js +35 -22
- package/build/string/formatting.js.map +1 -1
- package/build/string/index.d.ts +1 -0
- package/build/string/index.d.ts.map +1 -1
- package/build/string/index.js +1 -0
- package/build/string/index.js.map +1 -1
- package/build/string/transformation.d.ts +19 -9
- package/build/string/transformation.d.ts.map +1 -1
- package/build/string/transformation.js +21 -10
- package/build/string/transformation.js.map +1 -1
- package/build/string/validation.d.ts +21 -9
- package/build/string/validation.d.ts.map +1 -1
- package/build/string/validation.js +23 -10
- package/build/string/validation.js.map +1 -1
- package/package.json +2 -2
|
@@ -14,8 +14,8 @@ import type { TFormatParams, TFormatArgs } from './types.js';
|
|
|
14
14
|
*/
|
|
15
15
|
export declare function EscapeHTML(str: string): string;
|
|
16
16
|
/**
|
|
17
|
-
* Formats a string by replacing placeholders with values
|
|
18
|
-
* Supports both named placeholders {name} and positional {0}, {1}
|
|
17
|
+
* Formats a string by replacing placeholders with values.
|
|
18
|
+
* Supports both named placeholders {name} and positional {0}, {1}.
|
|
19
19
|
*
|
|
20
20
|
* @param template - The template string with placeholders
|
|
21
21
|
* @param params - Either an object with named parameters or array of positional parameters
|
|
@@ -40,27 +40,40 @@ export declare function FormatString(template: string, params: TFormatParams | T
|
|
|
40
40
|
/**
|
|
41
41
|
* Truncates a string to a specified length, appending an ellipsis if truncated.
|
|
42
42
|
*
|
|
43
|
-
* @param str The string to truncate
|
|
44
|
-
* @param maxLength The maximum length before truncation
|
|
45
|
-
* @param ellipsis The string to append when truncated (default: '...')
|
|
46
|
-
* @returns The truncated string
|
|
43
|
+
* @param str - The string to truncate
|
|
44
|
+
* @param maxLength - The maximum length before truncation
|
|
45
|
+
* @param ellipsis - The string to append when truncated (default: '...')
|
|
46
|
+
* @returns The truncated string
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* TruncateString('Hello World', 5); // 'Hello...'
|
|
51
|
+
* TruncateString('Hello World', 5, '!'); // 'Hello!'
|
|
52
|
+
* ```
|
|
47
53
|
*/
|
|
48
54
|
export declare function TruncateString(str: string, maxLength: number, ellipsis?: string): string;
|
|
49
55
|
/**
|
|
50
56
|
* Pads a string to a specified length.
|
|
51
57
|
*
|
|
52
|
-
* @param str The input string
|
|
53
|
-
* @param length The target length
|
|
54
|
-
* @param char The character to pad with (default: ' ')
|
|
55
|
-
* @param padEnd If true, pads the end; otherwise, pads the start (default: true)
|
|
56
|
-
* @returns The padded string
|
|
58
|
+
* @param str - The input string
|
|
59
|
+
* @param length - The target length
|
|
60
|
+
* @param char - The character to pad with (default: ' ')
|
|
61
|
+
* @param padEnd - If true, pads the end; otherwise, pads the start (default: true)
|
|
62
|
+
* @returns The padded string
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```typescript
|
|
66
|
+
* PadString('hello', 10); // 'hello '
|
|
67
|
+
* PadString('hello', 10, '*'); // 'hello*****'
|
|
68
|
+
* PadString('hello', 10, '*', false); // '*****hello'
|
|
69
|
+
* ```
|
|
57
70
|
*/
|
|
58
71
|
export declare function PadString(str: string, length: number, char?: string, padEnd?: boolean): string;
|
|
59
72
|
/**
|
|
60
73
|
* Removes all HTML tags from a string.
|
|
61
74
|
*
|
|
62
|
-
* @param str The input string
|
|
63
|
-
* @returns The string with all HTML tags stripped
|
|
75
|
+
* @param str - The input string
|
|
76
|
+
* @returns The string with all HTML tags stripped
|
|
64
77
|
*
|
|
65
78
|
* @example
|
|
66
79
|
* ```typescript
|
|
@@ -71,10 +84,10 @@ export declare function StripHTML(str: string): string;
|
|
|
71
84
|
/**
|
|
72
85
|
* Returns the plural form of a word based on a count.
|
|
73
86
|
*
|
|
74
|
-
* @param word The singular word
|
|
75
|
-
* @param count The count to test against
|
|
76
|
-
* @param plural Optional custom plural form (defaults to `word + 's'`)
|
|
77
|
-
* @returns The singular word when `count === 1`, otherwise the plural
|
|
87
|
+
* @param word - The singular word
|
|
88
|
+
* @param count - The count to test against
|
|
89
|
+
* @param plural - Optional custom plural form (defaults to `word + 's'`)
|
|
90
|
+
* @returns The singular word when `count === 1`, otherwise the plural
|
|
78
91
|
*
|
|
79
92
|
* @example
|
|
80
93
|
* ```typescript
|
|
@@ -88,8 +101,8 @@ export declare function Pluralize(word: string, count: number, plural?: string):
|
|
|
88
101
|
* Counts the number of words in a string.
|
|
89
102
|
* Words are separated by one or more whitespace characters.
|
|
90
103
|
*
|
|
91
|
-
* @param str The input string
|
|
92
|
-
* @returns The number of words
|
|
104
|
+
* @param str - The input string
|
|
105
|
+
* @returns The number of words
|
|
93
106
|
*
|
|
94
107
|
* @example
|
|
95
108
|
* ```typescript
|
|
@@ -101,9 +114,9 @@ export declare function WordCount(str: string): number;
|
|
|
101
114
|
/**
|
|
102
115
|
* Counts the number of non-overlapping occurrences of `substr` in `str`.
|
|
103
116
|
*
|
|
104
|
-
* @param str The string to search in
|
|
105
|
-
* @param substr The substring to count
|
|
106
|
-
* @returns The number of occurrences
|
|
117
|
+
* @param str - The string to search in
|
|
118
|
+
* @param substr - The substring to count
|
|
119
|
+
* @returns The number of occurrences
|
|
107
120
|
*
|
|
108
121
|
* @example
|
|
109
122
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAAA,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AAE,MAAM,GAAG,MAAM,CAG7C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CASpE"}
|
|
@@ -23,8 +23,8 @@ export function EscapeHTML(str) {
|
|
|
23
23
|
return '';
|
|
24
24
|
}
|
|
25
25
|
/**
|
|
26
|
-
* Formats a string by replacing placeholders with values
|
|
27
|
-
* Supports both named placeholders {name} and positional {0}, {1}
|
|
26
|
+
* Formats a string by replacing placeholders with values.
|
|
27
|
+
* Supports both named placeholders {name} and positional {0}, {1}.
|
|
28
28
|
*
|
|
29
29
|
* @param template - The template string with placeholders
|
|
30
30
|
* @param params - Either an object with named parameters or array of positional parameters
|
|
@@ -66,10 +66,16 @@ export function FormatString(template, params) {
|
|
|
66
66
|
/**
|
|
67
67
|
* Truncates a string to a specified length, appending an ellipsis if truncated.
|
|
68
68
|
*
|
|
69
|
-
* @param str The string to truncate
|
|
70
|
-
* @param maxLength The maximum length before truncation
|
|
71
|
-
* @param ellipsis The string to append when truncated (default: '...')
|
|
72
|
-
* @returns The truncated string
|
|
69
|
+
* @param str - The string to truncate
|
|
70
|
+
* @param maxLength - The maximum length before truncation
|
|
71
|
+
* @param ellipsis - The string to append when truncated (default: '...')
|
|
72
|
+
* @returns The truncated string
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* TruncateString('Hello World', 5); // 'Hello...'
|
|
77
|
+
* TruncateString('Hello World', 5, '!'); // 'Hello!'
|
|
78
|
+
* ```
|
|
73
79
|
*/
|
|
74
80
|
export function TruncateString(str, maxLength, ellipsis = '...') {
|
|
75
81
|
if (str && typeof str === 'string' && maxLength > 0) {
|
|
@@ -83,11 +89,18 @@ export function TruncateString(str, maxLength, ellipsis = '...') {
|
|
|
83
89
|
/**
|
|
84
90
|
* Pads a string to a specified length.
|
|
85
91
|
*
|
|
86
|
-
* @param str The input string
|
|
87
|
-
* @param length The target length
|
|
88
|
-
* @param char The character to pad with (default: ' ')
|
|
89
|
-
* @param padEnd If true, pads the end; otherwise, pads the start (default: true)
|
|
90
|
-
* @returns The padded string
|
|
92
|
+
* @param str - The input string
|
|
93
|
+
* @param length - The target length
|
|
94
|
+
* @param char - The character to pad with (default: ' ')
|
|
95
|
+
* @param padEnd - If true, pads the end; otherwise, pads the start (default: true)
|
|
96
|
+
* @returns The padded string
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* PadString('hello', 10); // 'hello '
|
|
101
|
+
* PadString('hello', 10, '*'); // 'hello*****'
|
|
102
|
+
* PadString('hello', 10, '*', false); // '*****hello'
|
|
103
|
+
* ```
|
|
91
104
|
*/
|
|
92
105
|
export function PadString(str, length, char = ' ', padEnd = true) {
|
|
93
106
|
if (typeof str === 'string' && length > str.length) {
|
|
@@ -100,8 +113,8 @@ export function PadString(str, length, char = ' ', padEnd = true) {
|
|
|
100
113
|
/**
|
|
101
114
|
* Removes all HTML tags from a string.
|
|
102
115
|
*
|
|
103
|
-
* @param str The input string
|
|
104
|
-
* @returns The string with all HTML tags stripped
|
|
116
|
+
* @param str - The input string
|
|
117
|
+
* @returns The string with all HTML tags stripped
|
|
105
118
|
*
|
|
106
119
|
* @example
|
|
107
120
|
* ```typescript
|
|
@@ -116,10 +129,10 @@ export function StripHTML(str) {
|
|
|
116
129
|
/**
|
|
117
130
|
* Returns the plural form of a word based on a count.
|
|
118
131
|
*
|
|
119
|
-
* @param word The singular word
|
|
120
|
-
* @param count The count to test against
|
|
121
|
-
* @param plural Optional custom plural form (defaults to `word + 's'`)
|
|
122
|
-
* @returns The singular word when `count === 1`, otherwise the plural
|
|
132
|
+
* @param word - The singular word
|
|
133
|
+
* @param count - The count to test against
|
|
134
|
+
* @param plural - Optional custom plural form (defaults to `word + 's'`)
|
|
135
|
+
* @returns The singular word when `count === 1`, otherwise the plural
|
|
123
136
|
*
|
|
124
137
|
* @example
|
|
125
138
|
* ```typescript
|
|
@@ -137,8 +150,8 @@ export function Pluralize(word, count, plural) {
|
|
|
137
150
|
* Counts the number of words in a string.
|
|
138
151
|
* Words are separated by one or more whitespace characters.
|
|
139
152
|
*
|
|
140
|
-
* @param str The input string
|
|
141
|
-
* @returns The number of words
|
|
153
|
+
* @param str - The input string
|
|
154
|
+
* @returns The number of words
|
|
142
155
|
*
|
|
143
156
|
* @example
|
|
144
157
|
* ```typescript
|
|
@@ -154,9 +167,9 @@ export function WordCount(str) {
|
|
|
154
167
|
/**
|
|
155
168
|
* Counts the number of non-overlapping occurrences of `substr` in `str`.
|
|
156
169
|
*
|
|
157
|
-
* @param str The string to search in
|
|
158
|
-
* @param substr The substring to count
|
|
159
|
-
* @returns The number of occurrences
|
|
170
|
+
* @param str - The string to search in
|
|
171
|
+
* @param substr - The substring to count
|
|
172
|
+
* @returns The number of occurrences
|
|
160
173
|
*
|
|
161
174
|
* @example
|
|
162
175
|
* ```typescript
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatting.js","sourceRoot":"","sources":["../../src/string/formatting.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,UAAU,CAAC,GAAW;IACrC,IAAI,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;QACpC,OAAO,GAAG;aACR,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC;aACvB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;aACtB,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC;aACtB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC;aACxB,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,YAAY,CAC3B,QAAgB,EAChB,MAAmC;IAEnC,IAAI,QAAQ,IAAI,OAAO,QAAQ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AQ;QAAE,OAAO,EAAE,CAAC;IACjD,OAAO,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC;AACpD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,SAAS,CAAC,GAAW;IACpC,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,CAAC,CAAC;IAC9C,OAAO,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AACxD,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,gBAAgB,CAAC,GAAW,EAAE,MAAc;IAC3D,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM;QAAE,OAAO,CAAC,CAAC;IAC9B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;QAChD,KAAK,EAAE,CAAC;QACR,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC;IACtB,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC"}
|
package/build/string/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export * from './case-conversion.js';
|
|
|
11
11
|
export * from './validation.js';
|
|
12
12
|
export * from './formatting.js';
|
|
13
13
|
export * from './transformation.js';
|
|
14
|
+
export * from './comparison.js';
|
|
14
15
|
export type { TStringValidator, TStringFormatter, TStringTransformer, TCaseConverter, TStringPredicate, TFormatValue, TFormatParams, TFormatArgs } from './types.js';
|
|
15
16
|
export * from './assert.js';
|
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAEhC,YAAY,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,cAAc,EAAE,gBAAgB,EAAE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACrK,cAAc,aAAa,CAAC"}
|
package/build/string/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/string/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,cAAc,sBAAsB,CAAC;AACrC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAGhC,cAAc,aAAa,CAAC"}
|
|
@@ -1,18 +1,28 @@
|
|
|
1
|
-
import type { TStringTransformer } from './types.js';
|
|
2
1
|
/**
|
|
3
2
|
* Reverses a string.
|
|
4
3
|
*
|
|
5
|
-
* @param input The input string
|
|
6
|
-
* @returns The reversed string
|
|
7
|
-
*
|
|
4
|
+
* @param input - The input string
|
|
5
|
+
* @returns The reversed string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* ReverseString('hello'); // 'olleh'
|
|
10
|
+
* ReverseString('12345'); // '54321'
|
|
11
|
+
* ```
|
|
8
12
|
*/
|
|
9
|
-
export declare
|
|
13
|
+
export declare function ReverseString(input: string): string;
|
|
10
14
|
/**
|
|
11
15
|
* Converts a string to a URL-friendly slug.
|
|
12
16
|
*
|
|
13
|
-
* @param input The input string
|
|
14
|
-
* @returns The URL-friendly slug
|
|
15
|
-
*
|
|
17
|
+
* @param input - The input string
|
|
18
|
+
* @returns The URL-friendly slug
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* Slugify('Hello World!'); // 'hello-world'
|
|
23
|
+
* Slugify('The Quick Brown Fox'); // 'the-quick-brown-fox'
|
|
24
|
+
* Slugify('CamelCaseText'); // 'camelcasetext'
|
|
25
|
+
* ```
|
|
16
26
|
*/
|
|
17
|
-
export declare
|
|
27
|
+
export declare function Slugify(input: string): string;
|
|
18
28
|
//# sourceMappingURL=transformation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformation.d.ts","sourceRoot":"","sources":["../../src/string/transformation.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"transformation.d.ts","sourceRoot":"","sources":["../../src/string/transformation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMnD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAW7C"}
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Reverses a string.
|
|
3
3
|
*
|
|
4
|
-
* @param input The input string
|
|
5
|
-
* @returns The reversed string
|
|
6
|
-
*
|
|
4
|
+
* @param input - The input string
|
|
5
|
+
* @returns The reversed string
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* ReverseString('hello'); // 'olleh'
|
|
10
|
+
* ReverseString('12345'); // '54321'
|
|
11
|
+
* ```
|
|
7
12
|
*/
|
|
8
|
-
export
|
|
13
|
+
export function ReverseString(input) {
|
|
9
14
|
if (input && typeof input === 'string') {
|
|
10
15
|
return Array.from(input).reverse().join('');
|
|
11
16
|
}
|
|
12
17
|
return '';
|
|
13
|
-
}
|
|
18
|
+
}
|
|
14
19
|
/**
|
|
15
20
|
* Converts a string to a URL-friendly slug.
|
|
16
21
|
*
|
|
17
|
-
* @param input The input string
|
|
18
|
-
* @returns The URL-friendly slug
|
|
19
|
-
*
|
|
22
|
+
* @param input - The input string
|
|
23
|
+
* @returns The URL-friendly slug
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```typescript
|
|
27
|
+
* Slugify('Hello World!'); // 'hello-world'
|
|
28
|
+
* Slugify('The Quick Brown Fox'); // 'the-quick-brown-fox'
|
|
29
|
+
* Slugify('CamelCaseText'); // 'camelcasetext'
|
|
30
|
+
* ```
|
|
20
31
|
*/
|
|
21
|
-
export
|
|
32
|
+
export function Slugify(input) {
|
|
22
33
|
if (input && typeof input === 'string') {
|
|
23
34
|
return input
|
|
24
35
|
.toLowerCase()
|
|
@@ -28,5 +39,5 @@ export const SLUGIFY = (input) => {
|
|
|
28
39
|
.replace(/^-+|-+$/gu, '');
|
|
29
40
|
}
|
|
30
41
|
return '';
|
|
31
|
-
}
|
|
42
|
+
}
|
|
32
43
|
//# sourceMappingURL=transformation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../src/string/transformation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"transformation.js","sourceRoot":"","sources":["../../src/string/transformation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,OAAO,CAAC,KAAa;IACpC,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QACxC,OAAO,KAAK;aACV,WAAW,EAAE;aACb,IAAI,EAAE;aACN,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC;aACzB,OAAO,CAAC,WAAW,EAAE,GAAG,CAAC;aACzB,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC;IAC5B,CAAC;IAED,OAAO,EAAE,CAAC;AACX,CAAC"}
|
|
@@ -1,18 +1,30 @@
|
|
|
1
|
-
import type { TStringValidator } from './types.js';
|
|
2
1
|
/**
|
|
3
2
|
* Checks if a string is empty or contains only whitespace.
|
|
4
3
|
*
|
|
5
|
-
* @param value The string to check
|
|
6
|
-
* @returns `true` if the string is empty or contains only whitespace
|
|
7
|
-
*
|
|
4
|
+
* @param value - The string to check
|
|
5
|
+
* @returns `true` if the string is empty or contains only whitespace
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* IsBlankString(''); // true
|
|
10
|
+
* IsBlankString(' '); // true
|
|
11
|
+
* IsBlankString('hello'); // false
|
|
12
|
+
* ```
|
|
8
13
|
*/
|
|
9
|
-
export declare
|
|
14
|
+
export declare function IsBlankString(value: string): boolean;
|
|
10
15
|
/**
|
|
11
16
|
* Checks if a string is a valid hexadecimal value.
|
|
12
17
|
*
|
|
13
|
-
* @param value The input string
|
|
14
|
-
* @returns `true` if the string is a valid hexadecimal value
|
|
15
|
-
*
|
|
18
|
+
* @param value - The input string
|
|
19
|
+
* @returns `true` if the string is a valid hexadecimal value
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```typescript
|
|
23
|
+
* IsHexString('#ff00ff'); // true
|
|
24
|
+
* IsHexString('0xDEADBEEF'); // true
|
|
25
|
+
* IsHexString('ff00ff'); // true
|
|
26
|
+
* IsHexString('xyz'); // false
|
|
27
|
+
* ```
|
|
16
28
|
*/
|
|
17
|
-
export declare
|
|
29
|
+
export declare function IsHexString(value: string): boolean;
|
|
18
30
|
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/string/validation.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../src/string/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEpD;AAQD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAElD"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Checks if a string is empty or contains only whitespace.
|
|
3
3
|
*
|
|
4
|
-
* @param value The string to check
|
|
5
|
-
* @returns `true` if the string is empty or contains only whitespace
|
|
6
|
-
*
|
|
4
|
+
* @param value - The string to check
|
|
5
|
+
* @returns `true` if the string is empty or contains only whitespace
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* IsBlankString(''); // true
|
|
10
|
+
* IsBlankString(' '); // true
|
|
11
|
+
* IsBlankString('hello'); // false
|
|
12
|
+
* ```
|
|
7
13
|
*/
|
|
8
|
-
export
|
|
14
|
+
export function IsBlankString(value) {
|
|
9
15
|
return !value || (/^\s*$/u).test(value);
|
|
10
|
-
}
|
|
16
|
+
}
|
|
11
17
|
/**
|
|
12
18
|
* Compiled regex pattern for hexadecimal validation.
|
|
13
19
|
* Cached for optimal performance with repeated calls.
|
|
@@ -16,11 +22,18 @@ const HEX_PATTERN = /^(?<prefix>#|0x)?(?<hex>[0-9a-f]+)$/iu;
|
|
|
16
22
|
/**
|
|
17
23
|
* Checks if a string is a valid hexadecimal value.
|
|
18
24
|
*
|
|
19
|
-
* @param value The input string
|
|
20
|
-
* @returns `true` if the string is a valid hexadecimal value
|
|
21
|
-
*
|
|
25
|
+
* @param value - The input string
|
|
26
|
+
* @returns `true` if the string is a valid hexadecimal value
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```typescript
|
|
30
|
+
* IsHexString('#ff00ff'); // true
|
|
31
|
+
* IsHexString('0xDEADBEEF'); // true
|
|
32
|
+
* IsHexString('ff00ff'); // true
|
|
33
|
+
* IsHexString('xyz'); // false
|
|
34
|
+
* ```
|
|
22
35
|
*/
|
|
23
|
-
export
|
|
36
|
+
export function IsHexString(value) {
|
|
24
37
|
return HEX_PATTERN.test(value);
|
|
25
|
-
}
|
|
38
|
+
}
|
|
26
39
|
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/string/validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/string/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa,CAAC,KAAa;IAC1C,OAAO,CAAC,KAAK,IAAI,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAED;;;GAGG;AACH,MAAM,WAAW,GAAG,uCAAuC,CAAC;AAE5D;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa;IACxC,OAAO,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pawells/typescript-common",
|
|
3
3
|
"displayName": "TypeScript Common Utilities",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0",
|
|
5
5
|
"description": "Shared TypeScript utility library — array, object, string, time, and enum helpers. ESM-only, no runtime dependencies.",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./build/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"eslint-plugin-unused-imports": "^4.0.0",
|
|
42
42
|
"globals": "^17.4.0",
|
|
43
43
|
"husky": "^9.1.7",
|
|
44
|
-
"typescript": "^
|
|
44
|
+
"typescript": "^6.0.2",
|
|
45
45
|
"vitest": "^4.0.18"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|