@coderich/util 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.
- package/package.json +5 -8
- package/src/index.js +7 -3
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@coderich/util",
|
|
3
3
|
"main": "src/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -14,14 +14,11 @@
|
|
|
14
14
|
"lint": "eslint --config=.eslintrc ./",
|
|
15
15
|
"dev": "coderich-dev"
|
|
16
16
|
},
|
|
17
|
-
"devDependencies": {
|
|
18
|
-
"@coderich/dev": "0.0.13"
|
|
19
|
-
},
|
|
20
|
-
"repository": {
|
|
21
|
-
"type": "git",
|
|
22
|
-
"url": "git@github.com:CoderichLLC/nodejs-util.git"
|
|
23
|
-
},
|
|
24
17
|
"dependencies": {
|
|
18
|
+
"bson-objectid": "2.0.4",
|
|
25
19
|
"lodash.set": "4.3.2"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@coderich/dev": "0.0.13"
|
|
26
23
|
}
|
|
27
24
|
}
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const ChildProcess = require('child_process');
|
|
2
|
+
const ObjectId = require('bson-objectid');
|
|
2
3
|
const set = require('lodash.set');
|
|
3
4
|
|
|
4
5
|
exports.shellCommand = (cmd, ...args) => {
|
|
@@ -7,9 +8,12 @@ exports.shellCommand = (cmd, ...args) => {
|
|
|
7
8
|
return (stderr || stdout).trim();
|
|
8
9
|
};
|
|
9
10
|
|
|
10
|
-
exports.flatten = (mixed) => {
|
|
11
|
+
exports.flatten = (mixed, spread = true) => {
|
|
11
12
|
return exports.map(mixed, el => (function flatten(data, obj = {}, path = []) {
|
|
12
|
-
|
|
13
|
+
const type = Object.prototype.toString.call(data);
|
|
14
|
+
const types = spread ? ['[object Object]', '[object Array]'] : ['[object Object]'];
|
|
15
|
+
|
|
16
|
+
if (types.includes(type) && !ObjectId.isValid(data)) {
|
|
13
17
|
return Object.entries(data).reduce((o, [key, value]) => {
|
|
14
18
|
const $key = key.split('.').length > 1 ? `['${key}']` : key;
|
|
15
19
|
return flatten(value, o, path.concat($key));
|
|
@@ -22,7 +26,7 @@ exports.flatten = (mixed) => {
|
|
|
22
26
|
}
|
|
23
27
|
|
|
24
28
|
return data;
|
|
25
|
-
}(
|
|
29
|
+
}(el)));
|
|
26
30
|
};
|
|
27
31
|
|
|
28
32
|
exports.unflatten = (data) => {
|