@karmaniverous/jsonmap 0.2.8 → 0.3.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
@@ -122,19 +122,20 @@ JsonMap class to apply transformations to a JSON object
122
122
  **Kind**: global class
123
123
 
124
124
  * [JsonMap](#JsonMap)
125
- * [new JsonMap([map], [lib])](#new_JsonMap_new)
125
+ * [new JsonMap([map], [lib], [ignore])](#new_JsonMap_new)
126
126
  * [.transform(input)](#JsonMap+transform) ⇒ <code>object</code>
127
127
 
128
128
  <a name="new_JsonMap_new"></a>
129
129
 
130
- ### new JsonMap([map], [lib])
130
+ ### new JsonMap([map], [lib], [ignore])
131
131
  Creates an instance of JsonMap.
132
132
 
133
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. |
134
+ | Param | Type | Default | Description |
135
+ | --- | --- | --- | --- |
136
+ | [map] | <code>object</code> | | The data mapping configuration. |
137
+ | [lib] | <code>object</code> | | A collection of function libraries. |
138
+ | [ignore] | <code>string</code> | <code>&quot;^\\$&quot;</code> | Regex pattern of keys to ignore. Defaults to '^\\$'. |
138
139
 
139
140
  <a name="JsonMap+transform"></a>
140
141
 
@@ -54,12 +54,15 @@ class JsonMap {
54
54
  *
55
55
  * @param {object} [map] - The data mapping configuration.
56
56
  * @param {object} [lib] - A collection of function libraries.
57
+ * @param {string} [ignore] - Regex pattern of keys to ignore. Defaults to '^\\$'.
57
58
  */
58
59
  constructor() {
59
60
  let map = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
60
61
  let lib = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
62
+ let ignore = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '^\\$';
61
63
  this.map = map;
62
64
  this.lib = lib;
65
+ this.ignore = new RegExp(ignore);
63
66
  }
64
67
 
65
68
  /**
@@ -80,8 +83,8 @@ class JsonMap {
80
83
  } = getJsonFns();
81
84
  const result = JSON.parse(JSON.stringify(await this.#transform(this.map, this.input, this.output), replacer), reviver);
82
85
 
83
- // Recursively eliminate non-string keys & string keys starting with $.
84
- const deep = value => (0, _lodash7.default)(value) ? (0, _lodash10.default)((0, _lodash11.default)(value, (v, k) => /^[^$]/.test(k)), value => (0, _lodash2.default)(value, deep)) : undefined;
86
+ // Recursively eliminate non-string keys & string keys starting with $ and not in ignoreExclusions.
87
+ const deep = value => (0, _lodash7.default)(value) ? (0, _lodash10.default)((0, _lodash11.default)(value, (v, k) => !this.ignore.test(k)), value => (0, _lodash2.default)(value, deep)) : undefined;
85
88
  return (0, _lodash2.default)(result, deep);
86
89
  }
87
90
 
@@ -50,10 +50,12 @@ class JsonMap {
50
50
  *
51
51
  * @param {object} [map] - The data mapping configuration.
52
52
  * @param {object} [lib] - A collection of function libraries.
53
+ * @param {string} [ignore] - Regex pattern of keys to ignore. Defaults to '^\\$'.
53
54
  */
54
- constructor(map = {}, lib = {}) {
55
+ constructor(map = {}, lib = {}, ignore = '^\\$') {
55
56
  this.map = map;
56
57
  this.lib = lib;
58
+ this.ignore = new RegExp(ignore);
57
59
  }
58
60
 
59
61
  /**
@@ -77,11 +79,11 @@ class JsonMap {
77
79
  reviver
78
80
  );
79
81
 
80
- // Recursively eliminate non-string keys & string keys starting with $.
82
+ // Recursively eliminate non-string keys & string keys starting with $ and not in ignoreExclusions.
81
83
  const deep = (value) =>
82
84
  isPlainObject(value)
83
85
  ? mapValues(
84
- pickBy(value, (v, k) => /^[^$]/.test(k)),
86
+ pickBy(value, (v, k) => !this.ignore.test(k)),
85
87
  (value) => cloneDeepWith(value, deep)
86
88
  )
87
89
  : undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jsonmap",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },