ut2 1.7.2 → 1.8.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 (48) hide show
  1. package/README.md +6 -2
  2. package/dist/ut2.js +72 -12
  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/conforms.js +4 -3
  7. package/es/curry.js +32 -0
  8. package/es/index.js +4 -0
  9. package/es/internals/helpers.js +3 -2
  10. package/es/internals/native.js +2 -1
  11. package/es/invert.js +22 -0
  12. package/es/isBigInt.js +8 -0
  13. package/es/omit.js +4 -3
  14. package/es/partial.js +1 -1
  15. package/es/pascalCase.js +11 -0
  16. package/es/pick.js +4 -3
  17. package/lib/conforms.js +4 -3
  18. package/lib/curry.js +34 -0
  19. package/lib/index.js +8 -0
  20. package/lib/internals/helpers.js +2 -1
  21. package/lib/internals/native.js +1 -0
  22. package/lib/invert.js +24 -0
  23. package/lib/isBigInt.js +10 -0
  24. package/lib/omit.js +4 -3
  25. package/lib/partial.js +1 -1
  26. package/lib/pascalCase.js +13 -0
  27. package/lib/pick.js +4 -3
  28. package/package.json +1 -1
  29. package/types/allKeys.d.ts +1 -1
  30. package/types/allKeysIn.d.ts +1 -1
  31. package/types/conforms.d.ts +7 -2
  32. package/types/conformsTo.d.ts +3 -3
  33. package/types/curry.d.ts +123 -0
  34. package/types/delay.d.ts +1 -1
  35. package/types/index.d.ts +4 -0
  36. package/types/internals/helpers.d.ts +1 -0
  37. package/types/internals/native.d.ts +1 -0
  38. package/types/internals/types.d.ts +2 -0
  39. package/types/invert.d.ts +19 -0
  40. package/types/isBigInt.d.ts +22 -0
  41. package/types/keys.d.ts +1 -1
  42. package/types/keysIn.d.ts +1 -1
  43. package/types/omit.d.ts +6 -1
  44. package/types/omitBy.d.ts +3 -2
  45. package/types/partial.d.ts +5 -5
  46. package/types/pascalCase.d.ts +27 -0
  47. package/types/pick.d.ts +6 -1
  48. package/types/pickBy.d.ts +3 -2
package/README.md CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  **与其他工具库对比([`lodash`]、[`underscore`])**
10
10
 
11
- - 基于 ES2015+ 标准,无需原生支持的方法(`forEach`、`filter`、`Object.keys`、`Object.entries` ……)。
11
+ - 大部分是基于 ES2015+ 标准实现的纯函数,没有过多的包装嵌套。
12
12
  - 使用 TypeScript 实现,提供类型定义。
13
13
  - 导出 `es`、`cjs`、`umd` 模块格式,支持不同开发环境使用。
14
14
 
@@ -91,6 +91,7 @@ const debounced = debounce(() => {
91
91
  - [Function](https://caijf.github.io/ut2/module-Function.html) 函数
92
92
  - [after](https://caijf.github.io/ut2/module-Function.html#.after) - 调用 `n` 或更多次之后触发。
93
93
  - [before](https://caijf.github.io/ut2/module-Function.html#.before) - 调用次数少于 `n` 次之前触发。
94
+ - [curry](https://caijf.github.io/ut2/module-Function.html#.curry) - 柯里化函数。
94
95
  - [debounce](https://caijf.github.io/ut2/module-Function.html#.debounce) - 防抖函数。
95
96
  - [delay](https://caijf.github.io/ut2/module-Function.html#.delay) - 延迟触发。
96
97
  - [negate](https://caijf.github.io/ut2/module-Function.html#.negate) - 否定断言。
@@ -103,6 +104,7 @@ const debounced = debounce(() => {
103
104
  - [isArrayBuffer](https://caijf.github.io/ut2/module-Language.html#.isArrayBuffer) - `ArrayBuffer` 对象。
104
105
  - [isArrayLike](https://caijf.github.io/ut2/module-Language.html#.isArrayLike) - 类数组。
105
106
  - [isArrayLikeObject](https://caijf.github.io/ut2/module-Language.html#.isArrayLikeObject) - 类数组对象。
107
+ - [isBigInt](https://caijf.github.io/ut2/module-Language.html#.isBigInt) - `bigint` 类型或对象。
106
108
  - [isBlob](https://caijf.github.io/ut2/module-Language.html#.isBlob) - `Blob` 对象。
107
109
  - [isBoolean](https://caijf.github.io/ut2/module-Language.html#.isBoolean) - 布尔类型或对象。
108
110
  - [isBuffer](https://caijf.github.io/ut2/module-Language.html#.isBuffer) - `Buffer` 对象。
@@ -149,6 +151,7 @@ const debounced = debounce(() => {
149
151
  - [Object](https://caijf.github.io/ut2/module-Object.html) 对象
150
152
  - [allKeys](https://caijf.github.io/ut2/module-Object.html#.allKeys) - 对象自身的可枚举属性(包含 `Symbol` 属性)。
151
153
  - [allKeysIn](https://caijf.github.io/ut2/module-Object.html#.allKeysIn) - 对象自身及继承的可枚举属性(包含 `Symbol` 属性)。
154
+ - [invert](https://caijf.github.io/ut2/module-Object.html#.invert) - 对象自身的可枚举属性(不包含 `Symbol` 属性)和值反转。
152
155
  - [keys](https://caijf.github.io/ut2/module-Object.html#.keys) - 对象自身的可枚举属性(不包含 `Symbol` 属性)。
153
156
  - [keysIn](https://caijf.github.io/ut2/module-Object.html#.keysIn) - 对象自身及继承的可枚举属性(不包含 `Symbol` 属性)。
154
157
  - [merge](https://caijf.github.io/ut2/module-Object.html#.merge) - 递归对象或数组进行合并。
@@ -164,7 +167,8 @@ const debounced = debounce(() => {
164
167
  - [kebabCase](https://caijf.github.io/ut2/module-String.html#.kebabCase) - 连接符分隔小写。
165
168
  - [lowerCase](https://caijf.github.io/ut2/module-String.html#.lowerCase) - 空格分隔小写。
166
169
  - [lowerFirst](https://caijf.github.io/ut2/module-String.html#.lowerFirst) - 首字母小写。
167
- - [snakeCase](https://caijf.github.io/ut2/module-String.html#.snakeCase) - 下划线分隔小写
170
+ - [pascalCase](https://caijf.github.io/ut2/module-String.html#.pascalCase) - 帕斯卡小写。又名大驼峰。
171
+ - [snakeCase](https://caijf.github.io/ut2/module-String.html#.snakeCase) - 下划线分隔小写。
168
172
  - [unescape](https://caijf.github.io/ut2/module-String.html#.unescape) - 转义字符串中的 HTML 实体字符 `&` `<` `"` `'`。
169
173
  - [upperCase](https://caijf.github.io/ut2/module-String.html#.upperCase) - 空格分隔大写。
170
174
  - [upperFirst](https://caijf.github.io/ut2/module-String.html#.upperFirst) - 首字母大写。
package/dist/ut2.js CHANGED
@@ -32,6 +32,7 @@
32
32
  var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || 9007199254740991;
33
33
  var MIN_SAFE_INTEGER = Number.MIN_SAFE_INTEGER || -9007199254740991;
34
34
  var MAX_ARRAY_LENGTH = 4294967295;
35
+ var bigIntTag = '[object BigInt]';
35
36
  var numberTag = '[object Number]';
36
37
  var booleanTag = '[object Boolean]';
37
38
  var stringTag = '[object String]';
@@ -598,7 +599,7 @@
598
599
  return value == null || value !== value ? defaultValue : value;
599
600
  };
600
601
 
601
- var VERSION = "1.7.2";
602
+ var VERSION = "1.8.0";
602
603
  var supportedArgumentsType = getTag((function () { return arguments; })()) === argumentsTag;
603
604
  var FUNC_ERROR_TEXT = 'Expected a function';
604
605
  function toSource(func) {
@@ -617,6 +618,7 @@
617
618
  return '';
618
619
  }
619
620
  var stubFlase = function () { return false; };
621
+ var stubTrue = function () { return true; };
620
622
 
621
623
  function after(n, func) {
622
624
  if (typeof func !== 'function') {
@@ -647,6 +649,36 @@
647
649
  };
648
650
  }
649
651
 
652
+ function isUndefined(value) {
653
+ return value === void 0;
654
+ }
655
+
656
+ var PLACEHOLDER$1 = {
657
+ __ut2_curry_ph__: null
658
+ };
659
+ var curry = function (func, arity) {
660
+ arity = isUndefined(arity) ? func.length : mathMax(toInteger(arity), 0);
661
+ function wrap() {
662
+ var args = arrayProtoSlice.call(arguments);
663
+ var context = this;
664
+ function inner() {
665
+ var argsInner = arrayProtoSlice.call(arguments);
666
+ for (var i = 0; i < args.length; i++) {
667
+ args[i] = args[i] === PLACEHOLDER$1 && argsInner.length > 0 ? argsInner.shift() : args[i];
668
+ }
669
+ args = args.concat(argsInner);
670
+ var realArgsLength = args.filter(function (arg) { return arg !== PLACEHOLDER$1; }).length;
671
+ if (realArgsLength >= arity) {
672
+ return func.apply(context, args);
673
+ }
674
+ return inner;
675
+ }
676
+ return inner();
677
+ }
678
+ return wrap;
679
+ };
680
+ curry.placeholder = curry._ = PLACEHOLDER$1;
681
+
650
682
  function baseDebounce(func, wait, immediate, __throttle__) {
651
683
  if (__throttle__ === void 0) { __throttle__ = false; }
652
684
  if (typeof func !== 'function') {
@@ -762,7 +794,7 @@
762
794
  }
763
795
 
764
796
  var PLACEHOLDER = {
765
- __ut2_partial__: 1
797
+ __ut2_partial_ph__: null
766
798
  };
767
799
  var partial = function (func) {
768
800
  var argsOrig = arrayProtoSlice.call(arguments, 1);
@@ -813,6 +845,10 @@
813
845
  return nodeIsArrayBuffer ? nodeIsArrayBuffer(value) : getTag(value) === arrayBufferTag;
814
846
  }
815
847
 
848
+ function isBigInt(value) {
849
+ return typeof value === 'bigint' || getTag(value) === bigIntTag;
850
+ }
851
+
816
852
  var blobExisted = typeof Blob !== 'undefined';
817
853
  function isBlob(value) {
818
854
  if (blobExisted && value instanceof Blob) {
@@ -1267,10 +1303,6 @@
1267
1303
  return typeof value === 'string' || getTag(value) === stringTag;
1268
1304
  }
1269
1305
 
1270
- function isUndefined(value) {
1271
- return value === void 0;
1272
- }
1273
-
1274
1306
  function isWeakMap(value) {
1275
1307
  return getTagWithBugfix$1(value) === weakMapTag;
1276
1308
  }
@@ -1421,6 +1453,23 @@
1421
1453
  return getKeysIn(object).concat(getSymbolsIn(object));
1422
1454
  }
1423
1455
 
1456
+ function invert(object, predicate) {
1457
+ if (predicate === void 0) { predicate = stubTrue; }
1458
+ var _keys = keys$1(object);
1459
+ var result = {};
1460
+ _keys.forEach(function (key) {
1461
+ var value = object[key];
1462
+ if (predicate(value, key)) {
1463
+ var valueStr = value != null && typeof value.toString != 'function' ? objectProtoToString.call(value) : value;
1464
+ result[valueStr] = key;
1465
+ }
1466
+ else {
1467
+ result[key] = value;
1468
+ }
1469
+ });
1470
+ return result;
1471
+ }
1472
+
1424
1473
  function keysIn(object) {
1425
1474
  if (!isObject(object)) {
1426
1475
  return [];
@@ -1482,7 +1531,7 @@
1482
1531
  return isArray(value) ? value : [value];
1483
1532
  }
1484
1533
 
1485
- function omit(object, fields) {
1534
+ var omit = function (object, fields) {
1486
1535
  if (fields === void 0) { fields = []; }
1487
1536
  var keys = allKeysIn(object);
1488
1537
  var fieldArr = castArray(fields);
@@ -1493,7 +1542,7 @@
1493
1542
  }
1494
1543
  });
1495
1544
  return result;
1496
- }
1545
+ };
1497
1546
 
1498
1547
  function pickBy(object, predicate) {
1499
1548
  if (predicate === void 0) { predicate = stubFlase; }
@@ -1515,7 +1564,7 @@
1515
1564
  return pickBy(object, negate(predicate));
1516
1565
  }
1517
1566
 
1518
- function pick(object, fields) {
1567
+ var pick = function (object, fields) {
1519
1568
  if (fields === void 0) { fields = []; }
1520
1569
  var result = {};
1521
1570
  var fieldArr = castArray(fields);
@@ -1525,7 +1574,7 @@
1525
1574
  }
1526
1575
  });
1527
1576
  return result;
1528
- }
1577
+ };
1529
1578
 
1530
1579
  var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
1531
1580
  function words(string, pattern) {
@@ -1596,6 +1645,13 @@
1596
1645
 
1597
1646
  var lowerFirst = createCaseFirst('toLowerCase');
1598
1647
 
1648
+ function pascalCase(string, pattern) {
1649
+ return splitCaseWords(string, pattern).reduce(function (prev, cur) {
1650
+ cur = cur.toLowerCase();
1651
+ return prev + upperFirst(cur);
1652
+ }, '');
1653
+ }
1654
+
1599
1655
  function snakeCase(string, pattern) {
1600
1656
  return splitCaseWords(string, pattern).reduce(function (prev, cur, index) { return prev + (index ? '_' : '') + cur.toLowerCase(); }, '');
1601
1657
  }
@@ -1642,11 +1698,11 @@
1642
1698
  return true;
1643
1699
  };
1644
1700
 
1645
- function conforms(source) {
1701
+ var conforms = function (source) {
1646
1702
  return function (object) {
1647
1703
  return conformsTo(object, source);
1648
1704
  };
1649
- }
1705
+ };
1650
1706
 
1651
1707
  function constant(value) {
1652
1708
  return function () {
@@ -1761,6 +1817,7 @@
1761
1817
  exports.conformsTo = conformsTo;
1762
1818
  exports.constant = constant;
1763
1819
  exports.countBy = countBy;
1820
+ exports.curry = curry;
1764
1821
  exports.debounce = debounce;
1765
1822
  exports.defaultTo = defaultTo;
1766
1823
  exports.delay = delay;
@@ -1781,11 +1838,13 @@
1781
1838
  exports.identity = identity;
1782
1839
  exports.inRange = inRange;
1783
1840
  exports.intersection = intersection;
1841
+ exports.invert = invert;
1784
1842
  exports.isArguments = isArguments;
1785
1843
  exports.isArray = isArray;
1786
1844
  exports.isArrayBuffer = isArrayBuffer;
1787
1845
  exports.isArrayLike = isArrayLike;
1788
1846
  exports.isArrayLikeObject = isArrayLikeObject;
1847
+ exports.isBigInt = isBigInt;
1789
1848
  exports.isBlob = isBlob;
1790
1849
  exports.isBoolean = isBoolean;
1791
1850
  exports.isBuffer = isBuffer;
@@ -1840,6 +1899,7 @@
1840
1899
  exports.orderBy = orderBy;
1841
1900
  exports.partial = partial;
1842
1901
  exports.partition = partition;
1902
+ exports.pascalCase = pascalCase;
1843
1903
  exports.pick = pick;
1844
1904
  exports.pickBy = pickBy;
1845
1905
  exports.random = random;