@coderich/util 0.1.7 → 0.1.9

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.
Files changed (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.js +4 -4
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@coderich/util",
3
3
  "main": "src/index.js",
4
- "version": "0.1.7",
4
+ "version": "0.1.9",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -20,6 +20,6 @@
20
20
  "lodash.set": "4.3.2"
21
21
  },
22
22
  "devDependencies": {
23
- "@coderich/dev": "0.0.13"
23
+ "@coderich/dev": "0.1.0"
24
24
  }
25
25
  }
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.isPlainArrayOrObject = obj => Array.isArray(obj) || exports.isPlainObject(obj);
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.isPlainArrayOrObject;
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 && Object.keys(data).length && typeFn(data)) {
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.isPlainArrayOrObject;
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]) => {