string-extn 1.0.11 โ†’ 1.1.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 CHANGED
@@ -18,6 +18,10 @@ A lightweight, TypeScript-first library for **safe and functional string manipul
18
18
  - [URL & Filename Safe Conversion](#url--filename-safe-conversion)
19
19
  - [String Validation](#string-validation)
20
20
  - [Unicode Operations](#unicode-operations)
21
+ - [Internationalization](#internationalization)
22
+ - [Security & Sanitization](#security--sanitization)
23
+ - [Performance Helpers](#performance-helpers)
24
+ - [Stream Utilities](#stream-utilities)
21
25
  - [Examples](#examples)
22
26
  - [Testing](#testing)
23
27
  - [License](#license)
@@ -69,6 +73,23 @@ A lightweight, TypeScript-first library for **safe and functional string manipul
69
73
  - **unicodeSlice** - Slice strings while respecting grapheme boundaries
70
74
  - **reverseUnicode** - Reverse strings with proper emoji and combining mark support
71
75
 
76
+ ### ๐ŸŒ Internationalization
77
+ - **localeCompare** - Locale-aware string comparison with configurable sensitivity
78
+ - **normalizeUnicode** - Normalize strings to NFC/NFD/NFKC/NFKD
79
+
80
+ ### ๐Ÿ” Security & Sanitization
81
+ - **escapeHTML** - Escape HTML-reserved characters
82
+ - **escapeSQL** - Escape SQL-sensitive characters
83
+ - **sanitizePath** - Remove traversal and dot segments from paths
84
+
85
+ ### โšก Performance Helpers
86
+ - **fastRepeat** - Repeat strings using a fast doubling approach
87
+ - **fastPadLeft** - Left-pad strings using fast repeat
88
+
89
+ ### ๐ŸŒŠ Stream Utilities
90
+ - **chunkString** - Split strings into fixed-size chunks
91
+ - **streamTransform** - Transform chunks and concatenate results
92
+
72
93
  ---
73
94
 
74
95
  ## Installation
@@ -211,6 +232,35 @@ reverseUnicode(emojiStr); // "๐Ÿ‘๐Ÿ‘๐Ÿฝ"
211
232
  | `unicodeSlice` | `unicodeSlice(str: string, start: number, end?: number): string` | Slices by grapheme boundaries |
212
233
  | `reverseUnicode` | `reverseUnicode(str: string): string` | Reverses with emoji/modifier support |
213
234
 
235
+ ### Internationalization
236
+
237
+ | Function | Signature | Description |
238
+ |----------|-----------|-------------|
239
+ | `localeCompare` | `localeCompare(a: string, b: string, locale?: string, sensitivity?: "base" | "accent" | "case" | "variant"): number` | Locale-aware string comparison |
240
+ | `normalizeUnicode` | `normalizeUnicode(input: string, form?: "NFC" | "NFD" | "NFKC" | "NFKD"): string` | Unicode normalization |
241
+
242
+ ### Security & Sanitization
243
+
244
+ | Function | Signature | Description |
245
+ |----------|-----------|-------------|
246
+ | `escapeHTML` | `escapeHTML(input: string): string` | Escapes HTML-reserved characters |
247
+ | `escapeSQL` | `escapeSQL(input: string): string` | Escapes SQL-sensitive characters |
248
+ | `sanitizePath` | `sanitizePath(input: string): string` | Removes traversal and dot segments |
249
+
250
+ ### Performance Helpers
251
+
252
+ | Function | Signature | Description |
253
+ |----------|-----------|-------------|
254
+ | `fastRepeat` | `fastRepeat(input: string, count: number): string` | Fast string repetition |
255
+ | `fastPadLeft` | `fastPadLeft(input: string, length: number, char?: string): string` | Fast left padding |
256
+
257
+ ### Stream Utilities
258
+
259
+ | Function | Signature | Description |
260
+ |----------|-----------|-------------|
261
+ | `chunkString` | `chunkString(input: string, size: number): string[]` | Split string into chunks |
262
+ | `streamTransform` | `streamTransform(chunks: string[], transformer: (chunk: string) => string): string` | Transform and concatenate |
263
+
214
264
  ---
215
265
 
216
266
  ## Examples
@@ -307,7 +357,30 @@ console.log(unicodeSlice(message, 6, 8)); // "๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ "
307
357
  console.log(reverseUnicode(message)); // Preserves emoji integrity
308
358
  ```
309
359
 
310
- ### Example 3: Function Composition
360
+ ### Example 8: Internationalization and Security
361
+
362
+ ```typescript
363
+ import { localeCompare, normalizeUnicode, escapeHTML, sanitizePath } from 'string-extn';
364
+
365
+ console.log(localeCompare('resume', 'rรฉsumรฉ', 'en', 'accent')); // Non-zero
366
+ console.log(normalizeUnicode('e\u0301', 'NFC')); // "\u00e9"
367
+ console.log(escapeHTML('<script>alert(1)</script>')); // Escaped HTML entities
368
+ console.log(sanitizePath('/var/../tmp')); // "/var/tmp"
369
+ ```
370
+
371
+ ### Example 9: Performance and Streams
372
+
373
+ ```typescript
374
+ import { fastRepeat, fastPadLeft, chunkString, streamTransform } from 'string-extn';
375
+
376
+ console.log(fastRepeat('ab', 4)); // "abababab"
377
+ console.log(fastPadLeft('7', 3, '0')); // "007"
378
+
379
+ const chunks = chunkString('abcdef', 2); // ["ab", "cd", "ef"]
380
+ console.log(streamTransform(chunks, c => c.toUpperCase())); // "ABCDEF"
381
+ ```
382
+
383
+ ### Example 10: Function Composition
311
384
 
312
385
  ```typescript
313
386
  import { compose } from 'string-extn';
package/dist/index.d.ts CHANGED
@@ -7,4 +7,8 @@ export * from './mask.js';
7
7
  export * from './similarity.js';
8
8
  export * from './diff.js';
9
9
  export * from './validate.js';
10
+ export * from './intl.js';
11
+ export * from './perf.js';
12
+ export * from './security.js';
13
+ export * from './stream.js';
10
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -7,4 +7,8 @@ export * from './mask.js';
7
7
  export * from './similarity.js';
8
8
  export * from './diff.js';
9
9
  export * from './validate.js';
10
+ export * from './intl.js';
11
+ export * from './perf.js';
12
+ export * from './security.js';
13
+ export * from './stream.js';
10
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,CAAC"}
package/dist/intl.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Compares two strings using locale-aware collation rules.
3
+ *
4
+ * @param a - The first string to compare.
5
+ * @param b - The second string to compare.
6
+ * @param locale - BCP 47 locale tag used for collation (defaults to "en").
7
+ * @param sensitivity - Controls how differences in case/diacritics are handled.
8
+ * @returns A negative number if `a` sorts before `b`, positive if after, or 0 if equal.
9
+ *
10
+ * Special behavior: Uses `Intl.Collator`, which provides Unicode-aware comparison.
11
+ */
12
+ export declare function localeCompare(a: string, b: string, locale?: string, sensitivity?: Intl.CollatorOptions["sensitivity"]): number;
13
+ /**
14
+ * Normalizes a string to the specified Unicode normalization form.
15
+ *
16
+ * @param input - The string to normalize.
17
+ * @param form - The Unicode normalization form (NFC, NFD, NFKC, or NFKD).
18
+ * @returns The normalized string.
19
+ *
20
+ * Special behavior: Preserves Unicode text while normalizing code point sequences.
21
+ */
22
+ export declare function normalizeUnicode(input: string, form?: "NFC" | "NFD" | "NFKC" | "NFKD"): string;
23
+ //# sourceMappingURL=intl.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../src/intl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC3B,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,SAAO,EACb,WAAW,GAAE,IAAI,CAAC,eAAe,CAAC,aAAa,CAAU,GACxD,MAAM,CAER;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,MAAM,EACb,IAAI,GAAE,KAAK,GAAG,KAAK,GAAG,MAAM,GAAG,MAAc,GAC5C,MAAM,CAER"}
package/dist/intl.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Compares two strings using locale-aware collation rules.
3
+ *
4
+ * @param a - The first string to compare.
5
+ * @param b - The second string to compare.
6
+ * @param locale - BCP 47 locale tag used for collation (defaults to "en").
7
+ * @param sensitivity - Controls how differences in case/diacritics are handled.
8
+ * @returns A negative number if `a` sorts before `b`, positive if after, or 0 if equal.
9
+ *
10
+ * Special behavior: Uses `Intl.Collator`, which provides Unicode-aware comparison.
11
+ */
12
+ export function localeCompare(a, b, locale = "en", sensitivity = "base") {
13
+ return new Intl.Collator(locale, { sensitivity }).compare(a, b);
14
+ }
15
+ /**
16
+ * Normalizes a string to the specified Unicode normalization form.
17
+ *
18
+ * @param input - The string to normalize.
19
+ * @param form - The Unicode normalization form (NFC, NFD, NFKC, or NFKD).
20
+ * @returns The normalized string.
21
+ *
22
+ * Special behavior: Preserves Unicode text while normalizing code point sequences.
23
+ */
24
+ export function normalizeUnicode(input, form = "NFC") {
25
+ return input.normalize(form);
26
+ }
27
+ //# sourceMappingURL=intl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intl.js","sourceRoot":"","sources":["../src/intl.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,aAAa,CAC3B,CAAS,EACT,CAAS,EACT,MAAM,GAAG,IAAI,EACb,cAAmD,MAAM;IAEzD,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAClE,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAC9B,KAAa,EACb,OAAwC,KAAK;IAE7C,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
package/dist/perf.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Repeats a string using a fast doubling technique.
3
+ *
4
+ * @param input - The string to repeat.
5
+ * @param count - The number of times to repeat the string.
6
+ * @returns The repeated string, or an empty string when count is not positive or not finite.
7
+ *
8
+ * Special behavior: Non-integer counts are floored; non-finite or non-positive counts return "".
9
+ */
10
+ export declare function fastRepeat(input: string, count: number): string;
11
+ /**
12
+ * Pads the left side of a string to a target length using a fast repeat.
13
+ *
14
+ * @param input - The string to pad.
15
+ * @param length - The desired total length of the result.
16
+ * @param char - The padding character (defaults to a space).
17
+ * @returns The padded string, or the original string if already long enough.
18
+ *
19
+ * Special behavior: Uses code unit length and does not trim or normalize input.
20
+ */
21
+ export declare function fastPadLeft(input: string, length: number, char?: string): string;
22
+ //# sourceMappingURL=perf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf.d.ts","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAY/D;AAED;;;;;;;;;GASG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,EACd,IAAI,SAAM,GACT,MAAM,CAGR"}
package/dist/perf.js ADDED
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Repeats a string using a fast doubling technique.
3
+ *
4
+ * @param input - The string to repeat.
5
+ * @param count - The number of times to repeat the string.
6
+ * @returns The repeated string, or an empty string when count is not positive or not finite.
7
+ *
8
+ * Special behavior: Non-integer counts are floored; non-finite or non-positive counts return "".
9
+ */
10
+ export function fastRepeat(input, count) {
11
+ if (!Number.isFinite(count) || count <= 0)
12
+ return "";
13
+ let remaining = Math.floor(count);
14
+ let result = "";
15
+ let current = input;
16
+ while (remaining > 0) {
17
+ if (remaining & 1)
18
+ result += current;
19
+ current += current;
20
+ remaining >>= 1;
21
+ }
22
+ return result;
23
+ }
24
+ /**
25
+ * Pads the left side of a string to a target length using a fast repeat.
26
+ *
27
+ * @param input - The string to pad.
28
+ * @param length - The desired total length of the result.
29
+ * @param char - The padding character (defaults to a space).
30
+ * @returns The padded string, or the original string if already long enough.
31
+ *
32
+ * Special behavior: Uses code unit length and does not trim or normalize input.
33
+ */
34
+ export function fastPadLeft(input, length, char = " ") {
35
+ if (input.length >= length)
36
+ return input;
37
+ return fastRepeat(char, length - input.length) + input;
38
+ }
39
+ //# sourceMappingURL=perf.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"perf.js","sourceRoot":"","sources":["../src/perf.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,KAAa;IACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACrD,IAAI,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAClC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,OAAO,GAAG,KAAK,CAAC;IAEpB,OAAO,SAAS,GAAG,CAAC,EAAE,CAAC;QACrB,IAAI,SAAS,GAAG,CAAC;YAAE,MAAM,IAAI,OAAO,CAAC;QACrC,OAAO,IAAI,OAAO,CAAC;QACnB,SAAS,KAAK,CAAC,CAAC;IAClB,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,WAAW,CACzB,KAAa,EACb,MAAc,EACd,IAAI,GAAG,GAAG;IAEV,IAAI,KAAK,CAAC,MAAM,IAAI,MAAM;QAAE,OAAO,KAAK,CAAC;IACzC,OAAO,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;AACzD,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Escapes HTML-reserved characters to their entity equivalents.
3
+ *
4
+ * @param input - The string to escape.
5
+ * @returns The escaped string with HTML-sensitive characters replaced.
6
+ *
7
+ * Special behavior: Escapes `&`, `<`, `>`, `"`, and `'` characters; does not decode entities.
8
+ */
9
+ export declare function escapeHTML(input: string): string;
10
+ /**
11
+ * Escapes SQL-sensitive characters by prefixing them with a backslash.
12
+ *
13
+ * @param input - The string to escape.
14
+ * @returns The escaped string with `'`, `"`, `;`, and `\` prefixed by `\`.
15
+ *
16
+ * Special behavior: Simple escaping helper; it does not validate SQL or prevent all injection cases.
17
+ */
18
+ export declare function escapeSQL(input: string): string;
19
+ /**
20
+ * Sanitizes a path-like string by removing traversal and dot segments.
21
+ *
22
+ * @param input - The path string to sanitize.
23
+ * @returns The sanitized path with `.` and `..` segments removed.
24
+ *
25
+ * Special behavior: Preserves a leading separator and normalizes repeated separators.
26
+ */
27
+ export declare function sanitizePath(input: string): string;
28
+ //# sourceMappingURL=security.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.d.ts","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAQA;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAEhD;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CASlD"}
@@ -0,0 +1,47 @@
1
+ const ESCAPE_MAP = {
2
+ "&": "&amp;",
3
+ "<": "&lt;",
4
+ ">": "&gt;",
5
+ '"': "&quot;",
6
+ "'": "&#x27;"
7
+ };
8
+ /**
9
+ * Escapes HTML-reserved characters to their entity equivalents.
10
+ *
11
+ * @param input - The string to escape.
12
+ * @returns The escaped string with HTML-sensitive characters replaced.
13
+ *
14
+ * Special behavior: Escapes `&`, `<`, `>`, `"`, and `'` characters; does not decode entities.
15
+ */
16
+ export function escapeHTML(input) {
17
+ return input.replace(/[&<>"']/g, char => ESCAPE_MAP[char] ?? char);
18
+ }
19
+ /**
20
+ * Escapes SQL-sensitive characters by prefixing them with a backslash.
21
+ *
22
+ * @param input - The string to escape.
23
+ * @returns The escaped string with `'`, `"`, `;`, and `\` prefixed by `\`.
24
+ *
25
+ * Special behavior: Simple escaping helper; it does not validate SQL or prevent all injection cases.
26
+ */
27
+ export function escapeSQL(input) {
28
+ return input.replace(/['";\\]/g, "\\$&");
29
+ }
30
+ /**
31
+ * Sanitizes a path-like string by removing traversal and dot segments.
32
+ *
33
+ * @param input - The path string to sanitize.
34
+ * @returns The sanitized path with `.` and `..` segments removed.
35
+ *
36
+ * Special behavior: Preserves a leading separator and normalizes repeated separators.
37
+ */
38
+ export function sanitizePath(input) {
39
+ const separator = input.includes("/") ? "/" : "\\";
40
+ const hasLeadingSeparator = input.startsWith("/") || input.startsWith("\\");
41
+ const parts = input
42
+ .split(/[\\/]+/)
43
+ .filter(part => part !== "" && part !== "." && part !== "..");
44
+ const sanitized = parts.join(separator);
45
+ return hasLeadingSeparator ? `${separator}${sanitized}` : sanitized;
46
+ }
47
+ //# sourceMappingURL=security.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"security.js","sourceRoot":"","sources":["../src/security.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAA2B;IACzC,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,QAAQ;CACd,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa;IACtC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,KAAa;IACrC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,YAAY,CAAC,KAAa;IACxC,MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;IACnD,MAAM,mBAAmB,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC5E,MAAM,KAAK,GAAG,KAAK;SAChB,KAAK,CAAC,QAAQ,CAAC;SACf,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,KAAK,EAAE,IAAI,IAAI,KAAK,GAAG,IAAI,IAAI,KAAK,IAAI,CAAC,CAAC;IAEhE,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACxC,OAAO,mBAAmB,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,SAAS,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACtE,CAAC"}
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Splits a string into an array of fixed-size chunks.
3
+ *
4
+ * @param input - The string to split.
5
+ * @param size - The chunk size in code units; must be a positive, finite number.
6
+ * @returns An array of chunk strings.
7
+ *
8
+ * Special behavior: Throws when size is non-positive or non-finite.
9
+ */
10
+ export declare function chunkString(input: string, size: number): string[];
11
+ /**
12
+ * Applies a transformer to each chunk and concatenates the results.
13
+ *
14
+ * @param chunks - The list of chunks to transform.
15
+ * @param transformer - The function applied to each chunk.
16
+ * @returns The concatenated transformed result.
17
+ *
18
+ * Special behavior: Preserves chunk order and performs a simple left-to-right join.
19
+ */
20
+ export declare function streamTransform(chunks: string[], transformer: (chunk: string) => string): string;
21
+ //# sourceMappingURL=stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CASjE;AAGD;;;;;;;;GAQG;AACH,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EAAE,EAChB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GACrC,MAAM,CAMR"}
package/dist/stream.js ADDED
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Splits a string into an array of fixed-size chunks.
3
+ *
4
+ * @param input - The string to split.
5
+ * @param size - The chunk size in code units; must be a positive, finite number.
6
+ * @returns An array of chunk strings.
7
+ *
8
+ * Special behavior: Throws when size is non-positive or non-finite.
9
+ */
10
+ export function chunkString(input, size) {
11
+ if (!Number.isFinite(size) || size <= 0) {
12
+ throw new Error("Chunk size must be a positive number.");
13
+ }
14
+ const result = [];
15
+ for (let i = 0; i < input.length; i += size) {
16
+ result.push(input.slice(i, i + size));
17
+ }
18
+ return result;
19
+ }
20
+ /**
21
+ * Applies a transformer to each chunk and concatenates the results.
22
+ *
23
+ * @param chunks - The list of chunks to transform.
24
+ * @param transformer - The function applied to each chunk.
25
+ * @returns The concatenated transformed result.
26
+ *
27
+ * Special behavior: Preserves chunk order and performs a simple left-to-right join.
28
+ */
29
+ export function streamTransform(chunks, transformer) {
30
+ let result = "";
31
+ for (const chunk of chunks) {
32
+ result += transformer(chunk);
33
+ }
34
+ return result;
35
+ }
36
+ //# sourceMappingURL=stream.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stream.js","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AACA;;;;;;;;GAQG;AACH,MAAM,UAAU,WAAW,CAAC,KAAa,EAAE,IAAY;IACrD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,IAAI,IAAI,EAAE,CAAC;QAC5C,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;IACxC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAGD;;;;;;;;GAQG;AACH,MAAM,UAAU,eAAe,CAC7B,MAAgB,EAChB,WAAsC;IAEtC,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-extn",
3
- "version": "1.0.11",
3
+ "version": "1.1.0",
4
4
  "description": "Extended string utility functions for JavaScript and TypeScript.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -16,6 +16,17 @@
16
16
  "string",
17
17
  "utility",
18
18
  "functional",
19
+ "security",
20
+ "html-escape",
21
+ "sql-escape",
22
+ "path-sanitization",
23
+ "performance",
24
+ "fast-repeat",
25
+ "padding",
26
+ "stream",
27
+ "chunk",
28
+ "internationalization",
29
+ "i18n",
19
30
  "unicode",
20
31
  "typescript",
21
32
  "string-manipulation",