ut2 1.15.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 (68) hide show
  1. package/README.md +7 -0
  2. package/dist/ut2.js +131 -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 +6 -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/pathPairs.js +25 -0
  15. package/es/set.js +33 -0
  16. package/es/toPath.js +20 -0
  17. package/es/unset.js +15 -0
  18. package/lib/fromPathPairs.js +27 -0
  19. package/lib/get.js +22 -0
  20. package/lib/guard.js +2 -1
  21. package/lib/index.js +12 -0
  22. package/lib/internals/helpers.js +1 -1
  23. package/lib/internals/isIndex.js +14 -0
  24. package/lib/internals/stringToPath.js +17 -0
  25. package/lib/merge.js +1 -1
  26. package/lib/pathPairs.js +27 -0
  27. package/lib/set.js +35 -0
  28. package/lib/toPath.js +22 -0
  29. package/lib/unset.js +17 -0
  30. package/package.json +3 -5
  31. package/types/camelCase.d.ts +1 -1
  32. package/types/ceil.d.ts +1 -1
  33. package/types/compact.d.ts +1 -1
  34. package/types/eq.d.ts +1 -1
  35. package/types/escape.d.ts +1 -1
  36. package/types/escapeRegExp.d.ts +1 -1
  37. package/types/floor.d.ts +1 -1
  38. package/types/fromPathPairs.d.ts +42 -0
  39. package/types/get.d.ts +21 -0
  40. package/types/index.d.ts +6 -0
  41. package/types/internals/isIndex.d.ts +17 -0
  42. package/types/internals/native.d.ts +3 -3
  43. package/types/internals/root.d.ts +1 -1
  44. package/types/internals/stringToPath.d.ts +9 -0
  45. package/types/internals/types.d.ts +1 -0
  46. package/types/invert.d.ts +1 -1
  47. package/types/isBlob.d.ts +2 -2
  48. package/types/isFile.d.ts +1 -1
  49. package/types/isLength.d.ts +1 -1
  50. package/types/isObject.d.ts +1 -1
  51. package/types/isTypedArray.d.ts +1 -1
  52. package/types/kebabCase.d.ts +1 -1
  53. package/types/merge.d.ts +1 -1
  54. package/types/mergeObject.d.ts +1 -1
  55. package/types/move.d.ts +1 -1
  56. package/types/omitBy.d.ts +1 -1
  57. package/types/orderBy.d.ts +1 -1
  58. package/types/partition.d.ts +2 -2
  59. package/types/pascalCase.d.ts +1 -1
  60. package/types/pathPairs.d.ts +30 -0
  61. package/types/pickBy.d.ts +1 -1
  62. package/types/round.d.ts +1 -1
  63. package/types/set.d.ts +24 -0
  64. package/types/snakeCase.d.ts +1 -1
  65. package/types/toLength.d.ts +1 -1
  66. package/types/toPath.d.ts +17 -0
  67. package/types/unset.d.ts +20 -0
  68. package/types/words.d.ts +1 -1
package/README.md CHANGED
@@ -154,14 +154,20 @@ const debounced = debounce(() => {
154
154
  - [allKeys](https://caijf.github.io/ut2/module-Object.html#.allKeys) - 对象自身的可枚举属性(包含 `Symbol` 属性)。
155
155
  - [allKeysIn](https://caijf.github.io/ut2/module-Object.html#.allKeysIn) - 对象自身及继承的可枚举属性(包含 `Symbol` 属性)。
156
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) - 获取对象路径的值。
157
159
  - [invert](https://caijf.github.io/ut2/module-Object.html#.invert) - 对象自身的可枚举属性(包含 `Symbol` 属性)和值反转。
158
160
  - [keys](https://caijf.github.io/ut2/module-Object.html#.keys) - 对象自身的可枚举属性(不包含 `Symbol` 属性)。
159
161
  - [keysIn](https://caijf.github.io/ut2/module-Object.html#.keysIn) - 对象自身及继承的可枚举属性(不包含 `Symbol` 属性)。
160
162
  - [merge](https://caijf.github.io/ut2/module-Object.html#.merge) - 递归对象自身的可枚举属性(包含 `Symbol` 属性)或数组进行合并。
163
+ - [mergeObject](https://caijf.github.io/ut2/module-Object.html#.merge) - 递归对象自身的可枚举属性(包含 `Symbol` 属性)进行合并,支持多个目标对象参数。
161
164
  - [omit](https://caijf.github.io/ut2/module-Object.html#.omit) - 排除部分属性。
162
165
  - [omitBy](https://caijf.github.io/ut2/module-Object.html#.omitBy) - 根据方法,排除部分属性。
166
+ - [pathPairs](https://caijf.github.io/ut2/module-Object.html#.pathPairs) - 将对象转为属性路径/值对的数组。
163
167
  - [pick](https://caijf.github.io/ut2/module-Object.html#.pick) - 选择部分属性。
164
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) - 删除对象路径的属性。
165
171
  - [String](https://caijf.github.io/ut2/module-String.html) 字符串
166
172
  - [camelCase](https://caijf.github.io/ut2/module-String.html#.camelCase) - 驼峰小写。
167
173
  - [capitalize](https://caijf.github.io/ut2/module-String.html#.capitalize) - 首字母大写,其余小写。
@@ -199,6 +205,7 @@ const debounced = debounce(() => {
199
205
  - [toInteger](https://caijf.github.io/ut2/module-Util.html#.toInteger) - 转为整数。
200
206
  - [toLength](https://caijf.github.io/ut2/module-Util.html#.toLength) - 转为数组长度整数。
201
207
  - [toNumber](https://caijf.github.io/ut2/module-Util.html#.toNumber) - 转为数字。
208
+ - [toPath](https://caijf.github.io/ut2/module-Util.html#.toPath) - 转为属性路径数组。
202
209
  - [toSafeInteger](https://caijf.github.io/ut2/module-Util.html#.toSafeInteger) - 转为安全整数。
203
210
  - [toString](https://caijf.github.io/ut2/module-Util.html#.toString) - 转为字符串。
204
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.15.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,7 @@
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); };
1643
1736
 
1644
1737
  var mergeObject = function (object, source) {
1645
1738
  var args = [];
@@ -1706,6 +1799,35 @@
1706
1799
  return result;
1707
1800
  }
1708
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
+
1709
1831
  var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
1710
1832
  function words(string, pattern) {
1711
1833
  if (pattern === void 0) { pattern = reAsciiWord; }
@@ -1847,7 +1969,7 @@
1847
1969
  if (shouldGuard && !shouldGuard(err)) {
1848
1970
  throw err;
1849
1971
  }
1850
- return undefined;
1972
+ return nativeUndefined;
1851
1973
  };
1852
1974
  try {
1853
1975
  var result = fn();
@@ -2042,6 +2164,8 @@
2042
2164
  exports.forEach = forEach;
2043
2165
  exports.forEachRight = forEachRight;
2044
2166
  exports.fromPairs = fromPairs;
2167
+ exports.fromPathPairs = fromPathPairs;
2168
+ exports.get = get;
2045
2169
  exports.groupBy = groupBy;
2046
2170
  exports.gt = gt;
2047
2171
  exports.gte = gte;
@@ -2117,6 +2241,7 @@
2117
2241
  exports.partial = partial;
2118
2242
  exports.partition = partition;
2119
2243
  exports.pascalCase = pascalCase;
2244
+ exports.pathPairs = pathPairs;
2120
2245
  exports.pick = pick;
2121
2246
  exports.pickBy = pickBy;
2122
2247
  exports.random = random;
@@ -2127,6 +2252,7 @@
2127
2252
  exports.retry = retry;
2128
2253
  exports.root = root;
2129
2254
  exports.round = round;
2255
+ exports.set = set;
2130
2256
  exports.shuffle = shuffle;
2131
2257
  exports.sleep = sleep;
2132
2258
  exports.snakeCase = snakeCase;
@@ -2137,6 +2263,7 @@
2137
2263
  exports.toInteger = toInteger;
2138
2264
  exports.toLength = toLength;
2139
2265
  exports.toNumber = toNumber;
2266
+ exports.toPath = toPath;
2140
2267
  exports.toSafeInteger = toSafeInteger;
2141
2268
  exports.toString = toString;
2142
2269
  exports.tryit = tryit;
@@ -2144,6 +2271,7 @@
2144
2271
  exports.union = union;
2145
2272
  exports.uniq = uniq;
2146
2273
  exports.uniqueId = uniqueId;
2274
+ exports.unset = unset;
2147
2275
  exports.unzip = unzip;
2148
2276
  exports.upperCase = upperCase;
2149
2277
  exports.upperFirst = upperFirst;