string-extn 1.1.0 → 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/README.md CHANGED
@@ -22,6 +22,10 @@ A lightweight, TypeScript-first library for **safe and functional string manipul
22
22
  - [Security & Sanitization](#security--sanitization)
23
23
  - [Performance Helpers](#performance-helpers)
24
24
  - [Stream Utilities](#stream-utilities)
25
+ - [Chaining & Fluent API](#chaining--fluent-api)
26
+ - [Lazy Evaluation](#lazy-evaluation)
27
+ - [Template Interpolation](#template-interpolation)
28
+ - [Plugin System](#plugin-system)
25
29
  - [Examples](#examples)
26
30
  - [Testing](#testing)
27
31
  - [License](#license)
@@ -90,6 +94,22 @@ A lightweight, TypeScript-first library for **safe and functional string manipul
90
94
  - **chunkString** - Split strings into fixed-size chunks
91
95
  - **streamTransform** - Transform chunks and concatenate results
92
96
 
97
+ ### 🔗 Chaining & Fluent API
98
+ - **chain** - Create chainable string transformations
99
+ - **StringChain** - Fluent wrapper with trim, case, replace, and reverse
100
+
101
+ ### 💤 Lazy Evaluation
102
+ - **lazy** - Build lazy transformation pipelines
103
+ - **LazyString** - Deferred execution via `execute()`
104
+
105
+ ### 🧩 Template Interpolation
106
+ - **template** - Replace {{key}} placeholders from a variable map
107
+
108
+ ### 🧩 Plugin System
109
+ - **registerPlugin** - Register a named string plugin
110
+ - **runPlugin** - Execute a registered plugin
111
+ - **listPlugins** - List registered plugin names
112
+
93
113
  ---
94
114
 
95
115
  ## Installation
@@ -145,6 +165,48 @@ unicodeSlice(emojiStr, 0, 1); // "👍🏽"
145
165
  reverseUnicode(emojiStr); // "👍👍🏽"
146
166
  ```
147
167
 
168
+ ### Chaining & Lazy Evaluation
169
+
170
+ ```typescript
171
+ import { chain, lazy } from 'string-extn';
172
+
173
+ const chained = chain(' Hello ')
174
+ .trim()
175
+ .toLower()
176
+ .replace('hello', 'hi')
177
+ .reverse()
178
+ .valueOf();
179
+ // "ih"
180
+
181
+ const pipeline = lazy(' Hello ')
182
+ .trim()
183
+ .toUpper();
184
+
185
+ pipeline.execute(); // "HELLO"
186
+ ```
187
+
188
+ ### Template Interpolation
189
+
190
+ ```typescript
191
+ import { template } from 'string-extn';
192
+
193
+ template('Hello {{name}}', { name: 'Ada' }); // "Hello Ada"
194
+ ```
195
+
196
+ ### Plugin System
197
+
198
+ ```typescript
199
+ import { registerPlugin, runPlugin, listPlugins } from 'string-extn';
200
+
201
+ registerPlugin({
202
+ name: 'wrap',
203
+ fn: (input, left: string, right: string) => `${left}${input}${right}`
204
+ });
205
+
206
+ runPlugin('wrap', 'core', '[', ']'); // "[core]"
207
+ listPlugins(); // ["wrap"]
208
+ ```
209
+
148
210
  ---
149
211
 
150
212
  ## API Reference
@@ -261,6 +323,44 @@ reverseUnicode(emojiStr); // "👍👍🏽"
261
323
  | `chunkString` | `chunkString(input: string, size: number): string[]` | Split string into chunks |
262
324
  | `streamTransform` | `streamTransform(chunks: string[], transformer: (chunk: string) => string): string` | Transform and concatenate |
263
325
 
326
+ ### Chaining & Fluent API
327
+
328
+ | Function | Signature | Description |
329
+ |----------|-----------|-------------|
330
+ | `chain` | `chain(input: string): StringChain` | Create a chainable string wrapper |
331
+ | `StringChain#trim` | `trim(): this` | Trim leading/trailing whitespace |
332
+ | `StringChain#toUpper` | `toUpper(): this` | Uppercase with default locale rules |
333
+ | `StringChain#toLower` | `toLower(): this` | Lowercase with default locale rules |
334
+ | `StringChain#replace` | `replace(search: string | RegExp, replacement: string): this` | Replace with string or RegExp |
335
+ | `StringChain#reverse` | `reverse(): this` | Reverse by Unicode code points |
336
+ | `StringChain#valueOf` | `valueOf(): string` | Get the current value |
337
+ | `StringChain#toString` | `toString(): string` | String coercion output |
338
+
339
+ ### Lazy Evaluation
340
+
341
+ | Function | Signature | Description |
342
+ |----------|-----------|-------------|
343
+ | `lazy` | `lazy(input: string): LazyString` | Create a lazy string wrapper |
344
+ | `LazyString#map` | `map(fn: (input: string) => string): this` | Register a deferred transform |
345
+ | `LazyString#trim` | `trim(): this` | Register a trim operation |
346
+ | `LazyString#toUpper` | `toUpper(): this` | Register uppercase conversion |
347
+ | `LazyString#toLower` | `toLower(): this` | Register lowercase conversion |
348
+ | `LazyString#execute` | `execute(): string` | Execute all operations in order |
349
+
350
+ ### Template Interpolation
351
+
352
+ | Function | Signature | Description |
353
+ |----------|-----------|-------------|
354
+ | `template` | `template(input: string, variables: Record<string, any>): string` | Replace {{key}} placeholders |
355
+
356
+ ### Plugin System
357
+
358
+ | Function | Signature | Description |
359
+ |----------|-----------|-------------|
360
+ | `registerPlugin` | `registerPlugin(plugin: StringExtnPlugin): void` | Register a named plugin |
361
+ | `runPlugin` | `runPlugin(name: string, input: string, ...args: any[]): string` | Execute a plugin by name |
362
+ | `listPlugins` | `listPlugins(): string[]` | List registered plugin names |
363
+
264
364
  ---
265
365
 
266
366
  ## Examples
@@ -0,0 +1,52 @@
1
+ export declare class StringChain {
2
+ private value;
3
+ /**
4
+ * Create a new chain wrapper for the provided input.
5
+ * @param input The string to wrap for chained operations.
6
+ */
7
+ constructor(input: string);
8
+ /**
9
+ * Trim leading and trailing whitespace from the current value.
10
+ * @returns The same chain instance for further chaining.
11
+ */
12
+ trim(): this;
13
+ /**
14
+ * Convert the current value to uppercase using default locale rules.
15
+ * @returns The same chain instance for further chaining.
16
+ */
17
+ toUpper(): this;
18
+ /**
19
+ * Convert the current value to lowercase using default locale rules.
20
+ * @returns The same chain instance for further chaining.
21
+ */
22
+ toLower(): this;
23
+ /**
24
+ * Replace a match in the current value using a string or RegExp search.
25
+ * @param search The string or RegExp pattern to search for.
26
+ * @param replacement The replacement string (supports RegExp replacement tokens).
27
+ * @returns The same chain instance for further chaining.
28
+ */
29
+ replace(search: string | RegExp, replacement: string): this;
30
+ /**
31
+ * Reverse the current value by Unicode code points.
32
+ * @returns The same chain instance for further chaining.
33
+ */
34
+ reverse(): this;
35
+ /**
36
+ * Get the current value as a string.
37
+ * @returns The current chained value.
38
+ */
39
+ valueOf(): string;
40
+ /**
41
+ * Convert the chain to a string for coercion or display.
42
+ * @returns The current chained value.
43
+ */
44
+ toString(): string;
45
+ }
46
+ /**
47
+ * Create a new `StringChain` instance for the provided input.
48
+ * @param input The string to wrap for chained operations.
49
+ * @returns A new `StringChain` instance.
50
+ */
51
+ export declare function chain(input: string): StringChain;
52
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,qBAAa,WAAW;IACtB,OAAO,CAAC,KAAK,CAAS;IAEtB;;;OAGG;gBACS,KAAK,EAAE,MAAM;IAIzB;;;OAGG;IACH,IAAI,IAAI,IAAI;IAKZ;;;OAGG;IACH,OAAO,IAAI,IAAI;IAKf;;;OAGG;IACH,OAAO,IAAI,IAAI;IAKf;;;;;OAKG;IACH,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,IAAI;IAK3D;;;OAGG;IACH,OAAO,IAAI,IAAI;IAKf;;;OAGG;IACH,OAAO,IAAI,MAAM;IAIjB;;;OAGG;IACH,QAAQ,IAAI,MAAM;CAGnB;AAED;;;;GAIG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,WAAW,CAEhD"}
package/dist/chain.js ADDED
@@ -0,0 +1,74 @@
1
+ export class StringChain {
2
+ /**
3
+ * Create a new chain wrapper for the provided input.
4
+ * @param input The string to wrap for chained operations.
5
+ */
6
+ constructor(input) {
7
+ this.value = input;
8
+ }
9
+ /**
10
+ * Trim leading and trailing whitespace from the current value.
11
+ * @returns The same chain instance for further chaining.
12
+ */
13
+ trim() {
14
+ this.value = this.value.trim();
15
+ return this;
16
+ }
17
+ /**
18
+ * Convert the current value to uppercase using default locale rules.
19
+ * @returns The same chain instance for further chaining.
20
+ */
21
+ toUpper() {
22
+ this.value = this.value.toUpperCase();
23
+ return this;
24
+ }
25
+ /**
26
+ * Convert the current value to lowercase using default locale rules.
27
+ * @returns The same chain instance for further chaining.
28
+ */
29
+ toLower() {
30
+ this.value = this.value.toLowerCase();
31
+ return this;
32
+ }
33
+ /**
34
+ * Replace a match in the current value using a string or RegExp search.
35
+ * @param search The string or RegExp pattern to search for.
36
+ * @param replacement The replacement string (supports RegExp replacement tokens).
37
+ * @returns The same chain instance for further chaining.
38
+ */
39
+ replace(search, replacement) {
40
+ this.value = this.value.replace(search, replacement);
41
+ return this;
42
+ }
43
+ /**
44
+ * Reverse the current value by Unicode code points.
45
+ * @returns The same chain instance for further chaining.
46
+ */
47
+ reverse() {
48
+ this.value = [...this.value].reverse().join("");
49
+ return this;
50
+ }
51
+ /**
52
+ * Get the current value as a string.
53
+ * @returns The current chained value.
54
+ */
55
+ valueOf() {
56
+ return this.value;
57
+ }
58
+ /**
59
+ * Convert the chain to a string for coercion or display.
60
+ * @returns The current chained value.
61
+ */
62
+ toString() {
63
+ return this.value;
64
+ }
65
+ }
66
+ /**
67
+ * Create a new `StringChain` instance for the provided input.
68
+ * @param input The string to wrap for chained operations.
69
+ * @returns A new `StringChain` instance.
70
+ */
71
+ export function chain(input) {
72
+ return new StringChain(input);
73
+ }
74
+ //# sourceMappingURL=chain.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.js","sourceRoot":"","sources":["../src/chain.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,WAAW;IAGtB;;;OAGG;IACH,YAAY,KAAa;QACvB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;QAC/B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACtC,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,MAAuB,EAAE,WAAmB;QAClD,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;QACrD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,IAAI,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAChD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;IAED;;;OAGG;IACH,QAAQ;QACN,OAAO,IAAI,CAAC,KAAK,CAAC;IACpB,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,KAAK,CAAC,KAAa;IACjC,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;AAChC,CAAC"}
package/dist/index.d.ts CHANGED
@@ -11,4 +11,7 @@ export * from './intl.js';
11
11
  export * from './perf.js';
12
12
  export * from './security.js';
13
13
  export * from './stream.js';
14
+ export * from './chain.js';
15
+ export * from './lazy.js';
16
+ export * from './plugin.js';
14
17
  //# 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;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,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;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/dist/index.js CHANGED
@@ -11,4 +11,7 @@ export * from './intl.js';
11
11
  export * from './perf.js';
12
12
  export * from './security.js';
13
13
  export * from './stream.js';
14
+ export * from './chain.js';
15
+ export * from './lazy.js';
16
+ export * from './plugin.js';
14
17
  //# 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;AAC9B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,aAAa,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;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
package/dist/lazy.d.ts ADDED
@@ -0,0 +1,42 @@
1
+ export declare class LazyString {
2
+ private input;
3
+ private operations;
4
+ /**
5
+ * Create a new lazy wrapper for the provided input.
6
+ * @param input The string to wrap for lazy operations.
7
+ */
8
+ constructor(input: string);
9
+ /**
10
+ * Register a transformation to run later during execution.
11
+ * @param fn A function that receives the current value and returns the next value.
12
+ * @returns The same lazy instance for further chaining.
13
+ */
14
+ map(fn: (input: string) => string): this;
15
+ /**
16
+ * Register a trim operation that removes surrounding whitespace.
17
+ * @returns The same lazy instance for further chaining.
18
+ */
19
+ trim(): this;
20
+ /**
21
+ * Register an uppercase conversion using default locale rules.
22
+ * @returns The same lazy instance for further chaining.
23
+ */
24
+ toUpper(): this;
25
+ /**
26
+ * Register a lowercase conversion using default locale rules.
27
+ * @returns The same lazy instance for further chaining.
28
+ */
29
+ toLower(): this;
30
+ /**
31
+ * Execute all registered operations in order and return the result.
32
+ * @returns The final transformed string.
33
+ */
34
+ execute(): string;
35
+ }
36
+ /**
37
+ * Create a new `LazyString` instance for the provided input.
38
+ * @param input The string to wrap for lazy operations.
39
+ * @returns A new `LazyString` instance.
40
+ */
41
+ export declare function lazy(input: string): LazyString;
42
+ //# sourceMappingURL=lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA,qBAAa,UAAU;IACrB,OAAO,CAAC,KAAK,CAAS;IACtB,OAAO,CAAC,UAAU,CAAiC;IAEnD;;;OAGG;gBACS,KAAK,EAAE,MAAM;IAIzB;;;;OAIG;IACH,GAAG,CAAC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI;IAKxC;;;OAGG;IACH,IAAI,IAAI,IAAI;IAIZ;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACH,OAAO,IAAI,IAAI;IAIf;;;OAGG;IACH,OAAO,IAAI,MAAM;CAMlB;AAED;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAE9C"}
package/dist/lazy.js ADDED
@@ -0,0 +1,56 @@
1
+ export class LazyString {
2
+ /**
3
+ * Create a new lazy wrapper for the provided input.
4
+ * @param input The string to wrap for lazy operations.
5
+ */
6
+ constructor(input) {
7
+ this.operations = [];
8
+ this.input = input;
9
+ }
10
+ /**
11
+ * Register a transformation to run later during execution.
12
+ * @param fn A function that receives the current value and returns the next value.
13
+ * @returns The same lazy instance for further chaining.
14
+ */
15
+ map(fn) {
16
+ this.operations.push(fn);
17
+ return this;
18
+ }
19
+ /**
20
+ * Register a trim operation that removes surrounding whitespace.
21
+ * @returns The same lazy instance for further chaining.
22
+ */
23
+ trim() {
24
+ return this.map(s => s.trim());
25
+ }
26
+ /**
27
+ * Register an uppercase conversion using default locale rules.
28
+ * @returns The same lazy instance for further chaining.
29
+ */
30
+ toUpper() {
31
+ return this.map(s => s.toUpperCase());
32
+ }
33
+ /**
34
+ * Register a lowercase conversion using default locale rules.
35
+ * @returns The same lazy instance for further chaining.
36
+ */
37
+ toLower() {
38
+ return this.map(s => s.toLowerCase());
39
+ }
40
+ /**
41
+ * Execute all registered operations in order and return the result.
42
+ * @returns The final transformed string.
43
+ */
44
+ execute() {
45
+ return this.operations.reduce((acc, fn) => fn(acc), this.input);
46
+ }
47
+ }
48
+ /**
49
+ * Create a new `LazyString` instance for the provided input.
50
+ * @param input The string to wrap for lazy operations.
51
+ * @returns A new `LazyString` instance.
52
+ */
53
+ export function lazy(input) {
54
+ return new LazyString(input);
55
+ }
56
+ //# sourceMappingURL=lazy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lazy.js","sourceRoot":"","sources":["../src/lazy.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAIrB;;;OAGG;IACH,YAAY,KAAa;QANjB,eAAU,GAA8B,EAAE,CAAC;QAOjD,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,EAA6B;QAC/B,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACzB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACjC,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC;IACxC,CAAC;IAED;;;OAGG;IACH,OAAO;QACL,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAC3B,CAAC,GAAG,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,EACpB,IAAI,CAAC,KAAK,CACX,CAAC;IACJ,CAAC;CACF;AAED;;;;GAIG;AACH,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,IAAI,UAAU,CAAC,KAAK,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Plugin contract for extending string utilities.
3
+ */
4
+ export type StringExtnPlugin = {
5
+ /** The unique plugin name used for registration and lookup. */
6
+ name: string;
7
+ /** The function invoked when the plugin runs. */
8
+ fn: (input: string, ...args: any[]) => string;
9
+ };
10
+ /**
11
+ * Register a plugin for later execution.
12
+ * @param plugin The plugin to register.
13
+ * @throws If a plugin with the same name is already registered.
14
+ */
15
+ export declare function registerPlugin(plugin: StringExtnPlugin): void;
16
+ /**
17
+ * Execute a registered plugin by name.
18
+ * @param name The plugin name to execute.
19
+ * @param input The input string passed to the plugin.
20
+ * @param args Additional arguments forwarded to the plugin function.
21
+ * @returns The plugin's result string.
22
+ * @throws If the plugin does not exist.
23
+ */
24
+ export declare function runPlugin(name: string, input: string, ...args: any[]): string;
25
+ /**
26
+ * List all registered plugin names in registration order.
27
+ * @returns An array of plugin names.
28
+ */
29
+ export declare function listPlugins(): string[];
30
+ //# sourceMappingURL=plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,+DAA+D;IAC/D,IAAI,EAAE,MAAM,CAAC;IACb,iDAAiD;IACjD,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,MAAM,CAAC;CAC/C,CAAC;AAIF;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,IAAI,CAM7D;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CACvB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,MAAM,EACb,GAAG,IAAI,EAAE,GAAG,EAAE,GACb,MAAM,CAQR;AAED;;;GAGG;AACH,wBAAgB,WAAW,IAAI,MAAM,EAAE,CAEtC"}
package/dist/plugin.js ADDED
@@ -0,0 +1,35 @@
1
+ const plugins = new Map();
2
+ /**
3
+ * Register a plugin for later execution.
4
+ * @param plugin The plugin to register.
5
+ * @throws If a plugin with the same name is already registered.
6
+ */
7
+ export function registerPlugin(plugin) {
8
+ if (plugins.has(plugin.name)) {
9
+ throw new Error(`Plugin '${plugin.name}' already exists`);
10
+ }
11
+ plugins.set(plugin.name, plugin);
12
+ }
13
+ /**
14
+ * Execute a registered plugin by name.
15
+ * @param name The plugin name to execute.
16
+ * @param input The input string passed to the plugin.
17
+ * @param args Additional arguments forwarded to the plugin function.
18
+ * @returns The plugin's result string.
19
+ * @throws If the plugin does not exist.
20
+ */
21
+ export function runPlugin(name, input, ...args) {
22
+ const plugin = plugins.get(name);
23
+ if (!plugin) {
24
+ throw new Error(`Plugin '${name}' not found`);
25
+ }
26
+ return plugin.fn(input, ...args);
27
+ }
28
+ /**
29
+ * List all registered plugin names in registration order.
30
+ * @returns An array of plugin names.
31
+ */
32
+ export function listPlugins() {
33
+ return Array.from(plugins.keys());
34
+ }
35
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAUA,MAAM,OAAO,GAAG,IAAI,GAAG,EAA4B,CAAC;AAEpD;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAwB;IACrD,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CAAC,WAAW,MAAM,CAAC,IAAI,kBAAkB,CAAC,CAAC;IAC5D,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,KAAa,EACb,GAAG,IAAW;IAEd,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAEjC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,WAAW,IAAI,aAAa,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,CAAC;AACnC,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,WAAW;IACzB,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Replace {{key}} placeholders in a template string with values from a map.
3
+ * @param input The template string containing {{key}} placeholders.
4
+ * @param variables A map of placeholder keys to values.
5
+ * @returns The rendered string with placeholders replaced.
6
+ * @remarks Keys are trimmed inside braces. Missing values (undefined) become an empty string.
7
+ */
8
+ export declare function template(input: string, variables: Record<string, any>): string;
9
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAC7B,MAAM,CAKR"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Replace {{key}} placeholders in a template string with values from a map.
3
+ * @param input The template string containing {{key}} placeholders.
4
+ * @param variables A map of placeholder keys to values.
5
+ * @returns The rendered string with placeholders replaced.
6
+ * @remarks Keys are trimmed inside braces. Missing values (undefined) become an empty string.
7
+ */
8
+ export function template(input, variables) {
9
+ return input.replace(/\{\{(.*?)\}\}/g, (_, key) => {
10
+ const value = variables[key.trim()];
11
+ return value !== undefined ? String(value) : "";
12
+ });
13
+ }
14
+ //# sourceMappingURL=template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.js","sourceRoot":"","sources":["../src/template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,QAAQ,CACtB,KAAa,EACb,SAA8B;IAE9B,OAAO,KAAK,CAAC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE;QAChD,MAAM,KAAK,GAAG,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;QACpC,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;IAClD,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "string-extn",
3
- "version": "1.1.0",
3
+ "version": "1.2.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",
@@ -53,20 +53,18 @@
53
53
  },
54
54
  "homepage": "https://github.com/balaji-kv/string-extn#readme",
55
55
  "dependencies": {
56
+ "glob": "^13.0.6",
56
57
  "grapheme-splitter": "^1.0.4",
57
58
  "typescript": "^5.9.3"
58
59
  },
59
60
  "devDependencies": {
60
- "@types/jest": "^29.5.14",
61
- "jest": "^29.7.0",
62
- "ts-jest": "^29.1.2",
63
- "ts-node": "^10.9.2",
64
- "glob": "^10.3.10"
61
+ "@types/jest": "^30.0.0",
62
+ "jest": "^30.2.0",
63
+ "ts-jest": "^29.4.6",
64
+ "ts-node": "^10.9.2"
65
65
  },
66
66
  "overrides": {
67
- "glob": "^10.3.10",
68
- "inflight": {
69
- "glob": "^10.3.10"
70
- }
67
+ "minimatch": "^10.2.2",
68
+ "glob": "^13.0.6"
71
69
  }
72
70
  }