@karmaniverous/jsonmap 0.2.1 → 0.2.2
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 +36 -36
- package/dist/default/lib/JsonMap/JsonMap.js +2 -2
- package/lib/JsonMap/JsonMap.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -111,44 +111,44 @@ const output = await jsonMap.transform(input);
|
|
|
111
111
|
```
|
|
112
112
|
|
|
113
113
|
The [unit tests](https://github.com/karmaniverous/jsonmap/blob/main/lib/JsonMap/JsonMap.test.js) demonstrate this example in action.
|
|
114
|
-
|
|
114
|
+
|
|
115
115
|
# API Documentation
|
|
116
116
|
|
|
117
|
-
<a name="JsonMap"></a>
|
|
118
|
-
|
|
119
|
-
## JsonMap
|
|
120
|
-
JsonMap class to apply transformations to a JSON object
|
|
121
|
-
|
|
122
|
-
**Kind**: global class
|
|
123
|
-
|
|
124
|
-
* [JsonMap](#JsonMap)
|
|
125
|
-
* [new JsonMap([map], [lib])](#new_JsonMap_new)
|
|
126
|
-
* [.transform(input)](#JsonMap+transform) ⇒ <code>object</code>
|
|
127
|
-
|
|
128
|
-
<a name="new_JsonMap_new"></a>
|
|
129
|
-
|
|
130
|
-
### new JsonMap([map], [lib])
|
|
131
|
-
Creates an instance of JsonMap.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
| Param | Type | Description |
|
|
135
|
-
| --- | --- | --- |
|
|
136
|
-
| [map] | <code>object</code> | The data mapping configuration. |
|
|
137
|
-
| [lib] | <code>object</code> | A collection of function libraries. |
|
|
138
|
-
|
|
139
|
-
<a name="JsonMap+transform"></a>
|
|
140
|
-
|
|
141
|
-
### jsonMap.transform(input) ⇒ <code>object</code>
|
|
142
|
-
Transforms the input data according to the map configuration.
|
|
143
|
-
|
|
144
|
-
**Kind**: instance method of [<code>JsonMap</code>](#JsonMap)
|
|
145
|
-
**Returns**: <code>object</code> - - The transformed data.
|
|
146
|
-
|
|
147
|
-
| Param | Type | Description |
|
|
148
|
-
| --- | --- | --- |
|
|
149
|
-
| input | <code>object</code> | The input data to be transformed. |
|
|
150
|
-
|
|
151
|
-
|
|
117
|
+
<a name="JsonMap"></a>
|
|
118
|
+
|
|
119
|
+
## JsonMap
|
|
120
|
+
JsonMap class to apply transformations to a JSON object
|
|
121
|
+
|
|
122
|
+
**Kind**: global class
|
|
123
|
+
|
|
124
|
+
* [JsonMap](#JsonMap)
|
|
125
|
+
* [new JsonMap([map], [lib])](#new_JsonMap_new)
|
|
126
|
+
* [.transform(input)](#JsonMap+transform) ⇒ <code>object</code>
|
|
127
|
+
|
|
128
|
+
<a name="new_JsonMap_new"></a>
|
|
129
|
+
|
|
130
|
+
### new JsonMap([map], [lib])
|
|
131
|
+
Creates an instance of JsonMap.
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
| Param | Type | Description |
|
|
135
|
+
| --- | --- | --- |
|
|
136
|
+
| [map] | <code>object</code> | The data mapping configuration. |
|
|
137
|
+
| [lib] | <code>object</code> | A collection of function libraries. |
|
|
138
|
+
|
|
139
|
+
<a name="JsonMap+transform"></a>
|
|
140
|
+
|
|
141
|
+
### jsonMap.transform(input) ⇒ <code>object</code>
|
|
142
|
+
Transforms the input data according to the map configuration.
|
|
143
|
+
|
|
144
|
+
**Kind**: instance method of [<code>JsonMap</code>](#JsonMap)
|
|
145
|
+
**Returns**: <code>object</code> - - The transformed data.
|
|
146
|
+
|
|
147
|
+
| Param | Type | Description |
|
|
148
|
+
| --- | --- | --- |
|
|
149
|
+
| input | <code>object</code> | The input data to be transformed. |
|
|
150
|
+
|
|
151
|
+
|
|
152
152
|
---
|
|
153
153
|
|
|
154
154
|
See more great templates and other tools on
|
|
@@ -50,8 +50,8 @@ class JsonMap {
|
|
|
50
50
|
// Calls the #transform method to perform the transformation
|
|
51
51
|
const result = await this.#transform(this.map, this.input, this.output);
|
|
52
52
|
|
|
53
|
-
// Recursively eliminate string keys starting with $.
|
|
54
|
-
const deep = value => (0, _lodash7.default)(value) ? (0, _lodash9.default)((0, _lodash10.default)(value, (v, k) =>
|
|
53
|
+
// Recursively eliminate non-string keys & string keys starting with $.
|
|
54
|
+
const deep = value => (0, _lodash7.default)(value) ? (0, _lodash9.default)((0, _lodash10.default)(value, (v, k) => (0, _lodash8.default)(k) && /^[^$]/.test(k)), value => (0, _lodash2.default)(value, deep)) : undefined;
|
|
55
55
|
return (0, _lodash2.default)(result, deep);
|
|
56
56
|
}
|
|
57
57
|
|
package/lib/JsonMap/JsonMap.js
CHANGED
|
@@ -41,11 +41,11 @@ class JsonMap {
|
|
|
41
41
|
// Calls the #transform method to perform the transformation
|
|
42
42
|
const result = await this.#transform(this.map, this.input, this.output);
|
|
43
43
|
|
|
44
|
-
// Recursively eliminate string keys starting with $.
|
|
44
|
+
// Recursively eliminate non-string keys & string keys starting with $.
|
|
45
45
|
const deep = (value) =>
|
|
46
46
|
isPlainObject(value)
|
|
47
47
|
? mapValues(
|
|
48
|
-
pickBy(value, (v, k) =>
|
|
48
|
+
pickBy(value, (v, k) => isString(k) && /^[^$]/.test(k)),
|
|
49
49
|
(value) => cloneDeepWith(value, deep)
|
|
50
50
|
)
|
|
51
51
|
: undefined;
|