@karmaniverous/jsonmap 0.0.2 → 0.0.3

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
@@ -41,14 +41,15 @@ The transformation output will reflect the structure of your `map` object and in
41
41
 
42
42
  ```js
43
43
  const map = {
44
- key1: 'static value passed directly to output',
44
+ foo: 'static value passed directly to output',
45
45
  // Structure passed directly to output.
46
- key2: [
46
+ bar: [
47
47
  {
48
- key2a: 'another static value',
49
- // Value defined by mapping rule with an array of transformation objects.
50
- // If there is only a single transformation object, no array is necessary.
51
- key2b: {
48
+ static: 'another static value',
49
+ // Value defined by a mapping rule expressing an array of transformation
50
+ // objects. If there is only a single transformation object, no array is
51
+ // necessary.
52
+ dynamic: {
52
53
  $: [
53
54
  // Each transformation object uses a special syntax to reference an
54
55
  // object, a method to run on it, and an array of parameters to pass.
@@ -76,6 +77,15 @@ const map = {
76
77
  },
77
78
  },
78
79
  ],
80
+ // Value defined by a single mapping rule executing a method against a
81
+ // previous output of the same mapping object.
82
+ progressive: {
83
+ $: {
84
+ object: '$.lib._',
85
+ method: 'toUpper',
86
+ params: '$.output.bar[0].static',
87
+ },
88
+ },
79
89
  };
80
90
  ```
81
91
 
@@ -98,6 +108,8 @@ const jsonMap = new JsonMap(lib, map);
98
108
  // Assumes some input data object is already defined.
99
109
  const output = await jsonMap.transform(input);
100
110
  ```
111
+
112
+ The [unit tests](https://github.com/karmaniverous/jsonmap/blob/main/lib/JsonMap/JsonMap.test.js) demonstrate this example in action.
101
113
 
102
114
  # API Documentation
103
115
 
@@ -151,7 +151,7 @@ function _resolvePath2(path, results) {
151
151
  const p = path.slice(pattern.length + 1);
152
152
 
153
153
  // Retrieves the value from the replacement object based on the remaining path
154
- const value = p.length ? (0, _get2.default)(replacement, p.split('.')) : replacement;
154
+ const value = p.length ? (0, _get2.default)(replacement, p) : replacement;
155
155
 
156
156
  // Returns the value if it exists, otherwise returns the original path
157
157
  return (0, _isNil2.default)(value) ? path : value;
@@ -147,7 +147,7 @@ class JsonMap {
147
147
  const p = path.slice(pattern.length + 1);
148
148
 
149
149
  // Retrieves the value from the replacement object based on the remaining path
150
- const value = p.length ? _.get(replacement, p.split('.')) : replacement;
150
+ const value = p.length ? _.get(replacement, p) : replacement;
151
151
 
152
152
  // Returns the value if it exists, otherwise returns the original path
153
153
  return _.isNil(value) ? path : value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jsonmap",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },