@js-utils-kit/string 1.0.1 → 1.2.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/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- function e(e){return e.replace(/^\w/,e=>e.toUpperCase())}function t(e,t=/\s+/){return e.split(t)}function n(e,n){return n?[...e].filter(e=>e===n).length:t(e).length}function r(e){return[...e].reduce((e,t)=>(e[t]=(e[t]||0)+1,e),{})}function i(e){return e?t(e,/\r\n|\r|\n/).length:0}function a(e,n){return n.length===0?0:t(e,n).length-1}function o(e){return t(e.trim()).length}function s(e,t=``){return e.replace(/[^\p{L}\p{N}\s]/gu,t)}function c(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.max(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function l(e){let n=t(e).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.max(e,t.length),0)}function u(e,t,n=` `){return e.padStart(t,n)}function d(e,t,n=` `){return e.padEnd(t,n)}function f(e,t){return e.repeat(t)}function p(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.min(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function m(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.min(e,t.length),1/0)}const h=Object.assign(e=>e.trim(),{start:e=>e.trimStart(),end:e=>e.trimEnd(),normalizeWhitespace:e=>e.trim().replace(/\s+/g,` `)});function g(e,t,n=`...`){return t<=0?``:e.length<=t?e:n.length>=t?n.slice(0,t):e.trim().slice(0,t)+n}function _(e){return[...new Set(e)]}exports.capitalize=e,exports.countChars=n,exports.countFrequencies=r,exports.countLines=i,exports.countSubstring=a,exports.countWords=o,exports.longestWord=c,exports.longestWordLength=l,exports.padLeft=u,exports.padRight=d,exports.repeatString=f,exports.shortestWord=p,exports.shortestWordLength=m,exports.splitString=t,exports.stripSymbols=s,exports.trim=h,exports.truncate=g,exports.uniqueChars=_;var v=require(`@js-utils-kit/types`);Object.keys(v).forEach(function(e){e!==`default`&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:function(){return v[e]}})});
1
+ function e(e){return e.replace(/^\w/,e=>e.toUpperCase())}function t(e,t=/\s+/){return e.split(t)}function n(e,n){return n?[...e].filter(e=>e===n).length:t(e).length}function r(e){return[...e].reduce((e,t)=>(e[t]=(e[t]||0)+1,e),{})}function i(e){return e?t(e,/\r\n|\r|\n/).length:0}function a(e,n){return n.length===0?0:t(e,n).length-1}function o(e){return t(e.trim()).length}function s(e,t=``){return e.replace(/[^\p{L}\p{N}\s]/gu,t)}function c(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.max(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function l(e){let n=t(e).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.max(e,t.length),0)}function u(e,t,n=` `){return e.padStart(t,n)}function d(e,t,n=` `){return e.padEnd(t,n)}function f(e,t){return e.repeat(t)}function p(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.min(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function m(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.min(e,t.length),1/0)}const h=Object.assign(e=>e.trim(),{start:e=>e.trimStart(),end:e=>e.trimEnd(),normalizeWhitespace:e=>e.trim().replace(/\s+/g,` `)});function g(e,t,n=`...`){return t<=0?``:e.length<=t?e:n.length>=t?n.slice(0,t):e.trim().slice(0,t)+n}function _(e){return[...new Set(e)]}exports.capitalize=e,exports.countChars=n,exports.countFrequencies=r,exports.countLines=i,exports.countSubstring=a,exports.countWords=o,exports.longestWord=c,exports.longestWordLength=l,exports.padLeft=u,exports.padRight=d,exports.repeatString=f,exports.shortestWord=p,exports.shortestWordLength=m,exports.splitString=t,exports.stripSymbols=s,exports.trim=h,exports.truncate=g,exports.uniqueChars=_;
package/dist/index.d.cts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Trim } from "@js-utils-kit/types";
2
- export * from "@js-utils-kit/types";
3
2
 
4
3
  //#region src/capitalize.d.ts
5
-
6
4
  /**
7
5
  * Capitalizes the first character of a string using a regular expression.
8
6
  *
@@ -16,8 +14,7 @@ export * from "@js-utils-kit/types";
16
14
  * capitalize("a"); // "A"
17
15
  * ```
18
16
  */
19
- declare function capitalize(/** The string to capitalize */
20
- value: string): string;
17
+ declare function capitalize(/** The string to capitalize */value: string): string;
21
18
  //#endregion
22
19
  //#region src/countChars.d.ts
23
20
  /**
@@ -36,9 +33,7 @@ value: string): string;
36
33
  * countChars("banana", "n"); // 2
37
34
  * ```
38
35
  */
39
- declare function countChars(/** The input string. */
40
- str: string, /** Optional character to count. */
41
- char?: string): number;
36
+ declare function countChars(/** The input string. */str: string, /** Optional character to count. */char?: string): number;
42
37
  //#endregion
43
38
  //#region src/countFrequencies.d.ts
44
39
  /**
@@ -60,6 +55,7 @@ char?: string): number;
60
55
  * ```
61
56
  */
62
57
  declare function countFrequencies(/** The input string. */
58
+
63
59
  str: string): Record<string, number>;
64
60
  //#endregion
65
61
  //#region src/countLines.d.ts
@@ -79,6 +75,7 @@ str: string): Record<string, number>;
79
75
  * ```
80
76
  */
81
77
  declare function countLines(/** The input string. */
78
+
82
79
  str: string): number;
83
80
  //#endregion
84
81
  //#region src/countSubstring.d.ts
@@ -99,7 +96,9 @@ str: string): number;
99
96
  * ```
100
97
  */
101
98
  declare function countSubstring(/** The input string. */
99
+
102
100
  str: string, /** The substring to count. */
101
+
103
102
  sub: string): number;
104
103
  //#endregion
105
104
  //#region src/countWords.d.ts
@@ -116,6 +115,7 @@ sub: string): number;
116
115
  * ```
117
116
  */
118
117
  declare function countWords(/** The input string */
118
+
119
119
  str: string): number;
120
120
  //#endregion
121
121
  //#region src/longestWord.d.ts
@@ -138,6 +138,7 @@ str: string): number;
138
138
  * ```
139
139
  */
140
140
  declare function longestWord(/** The input string. */
141
+
141
142
  str: string): string | string[];
142
143
  //#endregion
143
144
  //#region src/longestWordLength.d.ts
@@ -160,6 +161,7 @@ str: string): string | string[];
160
161
  * ```
161
162
  */
162
163
  declare function longestWordLength(/** The input string. */
164
+
163
165
  str: string): number;
164
166
  //#endregion
165
167
  //#region src/padLeft.d.ts
@@ -177,13 +179,16 @@ str: string): number;
177
179
  * ```
178
180
  */
179
181
  declare function padLeft(/** The string to pad */
182
+
180
183
  str: string, /** The target length of the padded string */
184
+
181
185
  length: number,
182
186
  /**
183
187
  * The character to use for padding (defaults to a space)
184
188
  *
185
189
  * @default ' '
186
190
  */
191
+
187
192
  char?: string): string;
188
193
  //#endregion
189
194
  //#region src/padRight.d.ts
@@ -201,13 +206,16 @@ char?: string): string;
201
206
  * ```
202
207
  */
203
208
  declare function padRight(/** The string to pad */
209
+
204
210
  str: string, /** The target length of the padded string */
211
+
205
212
  length: number,
206
213
  /**
207
214
  * The character to use for padding (defaults to a space)
208
215
  *
209
216
  * @default ' '
210
217
  */
218
+
211
219
  char?: string): string;
212
220
  //#endregion
213
221
  //#region src/repeatString.d.ts
@@ -225,7 +233,9 @@ char?: string): string;
225
233
  * ```
226
234
  */
227
235
  declare function repeatString(/** The string to repeat */
236
+
228
237
  str: string, /** The number of times to repeat the string (must be non-negative) */
238
+
229
239
  count: number): string;
230
240
  //#endregion
231
241
  //#region src/shortestWord.d.ts
@@ -248,6 +258,7 @@ count: number): string;
248
258
  * ```
249
259
  */
250
260
  declare function shortestWord(/** The input string. */
261
+
251
262
  str: string): string | string[];
252
263
  //#endregion
253
264
  //#region src/shortestWordLength.d.ts
@@ -269,6 +280,7 @@ str: string): string | string[];
269
280
  * ```
270
281
  */
271
282
  declare function shortestWordLength(/** The input string. */
283
+
272
284
  str: string): number;
273
285
  //#endregion
274
286
  //#region src/splitString.d.ts
@@ -291,12 +303,14 @@ str: string): number;
291
303
  * ```
292
304
  */
293
305
  declare function splitString(/** The input string to split. */
306
+
294
307
  str: string,
295
308
  /**
296
309
  * The delimiter (string or RegExp)
297
310
  *
298
311
  * @default whitespace `/\s+/`
299
312
  */
313
+
300
314
  val?: string | RegExp): string[];
301
315
  //#endregion
302
316
  //#region src/stripSymbols.d.ts
@@ -319,12 +333,14 @@ val?: string | RegExp): string[];
319
333
  * ```
320
334
  */
321
335
  declare function stripSymbols(/** The input string */
336
+
322
337
  str: string,
323
338
  /**
324
339
  * Optional replacement string for removed symbols.
325
340
  *
326
341
  * @default ""
327
342
  */
343
+
328
344
  replacement?: string): string;
329
345
  //#endregion
330
346
  //#region src/trim.d.ts
@@ -383,13 +399,16 @@ declare const trim: Trim;
383
399
  * ```
384
400
  */
385
401
  declare function truncate(/** The string to truncate */
402
+
386
403
  str: string, /** The maximum length of the resulting string */
404
+
387
405
  length: number,
388
406
  /**
389
407
  * The suffix to append if truncation occurs
390
408
  *
391
409
  * @default "..."
392
410
  */
411
+
393
412
  suffix?: string): string;
394
413
  //#endregion
395
414
  //#region src/uniqueChars.d.ts
@@ -408,6 +427,7 @@ suffix?: string): string;
408
427
  * ```
409
428
  */
410
429
  declare function uniqueChars(/** The input string. */
430
+
411
431
  str: string): string[];
412
432
  //#endregion
413
433
  export { capitalize, countChars, countFrequencies, countLines, countSubstring, countWords, longestWord, longestWordLength, padLeft, padRight, repeatString, shortestWord, shortestWordLength, splitString, stripSymbols, trim, truncate, uniqueChars };
package/dist/index.d.mts CHANGED
@@ -1,8 +1,6 @@
1
1
  import { Trim } from "@js-utils-kit/types";
2
- export * from "@js-utils-kit/types";
3
2
 
4
3
  //#region src/capitalize.d.ts
5
-
6
4
  /**
7
5
  * Capitalizes the first character of a string using a regular expression.
8
6
  *
@@ -16,8 +14,7 @@ export * from "@js-utils-kit/types";
16
14
  * capitalize("a"); // "A"
17
15
  * ```
18
16
  */
19
- declare function capitalize(/** The string to capitalize */
20
- value: string): string;
17
+ declare function capitalize(/** The string to capitalize */value: string): string;
21
18
  //#endregion
22
19
  //#region src/countChars.d.ts
23
20
  /**
@@ -36,9 +33,7 @@ value: string): string;
36
33
  * countChars("banana", "n"); // 2
37
34
  * ```
38
35
  */
39
- declare function countChars(/** The input string. */
40
- str: string, /** Optional character to count. */
41
- char?: string): number;
36
+ declare function countChars(/** The input string. */str: string, /** Optional character to count. */char?: string): number;
42
37
  //#endregion
43
38
  //#region src/countFrequencies.d.ts
44
39
  /**
@@ -60,6 +55,7 @@ char?: string): number;
60
55
  * ```
61
56
  */
62
57
  declare function countFrequencies(/** The input string. */
58
+
63
59
  str: string): Record<string, number>;
64
60
  //#endregion
65
61
  //#region src/countLines.d.ts
@@ -79,6 +75,7 @@ str: string): Record<string, number>;
79
75
  * ```
80
76
  */
81
77
  declare function countLines(/** The input string. */
78
+
82
79
  str: string): number;
83
80
  //#endregion
84
81
  //#region src/countSubstring.d.ts
@@ -99,7 +96,9 @@ str: string): number;
99
96
  * ```
100
97
  */
101
98
  declare function countSubstring(/** The input string. */
99
+
102
100
  str: string, /** The substring to count. */
101
+
103
102
  sub: string): number;
104
103
  //#endregion
105
104
  //#region src/countWords.d.ts
@@ -116,6 +115,7 @@ sub: string): number;
116
115
  * ```
117
116
  */
118
117
  declare function countWords(/** The input string */
118
+
119
119
  str: string): number;
120
120
  //#endregion
121
121
  //#region src/longestWord.d.ts
@@ -138,6 +138,7 @@ str: string): number;
138
138
  * ```
139
139
  */
140
140
  declare function longestWord(/** The input string. */
141
+
141
142
  str: string): string | string[];
142
143
  //#endregion
143
144
  //#region src/longestWordLength.d.ts
@@ -160,6 +161,7 @@ str: string): string | string[];
160
161
  * ```
161
162
  */
162
163
  declare function longestWordLength(/** The input string. */
164
+
163
165
  str: string): number;
164
166
  //#endregion
165
167
  //#region src/padLeft.d.ts
@@ -177,13 +179,16 @@ str: string): number;
177
179
  * ```
178
180
  */
179
181
  declare function padLeft(/** The string to pad */
182
+
180
183
  str: string, /** The target length of the padded string */
184
+
181
185
  length: number,
182
186
  /**
183
187
  * The character to use for padding (defaults to a space)
184
188
  *
185
189
  * @default ' '
186
190
  */
191
+
187
192
  char?: string): string;
188
193
  //#endregion
189
194
  //#region src/padRight.d.ts
@@ -201,13 +206,16 @@ char?: string): string;
201
206
  * ```
202
207
  */
203
208
  declare function padRight(/** The string to pad */
209
+
204
210
  str: string, /** The target length of the padded string */
211
+
205
212
  length: number,
206
213
  /**
207
214
  * The character to use for padding (defaults to a space)
208
215
  *
209
216
  * @default ' '
210
217
  */
218
+
211
219
  char?: string): string;
212
220
  //#endregion
213
221
  //#region src/repeatString.d.ts
@@ -225,7 +233,9 @@ char?: string): string;
225
233
  * ```
226
234
  */
227
235
  declare function repeatString(/** The string to repeat */
236
+
228
237
  str: string, /** The number of times to repeat the string (must be non-negative) */
238
+
229
239
  count: number): string;
230
240
  //#endregion
231
241
  //#region src/shortestWord.d.ts
@@ -248,6 +258,7 @@ count: number): string;
248
258
  * ```
249
259
  */
250
260
  declare function shortestWord(/** The input string. */
261
+
251
262
  str: string): string | string[];
252
263
  //#endregion
253
264
  //#region src/shortestWordLength.d.ts
@@ -269,6 +280,7 @@ str: string): string | string[];
269
280
  * ```
270
281
  */
271
282
  declare function shortestWordLength(/** The input string. */
283
+
272
284
  str: string): number;
273
285
  //#endregion
274
286
  //#region src/splitString.d.ts
@@ -291,12 +303,14 @@ str: string): number;
291
303
  * ```
292
304
  */
293
305
  declare function splitString(/** The input string to split. */
306
+
294
307
  str: string,
295
308
  /**
296
309
  * The delimiter (string or RegExp)
297
310
  *
298
311
  * @default whitespace `/\s+/`
299
312
  */
313
+
300
314
  val?: string | RegExp): string[];
301
315
  //#endregion
302
316
  //#region src/stripSymbols.d.ts
@@ -319,12 +333,14 @@ val?: string | RegExp): string[];
319
333
  * ```
320
334
  */
321
335
  declare function stripSymbols(/** The input string */
336
+
322
337
  str: string,
323
338
  /**
324
339
  * Optional replacement string for removed symbols.
325
340
  *
326
341
  * @default ""
327
342
  */
343
+
328
344
  replacement?: string): string;
329
345
  //#endregion
330
346
  //#region src/trim.d.ts
@@ -383,13 +399,16 @@ declare const trim: Trim;
383
399
  * ```
384
400
  */
385
401
  declare function truncate(/** The string to truncate */
402
+
386
403
  str: string, /** The maximum length of the resulting string */
404
+
387
405
  length: number,
388
406
  /**
389
407
  * The suffix to append if truncation occurs
390
408
  *
391
409
  * @default "..."
392
410
  */
411
+
393
412
  suffix?: string): string;
394
413
  //#endregion
395
414
  //#region src/uniqueChars.d.ts
@@ -408,6 +427,7 @@ suffix?: string): string;
408
427
  * ```
409
428
  */
410
429
  declare function uniqueChars(/** The input string. */
430
+
411
431
  str: string): string[];
412
432
  //#endregion
413
433
  export { capitalize, countChars, countFrequencies, countLines, countSubstring, countWords, longestWord, longestWordLength, padLeft, padRight, repeatString, shortestWord, shortestWordLength, splitString, stripSymbols, trim, truncate, uniqueChars };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export*from"@js-utils-kit/types";function e(e){return e.replace(/^\w/,e=>e.toUpperCase())}function t(e,t=/\s+/){return e.split(t)}function n(e,n){return n?[...e].filter(e=>e===n).length:t(e).length}function r(e){return[...e].reduce((e,t)=>(e[t]=(e[t]||0)+1,e),{})}function i(e){return e?t(e,/\r\n|\r|\n/).length:0}function a(e,n){return n.length===0?0:t(e,n).length-1}function o(e){return t(e.trim()).length}function s(e,t=``){return e.replace(/[^\p{L}\p{N}\s]/gu,t)}function c(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.max(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function l(e){let n=t(e).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.max(e,t.length),0)}function u(e,t,n=` `){return e.padStart(t,n)}function d(e,t,n=` `){return e.padEnd(t,n)}function f(e,t){return e.repeat(t)}function p(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.min(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function m(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.min(e,t.length),1/0)}const h=Object.assign(e=>e.trim(),{start:e=>e.trimStart(),end:e=>e.trimEnd(),normalizeWhitespace:e=>e.trim().replace(/\s+/g,` `)});function g(e,t,n=`...`){return t<=0?``:e.length<=t?e:n.length>=t?n.slice(0,t):e.trim().slice(0,t)+n}function _(e){return[...new Set(e)]}export{e as capitalize,n as countChars,r as countFrequencies,i as countLines,a as countSubstring,o as countWords,c as longestWord,l as longestWordLength,u as padLeft,d as padRight,f as repeatString,p as shortestWord,m as shortestWordLength,t as splitString,s as stripSymbols,h as trim,g as truncate,_ as uniqueChars};
1
+ function e(e){return e.replace(/^\w/,e=>e.toUpperCase())}function t(e,t=/\s+/){return e.split(t)}function n(e,n){return n?[...e].filter(e=>e===n).length:t(e).length}function r(e){return[...e].reduce((e,t)=>(e[t]=(e[t]||0)+1,e),{})}function i(e){return e?t(e,/\r\n|\r|\n/).length:0}function a(e,n){return n.length===0?0:t(e,n).length-1}function o(e){return t(e.trim()).length}function s(e,t=``){return e.replace(/[^\p{L}\p{N}\s]/gu,t)}function c(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.max(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function l(e){let n=t(e).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.max(e,t.length),0)}function u(e,t,n=` `){return e.padStart(t,n)}function d(e,t,n=` `){return e.padEnd(t,n)}function f(e,t){return e.repeat(t)}function p(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);if(n.length===0)return``;let r=Math.min(...n.map(e=>e.length)),i=n.filter(e=>e.length===r),a=[...new Set(i)];return a.length===1?a[0]:a}function m(e){let n=t(e.trim()).map(e=>s(e)).filter(Boolean);return n.length===0?0:n.reduce((e,t)=>Math.min(e,t.length),1/0)}const h=Object.assign(e=>e.trim(),{start:e=>e.trimStart(),end:e=>e.trimEnd(),normalizeWhitespace:e=>e.trim().replace(/\s+/g,` `)});function g(e,t,n=`...`){return t<=0?``:e.length<=t?e:n.length>=t?n.slice(0,t):e.trim().slice(0,t)+n}function _(e){return[...new Set(e)]}export{e as capitalize,n as countChars,r as countFrequencies,i as countLines,a as countSubstring,o as countWords,c as longestWord,l as longestWordLength,u as padLeft,d as padRight,f as repeatString,p as shortestWord,m as shortestWordLength,t as splitString,s as stripSymbols,h as trim,g as truncate,_ as uniqueChars};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@js-utils-kit/string",
3
- "version": "1.0.1",
3
+ "version": "1.2.0",
4
4
  "description": "String utilities",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -43,12 +43,12 @@
43
43
  "types": "./dist/index.d.cts",
44
44
  "exports": {
45
45
  ".": {
46
- "import": "./dist/index.mjs",
47
- "require": "./dist/index.cjs"
46
+ "require": "./dist/index.cjs",
47
+ "import": "./dist/index.mjs"
48
48
  }
49
49
  },
50
50
  "dependencies": {
51
- "@js-utils-kit/types": "1.0.0"
51
+ "@js-utils-kit/types": "1.2.0"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "tsdown",