@edirect/template 11.0.40 → 11.0.41

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
@@ -1,69 +1,87 @@
1
1
  # @edirect/template
2
2
 
3
- TemplateModule is a library that provides methods to transform a payload based on a given template. The transformation includes mapping fields, applying transformers, setting default values and so on.
3
+ `@edirect/template` is a flexible library for transforming payloads based on declarative templates. It supports mapping fields, applying custom transformers, setting default values, handling nested objects, and working with arrays.
4
4
 
5
- ### Installation
5
+ ## Features
6
6
 
7
- ```shell
8
- $ npm i --save @edirect/template
7
+ - Declarative template-based payload transformation
8
+ - Custom transformer functions for mapping, validation, formatting, and business rules
9
+ - Support for nested objects and arrays
10
+ - Default values and context-aware mapping
11
+ - Sequential transformers and transformer parameters
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ pnpm add @edirect/template
19
+ # or
20
+ npm install @edirect/template
9
21
  ```
10
22
 
11
- ### Import
23
+ ## Usage
12
24
 
13
- ```javascript
14
- import { TemplateModule } from './TemplateModule';
25
+ Import the module:
26
+
27
+ ```js
28
+ import { TemplateModule } from '@edirect/template';
15
29
  ```
16
30
 
17
- ### Methods
31
+ ## API
18
32
 
19
- #### `Constructor`
33
+ ### Constructor
20
34
 
21
- The TemplateModule class does not have a constructor.
35
+ The `TemplateModule` class can be instantiated directly:
22
36
 
23
- #### `setContext(context): void`
37
+ ```js
38
+ const templateModule = new TemplateModule();
39
+ ```
24
40
 
25
- Sets the context object to be used during the transformation.
41
+ ### setContext(context: object): void
26
42
 
27
- #### `setTemplate(template): void`
43
+ Sets the context object to be used during transformation.
44
+
45
+ ### setTemplate(template: object): void
28
46
 
29
47
  Sets the template object that describes the transformation to be performed.
30
48
 
31
- #### `setTransformers(transformers: ITransformer): void`
49
+ ### setTransformers(transformers: ITransformer): void
32
50
 
33
51
  Sets the transformers to be used during the transformation.
34
52
 
35
- #### `setOptions(transformers: ITemplateOptions): void`
53
+ ### setOptions(options: ITemplateOptions): void
36
54
 
37
- Sets the options to be used during and after the transformation.
55
+ Sets options to be used during and after the transformation.
38
56
 
39
- #### `verifyTransformer(transformer: ITransformer, methodName: string): boolean`
57
+ ### verifyTransformer(transformer: ITransformer, methodName: string): boolean
40
58
 
41
59
  Verifies if a given transformer method exists.
42
60
 
43
- #### `runTransformer(transformer: string, value?: unknown): unknown | null`
61
+ ### runTransformer(transformer: string, value?: unknown): unknown | null
44
62
 
45
63
  Runs a transformer on a given value.
46
64
 
47
- - transformer - The name of the transformer to be used.
48
- - value - The value to be transformed.
65
+ - `transformer`: The name of the transformer to use
66
+ - `value`: The value to be transformed
49
67
 
50
- #### `checkValue(value: any): boolean`
68
+ ### checkValue(value: any): boolean
51
69
 
52
70
  Checks if a given value is not null, undefined, or an empty string.
53
71
 
54
- #### `setValueByCondition(object, key: string, value: unknown)`
72
+ ### setValueByCondition(object, key: string, value: unknown)
55
73
 
56
- Sets a value in an object after verify using the checkValue() method.
74
+ Sets a value in an object after verifying with `checkValue()`.
57
75
 
58
- - object - The object to be modified.
59
- - key - The key of the value to be set.
60
- - value - The value to be set.
76
+ - `object`: The object to modify
77
+ - `key`: The key to set
78
+ - `value`: The value to set
61
79
 
62
- #### `transformPayload<T, U>(obj: T, template = this.template): U`
80
+ ### transformPayload<T, U>(obj: T, template = this.template): U
63
81
 
64
- Transforms a payload object on a given template.
82
+ Transforms a payload object using the provided template.
65
83
 
66
- ### Simple example
84
+ ## Simple Example
67
85
 
68
86
  ```javascript
69
87
  import { TemplateModule } from '@edirect/template';
@@ -93,7 +111,7 @@ console.log(result);
93
111
  // }
94
112
  ```
95
113
 
96
- ### Example with transformers
114
+ ## Example with Transformers
97
115
 
98
116
  #### First of all, what's a transformer?
99
117
 
@@ -196,7 +214,7 @@ console.log(result);
196
214
  // }
197
215
  ```
198
216
 
199
- ### Example with nested object + transformers
217
+ ## Example with Nested Object + Transformers
200
218
 
201
219
  `Note`: the transformer notation uses three keys to identify an object as being a transformer: fields, transformer, and defaultValue, if there are at least 1 of these keys, the engine will consider the object as being a transformer, on the other hand, if there isn't, the engine will consider as a nested object to mapper all information.
202
220
 
@@ -300,7 +318,7 @@ console.log(result);
300
318
  // }
301
319
  ```
302
320
 
303
- ### Example with arrays + transformers
321
+ ## Example with Arrays + Transformers
304
322
 
305
323
  `Note`: When it comes to arrays mapper, we need to have in mind that is required use this two keys: arraySource and arrayTemplate.
306
324
 
@@ -423,7 +441,7 @@ console.log(result);
423
441
  // }
424
442
  ```
425
443
 
426
- ### Example with arrays + ignoreIndexs
444
+ ## Example with Arrays + ignoreIndexs
427
445
 
428
446
  `Note`: When it comes to arrays mapper, we need to have in mind that is required use this two keys: arraySource and arrayTemplate.
429
447
 
@@ -542,7 +560,7 @@ console.log(result);
542
560
  // }
543
561
  ```
544
562
 
545
- ### Template example with transformer + transformerParams
563
+ ## Example: Transformer + transformerParams
546
564
 
547
565
  ##### File name: baseTransformers.ts
548
566
 
@@ -630,7 +648,7 @@ console.log(result);
630
648
  // }
631
649
  ```
632
650
 
633
- ### Template example with transformer + transformerParams + complexParams
651
+ ## Example: Transformer + transformerParams + complexParams
634
652
 
635
653
  ##### File name: baseTransformers.ts
636
654
 
@@ -687,7 +705,7 @@ console.log(result);
687
705
  // }
688
706
  ```
689
707
 
690
- ### Example with Sequential Transformers
708
+ ## Example: Sequential Transformers
691
709
 
692
710
  The library now supports applying multiple transformers sequentially to a single field. This is particularly useful for more complex transformations that require multiple steps.
693
711
 
@@ -1033,7 +1051,23 @@ console.log(result);
1033
1051
  // }
1034
1052
  ```
1035
1053
 
1036
- ### Example using simple arrays
1054
+ ## Example: Simple Arrays
1055
+
1056
+ ## Configuration & Environment Variables
1057
+
1058
+ `@edirect/template` is a pure JavaScript/TypeScript library and does not require any environment variables by default. However, if your custom transformers or templates depend on environment-specific values, you can inject them via your application context or configuration system.
1059
+
1060
+ For example, you can pass environment variables into the context:
1061
+
1062
+ ```js
1063
+ const context = {
1064
+ ...process.env,
1065
+ // other context values
1066
+ };
1067
+ templateModule.setContext(context);
1068
+ ```
1069
+
1070
+ **Note:** Never commit sensitive credentials to version control. Use environment variables or secure secrets management as appropriate for your application.
1037
1071
 
1038
1072
  ```js
1039
1073
  import { TemplateModule } from '@edirect/template';
package/dist/README.md CHANGED
@@ -1,69 +1,87 @@
1
1
  # @edirect/template
2
2
 
3
- TemplateModule is a library that provides methods to transform a payload based on a given template. The transformation includes mapping fields, applying transformers, setting default values and so on.
3
+ `@edirect/template` is a flexible library for transforming payloads based on declarative templates. It supports mapping fields, applying custom transformers, setting default values, handling nested objects, and working with arrays.
4
4
 
5
- ### Installation
5
+ ## Features
6
6
 
7
- ```shell
8
- $ npm i --save @edirect/template
7
+ - Declarative template-based payload transformation
8
+ - Custom transformer functions for mapping, validation, formatting, and business rules
9
+ - Support for nested objects and arrays
10
+ - Default values and context-aware mapping
11
+ - Sequential transformers and transformer parameters
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ```sh
18
+ pnpm add @edirect/template
19
+ # or
20
+ npm install @edirect/template
9
21
  ```
10
22
 
11
- ### Import
23
+ ## Usage
12
24
 
13
- ```javascript
14
- import { TemplateModule } from './TemplateModule';
25
+ Import the module:
26
+
27
+ ```js
28
+ import { TemplateModule } from '@edirect/template';
15
29
  ```
16
30
 
17
- ### Methods
31
+ ## API
18
32
 
19
- #### `Constructor`
33
+ ### Constructor
20
34
 
21
- The TemplateModule class does not have a constructor.
35
+ The `TemplateModule` class can be instantiated directly:
22
36
 
23
- #### `setContext(context): void`
37
+ ```js
38
+ const templateModule = new TemplateModule();
39
+ ```
24
40
 
25
- Sets the context object to be used during the transformation.
41
+ ### setContext(context: object): void
26
42
 
27
- #### `setTemplate(template): void`
43
+ Sets the context object to be used during transformation.
44
+
45
+ ### setTemplate(template: object): void
28
46
 
29
47
  Sets the template object that describes the transformation to be performed.
30
48
 
31
- #### `setTransformers(transformers: ITransformer): void`
49
+ ### setTransformers(transformers: ITransformer): void
32
50
 
33
51
  Sets the transformers to be used during the transformation.
34
52
 
35
- #### `setOptions(transformers: ITemplateOptions): void`
53
+ ### setOptions(options: ITemplateOptions): void
36
54
 
37
- Sets the options to be used during and after the transformation.
55
+ Sets options to be used during and after the transformation.
38
56
 
39
- #### `verifyTransformer(transformer: ITransformer, methodName: string): boolean`
57
+ ### verifyTransformer(transformer: ITransformer, methodName: string): boolean
40
58
 
41
59
  Verifies if a given transformer method exists.
42
60
 
43
- #### `runTransformer(transformer: string, value?: unknown): unknown | null`
61
+ ### runTransformer(transformer: string, value?: unknown): unknown | null
44
62
 
45
63
  Runs a transformer on a given value.
46
64
 
47
- - transformer - The name of the transformer to be used.
48
- - value - The value to be transformed.
65
+ - `transformer`: The name of the transformer to use
66
+ - `value`: The value to be transformed
49
67
 
50
- #### `checkValue(value: any): boolean`
68
+ ### checkValue(value: any): boolean
51
69
 
52
70
  Checks if a given value is not null, undefined, or an empty string.
53
71
 
54
- #### `setValueByCondition(object, key: string, value: unknown)`
72
+ ### setValueByCondition(object, key: string, value: unknown)
55
73
 
56
- Sets a value in an object after verify using the checkValue() method.
74
+ Sets a value in an object after verifying with `checkValue()`.
57
75
 
58
- - object - The object to be modified.
59
- - key - The key of the value to be set.
60
- - value - The value to be set.
76
+ - `object`: The object to modify
77
+ - `key`: The key to set
78
+ - `value`: The value to set
61
79
 
62
- #### `transformPayload<T, U>(obj: T, template = this.template): U`
80
+ ### transformPayload<T, U>(obj: T, template = this.template): U
63
81
 
64
- Transforms a payload object on a given template.
82
+ Transforms a payload object using the provided template.
65
83
 
66
- ### Simple example
84
+ ## Simple Example
67
85
 
68
86
  ```javascript
69
87
  import { TemplateModule } from '@edirect/template';
@@ -93,7 +111,7 @@ console.log(result);
93
111
  // }
94
112
  ```
95
113
 
96
- ### Example with transformers
114
+ ## Example with Transformers
97
115
 
98
116
  #### First of all, what's a transformer?
99
117
 
@@ -196,7 +214,7 @@ console.log(result);
196
214
  // }
197
215
  ```
198
216
 
199
- ### Example with nested object + transformers
217
+ ## Example with Nested Object + Transformers
200
218
 
201
219
  `Note`: the transformer notation uses three keys to identify an object as being a transformer: fields, transformer, and defaultValue, if there are at least 1 of these keys, the engine will consider the object as being a transformer, on the other hand, if there isn't, the engine will consider as a nested object to mapper all information.
202
220
 
@@ -300,7 +318,7 @@ console.log(result);
300
318
  // }
301
319
  ```
302
320
 
303
- ### Example with arrays + transformers
321
+ ## Example with Arrays + Transformers
304
322
 
305
323
  `Note`: When it comes to arrays mapper, we need to have in mind that is required use this two keys: arraySource and arrayTemplate.
306
324
 
@@ -423,7 +441,7 @@ console.log(result);
423
441
  // }
424
442
  ```
425
443
 
426
- ### Example with arrays + ignoreIndexs
444
+ ## Example with Arrays + ignoreIndexs
427
445
 
428
446
  `Note`: When it comes to arrays mapper, we need to have in mind that is required use this two keys: arraySource and arrayTemplate.
429
447
 
@@ -542,7 +560,7 @@ console.log(result);
542
560
  // }
543
561
  ```
544
562
 
545
- ### Template example with transformer + transformerParams
563
+ ## Example: Transformer + transformerParams
546
564
 
547
565
  ##### File name: baseTransformers.ts
548
566
 
@@ -630,7 +648,7 @@ console.log(result);
630
648
  // }
631
649
  ```
632
650
 
633
- ### Template example with transformer + transformerParams + complexParams
651
+ ## Example: Transformer + transformerParams + complexParams
634
652
 
635
653
  ##### File name: baseTransformers.ts
636
654
 
@@ -687,7 +705,7 @@ console.log(result);
687
705
  // }
688
706
  ```
689
707
 
690
- ### Example with Sequential Transformers
708
+ ## Example: Sequential Transformers
691
709
 
692
710
  The library now supports applying multiple transformers sequentially to a single field. This is particularly useful for more complex transformations that require multiple steps.
693
711
 
@@ -1033,7 +1051,23 @@ console.log(result);
1033
1051
  // }
1034
1052
  ```
1035
1053
 
1036
- ### Example using simple arrays
1054
+ ## Example: Simple Arrays
1055
+
1056
+ ## Configuration & Environment Variables
1057
+
1058
+ `@edirect/template` is a pure JavaScript/TypeScript library and does not require any environment variables by default. However, if your custom transformers or templates depend on environment-specific values, you can inject them via your application context or configuration system.
1059
+
1060
+ For example, you can pass environment variables into the context:
1061
+
1062
+ ```js
1063
+ const context = {
1064
+ ...process.env,
1065
+ // other context values
1066
+ };
1067
+ templateModule.setContext(context);
1068
+ ```
1069
+
1070
+ **Note:** Never commit sensitive credentials to version control. Use environment variables or secure secrets management as appropriate for your application.
1037
1071
 
1038
1072
  ```js
1039
1073
  import { TemplateModule } from '@edirect/template';
package/dist/package.json CHANGED
@@ -16,12 +16,12 @@
16
16
  "dist"
17
17
  ],
18
18
  "dependencies": {
19
- "lodash": "^4.17.21",
19
+ "lodash": "^4.17.23",
20
20
  "tslib": "^2.8.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "@types/lodash": "^4.17.23",
24
- "@types/node": "^25.0.9"
24
+ "@types/node": "^25.0.10"
25
25
  },
26
26
  "type": "commonjs"
27
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edirect/template",
3
- "version": "11.0.40",
3
+ "version": "11.0.41",
4
4
  "packageScope": "@edirect",
5
5
  "main": "./dist/src/index.js",
6
6
  "types": "./dist/src/index.d.ts",
@@ -17,12 +17,12 @@
17
17
  "dist"
18
18
  ],
19
19
  "dependencies": {
20
- "lodash": "^4.17.21",
20
+ "lodash": "^4.17.23",
21
21
  "tslib": "^2.8.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/lodash": "^4.17.23",
25
- "@types/node": "^25.0.9"
25
+ "@types/node": "^25.0.10"
26
26
  },
27
27
  "nx": {
28
28
  "name": "@edirect/template",