@coderich/util 1.0.2 → 1.0.4
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 +11 -3
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -10,8 +10,8 @@ exports.isEqual = isEqual;
|
|
|
10
10
|
exports.ObjectId = ObjectId;
|
|
11
11
|
|
|
12
12
|
exports.push = (arr, el) => arr[arr.push(el) - 1];
|
|
13
|
-
exports.uvl = (...values) => values.reduce((prev, value) => (prev === undefined ? value : prev)
|
|
14
|
-
exports.nvl = (...values) => values.reduce((prev, value) => (prev === null ? value : prev)
|
|
13
|
+
exports.uvl = (...values) => values.reduce((prev, value) => (prev === undefined ? value : prev));
|
|
14
|
+
exports.nvl = (...values) => values.reduce((prev, value) => (prev === null ? value : prev));
|
|
15
15
|
exports.pairs = (...values) => values.flat().reduce((prev, curr, i, arr) => (i % 2 === 0 ? prev.concat([arr.slice(i, i + 2)]) : prev), []);
|
|
16
16
|
exports.filterBy = (arr, fn) => arr.filter((b, index) => index === arr.findIndex(a => fn(a, b)));
|
|
17
17
|
exports.ensureArray = a => (Array.isArray(a) ? a : [a].filter(el => el !== undefined));
|
|
@@ -75,7 +75,7 @@ exports.unflatten = (data, options = {}) => {
|
|
|
75
75
|
const typeFn = options.safe ? exports.isPlainObject : exports.isPlainObjectOrArray;
|
|
76
76
|
|
|
77
77
|
return exports.map(data, (el) => {
|
|
78
|
-
return typeFn(data) ? Object.entries(el).reduce((prev, [key, value]) => {
|
|
78
|
+
return typeFn(data) ? Object.entries(exports.flatten(el, options)).reduce((prev, [key, value]) => {
|
|
79
79
|
return exports.set(prev, key, value);
|
|
80
80
|
}, {}) : el;
|
|
81
81
|
});
|
|
@@ -201,3 +201,11 @@ exports.requireDir = (dir) => {
|
|
|
201
201
|
|
|
202
202
|
return data;
|
|
203
203
|
};
|
|
204
|
+
|
|
205
|
+
exports.parseRegExp = (mixed) => {
|
|
206
|
+
if (mixed instanceof RegExp) return mixed;
|
|
207
|
+
const matches = mixed.match(/^\/?(.*?)\/?([gimy]*)$/);
|
|
208
|
+
if (!matches) throw new Error(`Invalid regular expression format: ${mixed}`);
|
|
209
|
+
const [, pattern, flags] = matches;
|
|
210
|
+
return new RegExp(pattern, flags);
|
|
211
|
+
};
|