@coderich/util 0.0.4 → 0.0.6
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 +2 -1
- package/src/index.js +12 -1
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.6",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"dev": "coderich-dev"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
+
"bson-objectid": "2.0.4",
|
|
18
19
|
"lodash.set": "4.3.2"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
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) => {
|
|
@@ -12,7 +13,7 @@ exports.flatten = (mixed, spread = true) => {
|
|
|
12
13
|
const type = Object.prototype.toString.call(data);
|
|
13
14
|
const types = spread ? ['[object Object]', '[object Array]'] : ['[object Object]'];
|
|
14
15
|
|
|
15
|
-
if (types.includes(type)) {
|
|
16
|
+
if (types.includes(type) && !ObjectId.isValid(data)) {
|
|
16
17
|
return Object.entries(data).reduce((o, [key, value]) => {
|
|
17
18
|
const $key = key.split('.').length > 1 ? `['${key}']` : key;
|
|
18
19
|
return flatten(value, o, path.concat($key));
|
|
@@ -43,3 +44,13 @@ exports.map = (mixed, fn) => {
|
|
|
43
44
|
const results = arr.map((...args) => fn(...args));
|
|
44
45
|
return isArray ? results : results[0];
|
|
45
46
|
};
|
|
47
|
+
|
|
48
|
+
exports.promiseChain = (promiseThunks) => {
|
|
49
|
+
return promiseThunks.reduce((chain, promiseThunk) => {
|
|
50
|
+
return chain.then((chainResult) => {
|
|
51
|
+
return promiseThunk(chainResult).then((promiseResult) => {
|
|
52
|
+
return [...chainResult, promiseResult];
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}, Promise.resolve([]));
|
|
56
|
+
};
|