ut2 1.14.0 → 1.16.0

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 (71) hide show
  1. package/README.md +7 -1
  2. package/dist/ut2.js +145 -3
  3. package/dist/ut2.js.map +1 -1
  4. package/dist/ut2.min.js +1 -1
  5. package/dist/ut2.min.js.map +1 -1
  6. package/es/fromPathPairs.js +25 -0
  7. package/es/get.js +20 -0
  8. package/es/guard.js +2 -1
  9. package/es/index.js +7 -0
  10. package/es/internals/helpers.js +1 -1
  11. package/es/internals/isIndex.js +12 -0
  12. package/es/internals/stringToPath.js +15 -0
  13. package/es/merge.js +1 -1
  14. package/es/mergeObject.js +17 -0
  15. package/es/pathPairs.js +25 -0
  16. package/es/set.js +33 -0
  17. package/es/toPath.js +20 -0
  18. package/es/unset.js +15 -0
  19. package/lib/fromPathPairs.js +27 -0
  20. package/lib/get.js +22 -0
  21. package/lib/guard.js +2 -1
  22. package/lib/index.js +14 -0
  23. package/lib/internals/helpers.js +1 -1
  24. package/lib/internals/isIndex.js +14 -0
  25. package/lib/internals/stringToPath.js +17 -0
  26. package/lib/merge.js +1 -1
  27. package/lib/mergeObject.js +19 -0
  28. package/lib/pathPairs.js +27 -0
  29. package/lib/set.js +35 -0
  30. package/lib/toPath.js +22 -0
  31. package/lib/unset.js +17 -0
  32. package/package.json +3 -5
  33. package/types/camelCase.d.ts +1 -1
  34. package/types/ceil.d.ts +1 -1
  35. package/types/compact.d.ts +1 -1
  36. package/types/eq.d.ts +1 -1
  37. package/types/escape.d.ts +1 -1
  38. package/types/escapeRegExp.d.ts +1 -1
  39. package/types/floor.d.ts +1 -1
  40. package/types/fromPairs.d.ts +2 -0
  41. package/types/fromPathPairs.d.ts +42 -0
  42. package/types/get.d.ts +21 -0
  43. package/types/index.d.ts +7 -0
  44. package/types/internals/isIndex.d.ts +17 -0
  45. package/types/internals/native.d.ts +3 -3
  46. package/types/internals/root.d.ts +1 -1
  47. package/types/internals/stringToPath.d.ts +9 -0
  48. package/types/internals/types.d.ts +1 -0
  49. package/types/invert.d.ts +1 -1
  50. package/types/isBlob.d.ts +2 -2
  51. package/types/isFile.d.ts +1 -1
  52. package/types/isLength.d.ts +1 -1
  53. package/types/isObject.d.ts +1 -1
  54. package/types/isTypedArray.d.ts +1 -1
  55. package/types/kebabCase.d.ts +1 -1
  56. package/types/merge.d.ts +1 -1
  57. package/types/mergeObject.d.ts +41 -0
  58. package/types/move.d.ts +1 -1
  59. package/types/omitBy.d.ts +1 -1
  60. package/types/orderBy.d.ts +1 -1
  61. package/types/partition.d.ts +2 -2
  62. package/types/pascalCase.d.ts +1 -1
  63. package/types/pathPairs.d.ts +30 -0
  64. package/types/pickBy.d.ts +1 -1
  65. package/types/round.d.ts +1 -1
  66. package/types/set.d.ts +24 -0
  67. package/types/snakeCase.d.ts +1 -1
  68. package/types/toLength.d.ts +1 -1
  69. package/types/toPath.d.ts +17 -0
  70. package/types/unset.d.ts +20 -0
  71. package/types/words.d.ts +1 -1
package/README.md CHANGED
@@ -64,7 +64,6 @@ const debounced = debounce(() => {
64
64
  - [chunk](https://caijf.github.io/ut2/module-Array.html#.chunk) - 拆分成多个 `size` 长度的区块。
65
65
  - [compact](https://caijf.github.io/ut2/module-Array.html#.compact) - 剔除假值元素。
66
66
  - [difference](https://caijf.github.io/ut2/module-Array.html#.difference) - 排除部分值。
67
- - [formPairs](https://caijf.github.io/ut2/module-Array.html#.fromPairs) - 将键值对转为对象。
68
67
  - [intersection](https://caijf.github.io/ut2/module-Array.html#.intersection) - 交集去重。
69
68
  - [move](https://caijf.github.io/ut2/module-Array.html#.move) - 数组元素移动。
70
69
  - [nth](https://caijf.github.io/ut2/module-Array.html#.nth) - 获取第 `n` 个元素。
@@ -155,14 +154,20 @@ const debounced = debounce(() => {
155
154
  - [allKeys](https://caijf.github.io/ut2/module-Object.html#.allKeys) - 对象自身的可枚举属性(包含 `Symbol` 属性)。
156
155
  - [allKeysIn](https://caijf.github.io/ut2/module-Object.html#.allKeysIn) - 对象自身及继承的可枚举属性(包含 `Symbol` 属性)。
157
156
  - [findKey](https://caijf.github.io/ut2/module-Object.html#.findKey) - 查找对象的键。
157
+ - [fromPathPairs](https://caijf.github.io/ut2/module-Object.html#.fromPathPairs) - 将属性路径/值对的数组转为对象。
158
+ - [get](https://caijf.github.io/ut2/module-Object.html#.get) - 获取对象路径的值。
158
159
  - [invert](https://caijf.github.io/ut2/module-Object.html#.invert) - 对象自身的可枚举属性(包含 `Symbol` 属性)和值反转。
159
160
  - [keys](https://caijf.github.io/ut2/module-Object.html#.keys) - 对象自身的可枚举属性(不包含 `Symbol` 属性)。
160
161
  - [keysIn](https://caijf.github.io/ut2/module-Object.html#.keysIn) - 对象自身及继承的可枚举属性(不包含 `Symbol` 属性)。
161
162
  - [merge](https://caijf.github.io/ut2/module-Object.html#.merge) - 递归对象自身的可枚举属性(包含 `Symbol` 属性)或数组进行合并。
163
+ - [mergeObject](https://caijf.github.io/ut2/module-Object.html#.merge) - 递归对象自身的可枚举属性(包含 `Symbol` 属性)进行合并,支持多个目标对象参数。
162
164
  - [omit](https://caijf.github.io/ut2/module-Object.html#.omit) - 排除部分属性。
163
165
  - [omitBy](https://caijf.github.io/ut2/module-Object.html#.omitBy) - 根据方法,排除部分属性。
166
+ - [pathPairs](https://caijf.github.io/ut2/module-Object.html#.pathPairs) - 将对象转为属性路径/值对的数组。
164
167
  - [pick](https://caijf.github.io/ut2/module-Object.html#.pick) - 选择部分属性。
165
168
  - [pickBy](https://caijf.github.io/ut2/module-Object.html#.pickBy) - 根据方法,选择部分属性。
169
+ - [set](https://caijf.github.io/ut2/module-Object.html#.set) - 设置对象属性路径值。
170
+ - [unset](https://caijf.github.io/ut2/module-Object.html#.unset) - 删除对象路径的属性。
166
171
  - [String](https://caijf.github.io/ut2/module-String.html) 字符串
167
172
  - [camelCase](https://caijf.github.io/ut2/module-String.html#.camelCase) - 驼峰小写。
168
173
  - [capitalize](https://caijf.github.io/ut2/module-String.html#.capitalize) - 首字母大写,其余小写。
@@ -200,6 +205,7 @@ const debounced = debounce(() => {
200
205
  - [toInteger](https://caijf.github.io/ut2/module-Util.html#.toInteger) - 转为整数。
201
206
  - [toLength](https://caijf.github.io/ut2/module-Util.html#.toLength) - 转为数组长度整数。
202
207
  - [toNumber](https://caijf.github.io/ut2/module-Util.html#.toNumber) - 转为数字。
208
+ - [toPath](https://caijf.github.io/ut2/module-Util.html#.toPath) - 转为属性路径数组。
203
209
  - [toSafeInteger](https://caijf.github.io/ut2/module-Util.html#.toSafeInteger) - 转为安全整数。
204
210
  - [toString](https://caijf.github.io/ut2/module-Util.html#.toString) - 转为字符串。
205
211
  - [tryit](https://caijf.github.io/ut2/module-Util.html#.tryit) - 包装函数为错误优先函数。
package/dist/ut2.js CHANGED
@@ -606,7 +606,7 @@
606
606
  return value == null || value !== value ? defaultValue : value;
607
607
  };
608
608
 
609
- var VERSION = "1.14.0";
609
+ var VERSION = "1.16.0";
610
610
  var isBrowser = typeof window !== stringUndefined && isObjectLike(window) && typeof document !== stringUndefined && isObjectLike(document) && window.document === document;
611
611
  var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
612
612
  var FUNC_ERROR_TEXT = 'Expected a function';
@@ -1562,6 +1562,99 @@
1562
1562
  return key;
1563
1563
  };
1564
1564
 
1565
+ function isIndex(value) {
1566
+ var type = typeof value;
1567
+ if (type === 'string' && value) {
1568
+ value = toNumber(value);
1569
+ }
1570
+ return isLength(value);
1571
+ }
1572
+
1573
+ var reEscapeChar = /\\(\\)?/g;
1574
+ var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
1575
+ function stringToPath(value) {
1576
+ var result = [];
1577
+ if (value.charCodeAt(0) === 46) {
1578
+ result.push('');
1579
+ }
1580
+ value.replace(rePropName, function (match, number, quote, subString) {
1581
+ result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
1582
+ return match;
1583
+ });
1584
+ return result;
1585
+ }
1586
+
1587
+ function toKey(value) {
1588
+ return isSymbol(value) ? value : toString(value);
1589
+ }
1590
+ function toPath(value, object) {
1591
+ if (isArray(value)) {
1592
+ return value.map(toKey);
1593
+ }
1594
+ if (isSymbol(value) || (typeof value === 'string' && isObject(object) && value in object)) {
1595
+ return [value];
1596
+ }
1597
+ return stringToPath(toString(value));
1598
+ }
1599
+
1600
+ function set(object, path, value, customizer) {
1601
+ if (!isObject(object)) {
1602
+ return object;
1603
+ }
1604
+ var paths = toPath(path, object);
1605
+ var length = paths.length;
1606
+ var lastIndex = length - 1;
1607
+ var index = -1;
1608
+ var nested = object;
1609
+ while (++index < length) {
1610
+ var key = paths[index];
1611
+ if (index === lastIndex) {
1612
+ nested[key] = value;
1613
+ }
1614
+ else {
1615
+ var objValue = nested[key];
1616
+ var newValue = customizer ? customizer(objValue, key, nested) : nativeUndefined;
1617
+ if (!isObject(newValue)) {
1618
+ newValue = isObject(objValue) ? objValue : isIndex(paths[index + 1]) ? [] : {};
1619
+ }
1620
+ nested[key] = newValue;
1621
+ nested = nested[key];
1622
+ }
1623
+ }
1624
+ return object;
1625
+ }
1626
+
1627
+ function fromPathPairs(value, customizer) {
1628
+ var valueIsArray = isArray(value);
1629
+ var firstPairPath = valueIsArray && isArray(value[0]) && isArray(value[0][0]) ? value[0][0] : [];
1630
+ var firstNode = customizer ? customizer(nativeUndefined, firstPairPath[0], nativeUndefined) : nativeUndefined;
1631
+ var result = isObject(firstNode) ? firstNode : isIndex(firstPairPath[0]) ? [] : {};
1632
+ var length = valueIsArray ? value.length : 0;
1633
+ var index = -1;
1634
+ while (++index < length) {
1635
+ var pathPair = value[index];
1636
+ if (isArray(pathPair)) {
1637
+ var _a = __read(pathPair, 2), paths = _a[0], val = _a[1];
1638
+ set(result, paths, val, customizer);
1639
+ }
1640
+ }
1641
+ return result;
1642
+ }
1643
+
1644
+ function baseGet(object, key) {
1645
+ var paths = toPath(key, object);
1646
+ var length = paths.length;
1647
+ var index = 0;
1648
+ while (!isNil(object) && index < length) {
1649
+ object = object[paths[index++]];
1650
+ }
1651
+ return index && index === length ? object : nativeUndefined;
1652
+ }
1653
+ function get(object, key, defaultValue) {
1654
+ var result = isNil(object) ? nativeUndefined : baseGet(object, key);
1655
+ return isUndefined(result) ? defaultValue : result;
1656
+ }
1657
+
1565
1658
  function invert(object, predicate) {
1566
1659
  if (predicate === void 0) { predicate = stubTrue; }
1567
1660
  var _keys = allKeys(object);
@@ -1639,7 +1732,20 @@
1639
1732
  if (getKeys === void 0) { getKeys = allKeys; }
1640
1733
  return baseMerge(object, source, getKeys, customizer);
1641
1734
  }
1642
- merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue : undefined); };
1735
+ merge.NOT_MERGE_ARRAYS = function (objValue, srcValue) { return (isArray(srcValue) ? srcValue : nativeUndefined); };
1736
+
1737
+ var mergeObject = function (object, source) {
1738
+ var args = [];
1739
+ for (var _i = 2; _i < arguments.length; _i++) {
1740
+ args[_i - 2] = arguments[_i];
1741
+ }
1742
+ if (args.length > 0) {
1743
+ var _a = __read(args), arg1 = _a[0], restArgs = _a.slice(1);
1744
+ var obj = merge(object, source, merge.NOT_MERGE_ARRAYS);
1745
+ return mergeObject.apply(void 0, __spreadArray([obj, arg1], __read(restArgs), false));
1746
+ }
1747
+ return merge(object, source, merge.NOT_MERGE_ARRAYS);
1748
+ };
1643
1749
 
1644
1750
  function castArray(value) {
1645
1751
  if (!arguments.length) {
@@ -1693,6 +1799,35 @@
1693
1799
  return result;
1694
1800
  }
1695
1801
 
1802
+ function basePathPairs(object, parentPath) {
1803
+ if (parentPath === void 0) { parentPath = []; }
1804
+ var result = [];
1805
+ if (isObjectLike(object)) {
1806
+ forEach(object, function (v, k) {
1807
+ var currentPath = parentPath.concat([k]);
1808
+ if (isObjectLike(v)) {
1809
+ result.push.apply(result, __spreadArray([], __read(basePathPairs(v, currentPath)), false));
1810
+ }
1811
+ else {
1812
+ result.push([currentPath, v]);
1813
+ }
1814
+ });
1815
+ }
1816
+ return result;
1817
+ }
1818
+ function pathPairs(object) {
1819
+ return basePathPairs(object);
1820
+ }
1821
+
1822
+ function unset(object, path) {
1823
+ if (isNil(object)) {
1824
+ return true;
1825
+ }
1826
+ var paths = toPath(path, object);
1827
+ var parent = paths.length < 2 ? object : get(object, paths.slice(0, -1));
1828
+ return isNil(parent) ? true : delete parent[nth(paths, -1)];
1829
+ }
1830
+
1696
1831
  var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
1697
1832
  function words(string, pattern) {
1698
1833
  if (pattern === void 0) { pattern = reAsciiWord; }
@@ -1834,7 +1969,7 @@
1834
1969
  if (shouldGuard && !shouldGuard(err)) {
1835
1970
  throw err;
1836
1971
  }
1837
- return undefined;
1972
+ return nativeUndefined;
1838
1973
  };
1839
1974
  try {
1840
1975
  var result = fn();
@@ -2029,6 +2164,8 @@
2029
2164
  exports.forEach = forEach;
2030
2165
  exports.forEachRight = forEachRight;
2031
2166
  exports.fromPairs = fromPairs;
2167
+ exports.fromPathPairs = fromPathPairs;
2168
+ exports.get = get;
2032
2169
  exports.groupBy = groupBy;
2033
2170
  exports.gt = gt;
2034
2171
  exports.gte = gte;
@@ -2090,6 +2227,7 @@
2090
2227
  exports.map = map;
2091
2228
  exports.max = max;
2092
2229
  exports.merge = merge;
2230
+ exports.mergeObject = mergeObject;
2093
2231
  exports.min = min;
2094
2232
  exports.move = move;
2095
2233
  exports.negate = negate;
@@ -2103,6 +2241,7 @@
2103
2241
  exports.partial = partial;
2104
2242
  exports.partition = partition;
2105
2243
  exports.pascalCase = pascalCase;
2244
+ exports.pathPairs = pathPairs;
2106
2245
  exports.pick = pick;
2107
2246
  exports.pickBy = pickBy;
2108
2247
  exports.random = random;
@@ -2113,6 +2252,7 @@
2113
2252
  exports.retry = retry;
2114
2253
  exports.root = root;
2115
2254
  exports.round = round;
2255
+ exports.set = set;
2116
2256
  exports.shuffle = shuffle;
2117
2257
  exports.sleep = sleep;
2118
2258
  exports.snakeCase = snakeCase;
@@ -2123,6 +2263,7 @@
2123
2263
  exports.toInteger = toInteger;
2124
2264
  exports.toLength = toLength;
2125
2265
  exports.toNumber = toNumber;
2266
+ exports.toPath = toPath;
2126
2267
  exports.toSafeInteger = toSafeInteger;
2127
2268
  exports.toString = toString;
2128
2269
  exports.tryit = tryit;
@@ -2130,6 +2271,7 @@
2130
2271
  exports.union = union;
2131
2272
  exports.uniq = uniq;
2132
2273
  exports.uniqueId = uniqueId;
2274
+ exports.unset = unset;
2133
2275
  exports.unzip = unzip;
2134
2276
  exports.upperCase = upperCase;
2135
2277
  exports.upperFirst = upperFirst;