@coderich/util 0.1.8 → 0.1.10
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 +1 -1
- package/src/index.js +5 -5
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -16,7 +16,7 @@ exports.filterBy = (arr, fn) => arr.filter((b, index) => index === arr.findIndex
|
|
|
16
16
|
exports.ensureArray = a => (Array.isArray(a) ? a : [a].filter(el => el !== undefined));
|
|
17
17
|
exports.timeout = ms => new Promise((resolve) => { setTimeout(resolve, ms); });
|
|
18
18
|
exports.ucFirst = string => string.charAt(0).toUpperCase() + string.slice(1);
|
|
19
|
-
exports.
|
|
19
|
+
exports.isPlainObjectOrArray = obj => Array.isArray(obj) || exports.isPlainObject(obj);
|
|
20
20
|
|
|
21
21
|
exports.isPlainObject = (obj) => {
|
|
22
22
|
if (obj == null) return false;
|
|
@@ -42,10 +42,10 @@ exports.shellCommand = (cmd, ...args) => {
|
|
|
42
42
|
|
|
43
43
|
exports.flatten = (mixed, options = {}) => {
|
|
44
44
|
const maxDepth = options.depth ?? Infinity;
|
|
45
|
-
const typeFn = options.safe ? exports.isPlainObject : exports.
|
|
45
|
+
const typeFn = options.safe ? exports.isPlainObject : exports.isPlainObjectOrArray;
|
|
46
46
|
|
|
47
47
|
return exports.map(mixed, el => (function flatten(data, obj = {}, path = [], depth = 0) {
|
|
48
|
-
if (depth <= maxDepth &&
|
|
48
|
+
if (depth <= maxDepth && typeFn(data) && Object.keys(data).length) {
|
|
49
49
|
return Object.entries(data).reduce((o, [key, value]) => {
|
|
50
50
|
const $key = options.strict && key.split('.').length > 1 ? `['${key}']` : key;
|
|
51
51
|
return flatten(value, o, path.concat($key), depth + 1);
|
|
@@ -62,7 +62,7 @@ exports.flatten = (mixed, options = {}) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
exports.unflatten = (data, options = {}) => {
|
|
65
|
-
const typeFn = options.safe ? exports.isPlainObject : exports.
|
|
65
|
+
const typeFn = options.safe ? exports.isPlainObject : exports.isPlainObjectOrArray;
|
|
66
66
|
|
|
67
67
|
return exports.map(data, (el) => {
|
|
68
68
|
return typeFn(data) ? Object.entries(el).reduce((prev, [key, value]) => {
|
|
@@ -131,7 +131,7 @@ exports.pipeline = (thunks, startValue) => {
|
|
|
131
131
|
return thunks.reduce((promise, thunk) => {
|
|
132
132
|
return promise.then((value) => {
|
|
133
133
|
if (value !== undefined) $value = value;
|
|
134
|
-
return Promise.resolve(thunk($value));
|
|
134
|
+
return Promise.resolve(thunk($value)).then((result = $value) => result);
|
|
135
135
|
});
|
|
136
136
|
}, Promise.resolve(startValue));
|
|
137
137
|
};
|