@karmaniverous/jsonmap 0.0.3 → 0.0.5

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.
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.JsonMap = void 0;
7
- var _isNil2 = _interopRequireDefault(require("lodash/isNil"));
8
- var _parseInt2 = _interopRequireDefault(require("lodash/parseInt"));
9
- var _get2 = _interopRequireDefault(require("lodash/get"));
10
- var _isString2 = _interopRequireDefault(require("lodash/isString"));
11
- var _set2 = _interopRequireDefault(require("lodash/set"));
12
- var _last2 = _interopRequireDefault(require("lodash/last"));
13
- var _castArray2 = _interopRequireDefault(require("lodash/castArray"));
14
- var _isArray2 = _interopRequireDefault(require("lodash/isArray"));
15
- var _isObject2 = _interopRequireDefault(require("lodash/isObject"));
7
+ var _lodash = _interopRequireDefault(require("lodash.castarray"));
8
+ var _lodash2 = _interopRequireDefault(require("lodash.get"));
9
+ var _lodash3 = _interopRequireDefault(require("lodash.isnil"));
10
+ var _lodash4 = _interopRequireDefault(require("lodash.isarray"));
11
+ var _lodash5 = _interopRequireDefault(require("lodash.isobject"));
12
+ var _lodash6 = _interopRequireDefault(require("lodash.isstring"));
13
+ var _lodash7 = _interopRequireDefault(require("lodash.last"));
14
+ var _lodash8 = _interopRequireDefault(require("lodash.parseint"));
15
+ var _lodash9 = _interopRequireDefault(require("lodash.set"));
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
  function _classPrivateMethodInitSpec(obj, privateSet) { _checkPrivateRedeclaration(obj, privateSet); privateSet.add(obj); }
18
18
  function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
@@ -68,9 +68,9 @@ exports.JsonMap = JsonMap;
68
68
  async function _transform2(node, input, output) {
69
69
  let path = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
70
70
  // Checks if the current node is an object and has a '$' key
71
- if ((0, _isObject2.default)(node) && '$' in node) {
71
+ if ((0, _lodash5.default)(node) && '$' in node) {
72
72
  // Retrieves the transformations to be applied (can be an array or a single object)
73
- const transformations = (0, _isArray2.default)(node['$']) ? node['$'] : [node['$']];
73
+ const transformations = (0, _lodash4.default)(node['$']) ? node['$'] : [node['$']];
74
74
 
75
75
  // Array to store the results of the transformations
76
76
  let results = [];
@@ -81,7 +81,7 @@ async function _transform2(node, input, output) {
81
81
  const object = _classPrivateMethodGet(this, _resolvePath, _resolvePath2).call(this, transformation.object, results);
82
82
 
83
83
  // Resolves the parameter paths for the transformation
84
- const params = await Promise.all((0, _castArray2.default)(transformation.params).map(param => _classPrivateMethodGet(this, _resolvePath, _resolvePath2).call(this, param, results)));
84
+ const params = await Promise.all((0, _lodash.default)(transformation.params).map(param => _classPrivateMethodGet(this, _resolvePath, _resolvePath2).call(this, param, results)));
85
85
 
86
86
  // Calls the specified method on the resolved object with the resolved parameters
87
87
  const result = await object[transformation.method](...params);
@@ -91,15 +91,15 @@ async function _transform2(node, input, output) {
91
91
  }
92
92
 
93
93
  // Sets the output at the specified path to the last result of the transformations & returns.
94
- const last = (0, _last2.default)(results);
95
- (0, _set2.default)(output, path, last);
96
- return last;
94
+ const lastResult = (0, _lodash7.default)(results);
95
+ (0, _lodash9.default)(output, path, lastResult);
96
+ return lastResult;
97
97
  }
98
98
 
99
99
  // Checks if the current node is an object
100
- if ((0, _isObject2.default)(node)) {
100
+ if ((0, _lodash5.default)(node)) {
101
101
  // Creates an empty array or object based on whether the current node is an array or not
102
- const transformedNode = (0, _isArray2.default)(node) ? [] : {};
102
+ const transformedNode = (0, _lodash4.default)(node) ? [] : {};
103
103
 
104
104
  // Iterates over each key-value pair in the current node
105
105
  for (const [key, value] of Object.entries(node)) {
@@ -112,17 +112,17 @@ async function _transform2(node, input, output) {
112
112
  }
113
113
 
114
114
  // Sets the output at the specified path to the transformedNode & returnsd.
115
- (0, _set2.default)(output, path, transformedNode);
115
+ (0, _lodash9.default)(output, path, transformedNode);
116
116
  return transformedNode;
117
117
  }
118
118
 
119
119
  // Sets the output at the specified path to the current node & returns.
120
- (0, _set2.default)(output, path, node);
120
+ (0, _lodash9.default)(output, path, node);
121
121
  return node;
122
122
  }
123
123
  function _resolvePath2(path, results) {
124
124
  // If the path is not a string, return it as is
125
- if (!(0, _isString2.default)(path)) {
125
+ if (!(0, _lodash6.default)(path)) {
126
126
  return path;
127
127
  }
128
128
 
@@ -139,7 +139,7 @@ function _resolvePath2(path, results) {
139
139
  // Retrieves the value from the previous results based on the index and any remaining path
140
140
  if (match) {
141
141
  const [, index, rest] = match;
142
- const value = (0, _get2.default)(results, [results.length - 1 - (0, _parseInt2.default)(index), ...(rest.length ? rest.split('.') : [])]);
142
+ const value = (0, _lodash2.default)(results, [results.length - 1 - (0, _lodash8.default)(index), ...(rest.length ? rest.split('.') : [])]);
143
143
 
144
144
  // Returns the value if it exists, otherwise returns the original path
145
145
  return value != null ? value : path;
@@ -151,10 +151,10 @@ 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) : replacement;
154
+ const value = p.length ? (0, _lodash2.default)(replacement, p) : replacement;
155
155
 
156
156
  // Returns the value if it exists, otherwise returns the original path
157
- return (0, _isNil2.default)(value) ? path : value;
157
+ return (0, _lodash3.default)(value) ? path : value;
158
158
  }
159
159
 
160
160
  // Returns the path as is if it does not match any special patterns
@@ -1,4 +1,13 @@
1
- import _ from 'lodash';
1
+ // npm imports
2
+ import castArray from 'lodash.castarray';
3
+ import get from 'lodash.get';
4
+ import isNil from 'lodash.isnil';
5
+ import isArray from 'lodash.isarray';
6
+ import isObject from 'lodash.isobject';
7
+ import isString from 'lodash.isstring';
8
+ import last from 'lodash.last';
9
+ import parseInt from 'lodash.parseint';
10
+ import set from 'lodash.set';
2
11
 
3
12
  /**
4
13
  * JsonMap class to apply transformations to a JSON object
@@ -42,9 +51,9 @@ class JsonMap {
42
51
  */
43
52
  async #transform(node, input, output, path = '') {
44
53
  // Checks if the current node is an object and has a '$' key
45
- if (_.isObject(node) && '$' in node) {
54
+ if (isObject(node) && '$' in node) {
46
55
  // Retrieves the transformations to be applied (can be an array or a single object)
47
- const transformations = _.isArray(node['$']) ? node['$'] : [node['$']];
56
+ const transformations = isArray(node['$']) ? node['$'] : [node['$']];
48
57
 
49
58
  // Array to store the results of the transformations
50
59
  let results = [];
@@ -56,7 +65,7 @@ class JsonMap {
56
65
 
57
66
  // Resolves the parameter paths for the transformation
58
67
  const params = await Promise.all(
59
- _.castArray(transformation.params).map((param) =>
68
+ castArray(transformation.params).map((param) =>
60
69
  this.#resolvePath(param, results)
61
70
  )
62
71
  );
@@ -69,15 +78,15 @@ class JsonMap {
69
78
  }
70
79
 
71
80
  // Sets the output at the specified path to the last result of the transformations & returns.
72
- const last = _.last(results);
73
- _.set(output, path, last);
74
- return last;
81
+ const lastResult = last(results);
82
+ set(output, path, lastResult);
83
+ return lastResult;
75
84
  }
76
85
 
77
86
  // Checks if the current node is an object
78
- if (_.isObject(node)) {
87
+ if (isObject(node)) {
79
88
  // Creates an empty array or object based on whether the current node is an array or not
80
- const transformedNode = _.isArray(node) ? [] : {};
89
+ const transformedNode = isArray(node) ? [] : {};
81
90
 
82
91
  // Iterates over each key-value pair in the current node
83
92
  for (const [key, value] of Object.entries(node)) {
@@ -95,12 +104,12 @@ class JsonMap {
95
104
  }
96
105
 
97
106
  // Sets the output at the specified path to the transformedNode & returnsd.
98
- _.set(output, path, transformedNode);
107
+ set(output, path, transformedNode);
99
108
  return transformedNode;
100
109
  }
101
110
 
102
111
  // Sets the output at the specified path to the current node & returns.
103
- _.set(output, path, node);
112
+ set(output, path, node);
104
113
  return node;
105
114
  }
106
115
 
@@ -114,7 +123,7 @@ class JsonMap {
114
123
  */
115
124
  #resolvePath(path, results) {
116
125
  // If the path is not a string, return it as is
117
- if (!_.isString(path)) {
126
+ if (!isString(path)) {
118
127
  return path;
119
128
  }
120
129
 
@@ -131,8 +140,8 @@ class JsonMap {
131
140
  // Retrieves the value from the previous results based on the index and any remaining path
132
141
  if (match) {
133
142
  const [, index, rest] = match;
134
- const value = _.get(results, [
135
- results.length - 1 - _.parseInt(index),
143
+ const value = get(results, [
144
+ results.length - 1 - parseInt(index),
136
145
  ...(rest.length ? rest.split('.') : []),
137
146
  ]);
138
147
 
@@ -147,10 +156,10 @@ class JsonMap {
147
156
  const p = path.slice(pattern.length + 1);
148
157
 
149
158
  // Retrieves the value from the replacement object based on the remaining path
150
- const value = p.length ? _.get(replacement, p) : replacement;
159
+ const value = p.length ? get(replacement, p) : replacement;
151
160
 
152
161
  // Returns the value if it exists, otherwise returns the original path
153
- return _.isNil(value) ? path : value;
162
+ return isNil(value) ? path : value;
154
163
  }
155
164
 
156
165
  // Returns the path as is if it does not match any special patterns
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@karmaniverous/jsonmap",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -22,7 +22,15 @@
22
22
  ],
23
23
  "license": "BSD-3-Clause",
24
24
  "dependencies": {
25
- "lodash": "^4.17.21"
25
+ "lodash.castarray": "^4.4.0",
26
+ "lodash.get": "^4.4.2",
27
+ "lodash.isarray": "^4.0.0",
28
+ "lodash.isnil": "^4.0.0",
29
+ "lodash.isobject": "^3.0.2",
30
+ "lodash.isstring": "^4.0.1",
31
+ "lodash.last": "^3.0.0",
32
+ "lodash.parseint": "^4.0.2",
33
+ "lodash.set": "^4.3.2"
26
34
  },
27
35
  "devDependencies": {
28
36
  "@babel/cli": "^7.21.0",
@@ -33,7 +41,6 @@
33
41
  "@babel/register": "^7.21.0",
34
42
  "@karmaniverous/get-dotenv": "^1.0.0",
35
43
  "@types/node": "^18.15.5",
36
- "babel-plugin-lodash": "^3.3.4",
37
44
  "chai": "^4.3.7",
38
45
  "concat-md": "^0.5.1",
39
46
  "eslint": "^8.36.0",
@@ -41,6 +48,7 @@
41
48
  "eslint-plugin-jsdoc": "^40.1.0",
42
49
  "eslint-plugin-mocha": "^10.1.0",
43
50
  "jsdoc-to-markdown": "^8.0.0",
51
+ "lodash": "^4.17.21",
44
52
  "mocha": "^10.2.0",
45
53
  "numeral": "^2.0.6",
46
54
  "prettier": "^2.8.5",