ut2 1.12.0 → 1.13.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.
package/README.md CHANGED
@@ -154,6 +154,7 @@ const debounced = debounce(() => {
154
154
  - [Object](https://caijf.github.io/ut2/module-Object.html) 对象
155
155
  - [allKeys](https://caijf.github.io/ut2/module-Object.html#.allKeys) - 对象自身的可枚举属性(包含 `Symbol` 属性)。
156
156
  - [allKeysIn](https://caijf.github.io/ut2/module-Object.html#.allKeysIn) - 对象自身及继承的可枚举属性(包含 `Symbol` 属性)。
157
+ - [findKey](https://caijf.github.io/ut2/module-Object.html#.findKey) - 查找对象的键。
157
158
  - [invert](https://caijf.github.io/ut2/module-Object.html#.invert) - 对象自身的可枚举属性(包含 `Symbol` 属性)和值反转。
158
159
  - [keys](https://caijf.github.io/ut2/module-Object.html#.keys) - 对象自身的可枚举属性(不包含 `Symbol` 属性)。
159
160
  - [keysIn](https://caijf.github.io/ut2/module-Object.html#.keysIn) - 对象自身及继承的可枚举属性(不包含 `Symbol` 属性)。
@@ -199,6 +200,7 @@ const debounced = debounce(() => {
199
200
  - [toNumber](https://caijf.github.io/ut2/module-Util.html#.toNumber) - 转为数字。
200
201
  - [toSafeInteger](https://caijf.github.io/ut2/module-Util.html#.toSafeInteger) - 转为安全整数。
201
202
  - [toString](https://caijf.github.io/ut2/module-Util.html#.toString) - 转为字符串。
203
+ - [tryit](https://caijf.github.io/ut2/module-Util.html#.tryit) - 包装函数为错误优先函数。
202
204
  - [uniqueId](https://caijf.github.io/ut2/module-Util.html#.uniqueId) - 唯一 ID。
203
205
  - [GLOBAL](https://caijf.github.io/ut2/global.html) 其他导出的成员
204
206
  - [MAX_ARRAY_LENGTH](https://caijf.github.io/ut2/global.html#MAX_ARRAY_LENGTH) - 最大数组长度。
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.12.0";
609
+ var VERSION = "1.13.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';
@@ -1430,6 +1430,100 @@
1430
1430
  return getKeysIn(object).concat(getSymbolsIn(object));
1431
1431
  }
1432
1432
 
1433
+ /******************************************************************************
1434
+ Copyright (c) Microsoft Corporation.
1435
+
1436
+ Permission to use, copy, modify, and/or distribute this software for any
1437
+ purpose with or without fee is hereby granted.
1438
+
1439
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
1440
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
1441
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
1442
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
1443
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
1444
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
1445
+ PERFORMANCE OF THIS SOFTWARE.
1446
+ ***************************************************************************** */
1447
+ /* global Reflect, Promise, SuppressedError, Symbol */
1448
+
1449
+
1450
+ function __values(o) {
1451
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
1452
+ if (m) return m.call(o);
1453
+ if (o && typeof o.length === "number") return {
1454
+ next: function () {
1455
+ if (o && i >= o.length) o = void 0;
1456
+ return { value: o && o[i++], done: !o };
1457
+ }
1458
+ };
1459
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
1460
+ }
1461
+
1462
+ function __read(o, n) {
1463
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1464
+ if (!m) return o;
1465
+ var i = m.call(o), r, ar = [], e;
1466
+ try {
1467
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1468
+ }
1469
+ catch (error) { e = { error: error }; }
1470
+ finally {
1471
+ try {
1472
+ if (r && !r.done && (m = i["return"])) m.call(i);
1473
+ }
1474
+ finally { if (e) throw e.error; }
1475
+ }
1476
+ return ar;
1477
+ }
1478
+
1479
+ function __spreadArray(to, from, pack) {
1480
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1481
+ if (ar || !(i in from)) {
1482
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1483
+ ar[i] = from[i];
1484
+ }
1485
+ }
1486
+ return to.concat(ar || Array.prototype.slice.call(from));
1487
+ }
1488
+
1489
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1490
+ var e = new Error(message);
1491
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1492
+ };
1493
+
1494
+ var findKey = function (obj, predicate) {
1495
+ var e_1, _a;
1496
+ if (predicate === void 0) { predicate = stubFlase; }
1497
+ var key;
1498
+ if (isMap(obj)) {
1499
+ try {
1500
+ for (var obj_1 = __values(obj), obj_1_1 = obj_1.next(); !obj_1_1.done; obj_1_1 = obj_1.next()) {
1501
+ var _b = __read(obj_1_1.value, 2), k = _b[0], v = _b[1];
1502
+ if (predicate(v, k)) {
1503
+ key = k;
1504
+ break;
1505
+ }
1506
+ }
1507
+ }
1508
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1509
+ finally {
1510
+ try {
1511
+ if (obj_1_1 && !obj_1_1.done && (_a = obj_1.return)) _a.call(obj_1);
1512
+ }
1513
+ finally { if (e_1) throw e_1.error; }
1514
+ }
1515
+ }
1516
+ else if (isObject(obj)) {
1517
+ forEach(obj, function (v, k) {
1518
+ if (predicate(v, k)) {
1519
+ key = k;
1520
+ return false;
1521
+ }
1522
+ });
1523
+ }
1524
+ return key;
1525
+ };
1526
+
1433
1527
  function invert(object, predicate) {
1434
1528
  if (predicate === void 0) { predicate = stubTrue; }
1435
1529
  var _keys = allKeys(object);
@@ -1776,6 +1870,31 @@
1776
1870
  return value;
1777
1871
  }
1778
1872
 
1873
+ var tryit = function (fn) {
1874
+ return function () {
1875
+ var args = [];
1876
+ for (var _i = 0; _i < arguments.length; _i++) {
1877
+ args[_i] = arguments[_i];
1878
+ }
1879
+ try {
1880
+ var result = fn.apply(void 0, __spreadArray([], __read(args), false));
1881
+ if (isPromiseLike(result)) {
1882
+ return result
1883
+ .then(function (res) {
1884
+ return [null, res];
1885
+ })
1886
+ .catch(function (err) {
1887
+ return [err, nativeUndefined];
1888
+ });
1889
+ }
1890
+ return [null, result];
1891
+ }
1892
+ catch (err) {
1893
+ return [err, nativeUndefined];
1894
+ }
1895
+ };
1896
+ };
1897
+
1779
1898
  var idCounter = 0;
1780
1899
  var defaultPrefix = '_' + mathRandom().toString(36).substring(2, 4);
1781
1900
  function uniqueId(prefix) {
@@ -1813,6 +1932,7 @@
1813
1932
  exports.every = every;
1814
1933
  exports.filter = filter;
1815
1934
  exports.find = find;
1935
+ exports.findKey = findKey;
1816
1936
  exports.floor = floor;
1817
1937
  exports.forEach = forEach;
1818
1938
  exports.forEachRight = forEachRight;
@@ -1911,6 +2031,7 @@
1911
2031
  exports.toNumber = toNumber;
1912
2032
  exports.toSafeInteger = toSafeInteger;
1913
2033
  exports.toString = toString;
2034
+ exports.tryit = tryit;
1914
2035
  exports.unescape = unescape;
1915
2036
  exports.union = union;
1916
2037
  exports.uniq = uniq;