ut2 1.5.2 → 1.5.4

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 (99) hide show
  1. package/README.md +2 -2
  2. package/dist/ut2.js +103 -129
  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/gt.js +3 -4
  7. package/es/gte.js +3 -4
  8. package/es/internals/createExtremum.js +19 -12
  9. package/es/internals/createIteratee.js +2 -1
  10. package/es/internals/getTag.js +2 -23
  11. package/es/internals/getTagWithBugfix.js +6 -6
  12. package/es/internals/helpers.js +6 -4
  13. package/es/internals/isEqualDeep.js +178 -0
  14. package/es/internals/native.js +1 -3
  15. package/es/isArguments.js +3 -2
  16. package/es/isArrayBuffer.js +3 -2
  17. package/es/isBlob.js +3 -2
  18. package/es/isBoolean.js +3 -2
  19. package/es/isDate.js +3 -2
  20. package/es/isEmpty.js +4 -3
  21. package/es/isEqual.js +1 -175
  22. package/es/isError.js +3 -2
  23. package/es/isFunction.js +3 -2
  24. package/es/isMatch.js +10 -11
  25. package/es/isNumber.js +3 -2
  26. package/es/isObject.js +1 -1
  27. package/es/isObjectLike.js +1 -1
  28. package/es/isRegExp.js +3 -2
  29. package/es/isString.js +3 -2
  30. package/es/isSymbol.js +3 -2
  31. package/es/isTypedArray.js +3 -2
  32. package/es/isWeakSet.js +3 -2
  33. package/es/lowerFirst.js +3 -4
  34. package/es/lt.js +3 -4
  35. package/es/lte.js +3 -4
  36. package/es/max.js +2 -4
  37. package/es/min.js +2 -4
  38. package/es/nth.js +2 -6
  39. package/es/omit.js +1 -1
  40. package/es/omitBy.js +2 -1
  41. package/es/pickBy.js +2 -1
  42. package/es/toString.js +1 -1
  43. package/es/uniq.js +13 -5
  44. package/es/upperFirst.js +3 -4
  45. package/lib/gt.js +3 -4
  46. package/lib/gte.js +3 -4
  47. package/lib/internals/createExtremum.js +19 -12
  48. package/lib/internals/createIteratee.js +2 -1
  49. package/lib/internals/getTag.js +1 -22
  50. package/lib/internals/getTagWithBugfix.js +5 -5
  51. package/lib/internals/helpers.js +4 -2
  52. package/lib/internals/isEqualDeep.js +180 -0
  53. package/lib/internals/native.js +0 -2
  54. package/lib/isArguments.js +2 -1
  55. package/lib/isArrayBuffer.js +2 -1
  56. package/lib/isBlob.js +2 -1
  57. package/lib/isBoolean.js +2 -1
  58. package/lib/isDate.js +2 -1
  59. package/lib/isEmpty.js +4 -3
  60. package/lib/isEqual.js +1 -175
  61. package/lib/isError.js +2 -1
  62. package/lib/isFunction.js +2 -1
  63. package/lib/isMatch.js +9 -10
  64. package/lib/isNumber.js +2 -1
  65. package/lib/isObject.js +1 -1
  66. package/lib/isObjectLike.js +1 -1
  67. package/lib/isRegExp.js +2 -1
  68. package/lib/isString.js +2 -1
  69. package/lib/isSymbol.js +2 -1
  70. package/lib/isTypedArray.js +2 -1
  71. package/lib/isWeakSet.js +2 -1
  72. package/lib/lowerFirst.js +3 -4
  73. package/lib/lt.js +3 -4
  74. package/lib/lte.js +3 -4
  75. package/lib/max.js +2 -4
  76. package/lib/min.js +2 -4
  77. package/lib/nth.js +2 -6
  78. package/lib/omit.js +1 -1
  79. package/lib/omitBy.js +2 -1
  80. package/lib/pickBy.js +2 -1
  81. package/lib/toString.js +1 -1
  82. package/lib/uniq.js +13 -5
  83. package/lib/upperFirst.js +3 -4
  84. package/package.json +7 -2
  85. package/types/gt.d.ts +2 -2
  86. package/types/gte.d.ts +2 -2
  87. package/types/identity.d.ts +1 -1
  88. package/types/internals/createExtremum.d.ts +1 -1
  89. package/types/internals/createIteratee.d.ts +2 -1
  90. package/types/internals/decimalAdjust.d.ts +1 -1
  91. package/types/internals/getTag.d.ts +1 -1
  92. package/types/internals/helpers.d.ts +1 -0
  93. package/types/internals/isEqualDeep.d.ts +26 -0
  94. package/types/internals/native.d.ts +0 -2
  95. package/types/isEqual.d.ts +2 -2
  96. package/types/lowerFirst.d.ts +2 -2
  97. package/types/lt.d.ts +2 -2
  98. package/types/lte.d.ts +2 -2
  99. package/types/upperFirst.d.ts +2 -2
package/lib/lt.js CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  var comparator = require('./internals/comparator.js');
4
4
 
5
- function lt(value, other) {
6
- return comparator.createOperation(comparator.baseLt)(value, other);
7
- }
5
+ var lt = comparator.createOperation(comparator.baseLt);
6
+ var lt$1 = lt;
8
7
 
9
- module.exports = lt;
8
+ module.exports = lt$1;
package/lib/lte.js CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  var comparator = require('./internals/comparator.js');
4
4
 
5
- function lte(value, other) {
6
- return comparator.createOperation(comparator.baseLte)(value, other);
7
- }
5
+ var lte = comparator.createOperation(comparator.baseLte);
6
+ var lte$1 = lte;
8
7
 
9
- module.exports = lte;
8
+ module.exports = lte$1;
package/lib/max.js CHANGED
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var gt = require('./gt.js');
4
- var identity = require('./identity.js');
3
+ var comparator = require('./internals/comparator.js');
5
4
  var createExtremum = require('./internals/createExtremum.js');
6
5
 
7
6
  function max(array, iteratee) {
8
- if (iteratee === void 0) { iteratee = identity; }
9
- return createExtremum(array, iteratee, gt);
7
+ return createExtremum(array, comparator.baseGt, iteratee);
10
8
  }
11
9
 
12
10
  module.exports = max;
package/lib/min.js CHANGED
@@ -1,12 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var identity = require('./identity.js');
3
+ var comparator = require('./internals/comparator.js');
4
4
  var createExtremum = require('./internals/createExtremum.js');
5
- var lt = require('./lt.js');
6
5
 
7
6
  function min(array, iteratee) {
8
- if (iteratee === void 0) { iteratee = identity; }
9
- return createExtremum(array, iteratee, lt);
7
+ return createExtremum(array, comparator.baseLt, iteratee);
10
8
  }
11
9
 
12
10
  module.exports = min;
package/lib/nth.js CHANGED
@@ -1,6 +1,5 @@
1
1
  'use strict';
2
2
 
3
- var native = require('./internals/native.js');
4
3
  var isArrayLike = require('./isArrayLike.js');
5
4
 
6
5
  function nth(array, n) {
@@ -8,11 +7,8 @@ function nth(array, n) {
8
7
  if (!isArrayLike(array)) {
9
8
  return undefined;
10
9
  }
11
- if (typeof native.arrayProtoAt === 'function') {
12
- return native.arrayProtoAt.call(array, n);
13
- }
14
- var index = n < 0 ? n + array.length : n;
15
- return array[index];
10
+ n += n < 0 ? array.length : 0;
11
+ return array[n];
16
12
  }
17
13
 
18
14
  module.exports = nth;
package/lib/omit.js CHANGED
@@ -9,7 +9,7 @@ function omit(object, fields) {
9
9
  var fieldArr = castArray(fields);
10
10
  var result = {};
11
11
  keys.forEach(function (key) {
12
- if (!fieldArr.includes(key)) {
12
+ if (fieldArr.indexOf(key) === -1) {
13
13
  result[key] = object[key];
14
14
  }
15
15
  });
package/lib/omitBy.js CHANGED
@@ -1,10 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ var helpers = require('./internals/helpers.js');
3
4
  var negate = require('./negate.js');
4
5
  var pickBy = require('./pickBy.js');
5
6
 
6
7
  function omitBy(object, predicate) {
7
- if (predicate === void 0) { predicate = function () { return false; }; }
8
+ if (predicate === void 0) { predicate = helpers.stubFlase; }
8
9
  return pickBy(object, negate(predicate));
9
10
  }
10
11
 
package/lib/pickBy.js CHANGED
@@ -1,9 +1,10 @@
1
1
  'use strict';
2
2
 
3
3
  var allKeysIn = require('./allKeysIn.js');
4
+ var helpers = require('./internals/helpers.js');
4
5
 
5
6
  function pickBy(object, predicate) {
6
- if (predicate === void 0) { predicate = function () { return false; }; }
7
+ if (predicate === void 0) { predicate = helpers.stubFlase; }
7
8
  var result = {};
8
9
  if (object === null) {
9
10
  return result;
package/lib/toString.js CHANGED
@@ -16,7 +16,7 @@ function baseToString(value) {
16
16
  return symbolToString ? symbolToString.call(value) : '';
17
17
  }
18
18
  var result = '' + value;
19
- return result == '0' && 1 / value === -Infinity ? '-0' : result;
19
+ return result === '0' && 1 / value === -Infinity ? '-0' : result;
20
20
  }
21
21
  function toString(value) {
22
22
  return value == null ? '' : baseToString(value);
package/lib/uniq.js CHANGED
@@ -3,17 +3,25 @@
3
3
  var eq = require('./eq.js');
4
4
  var createIteratee = require('./internals/createIteratee.js');
5
5
  var isArray = require('./isArray.js');
6
+ var isUndefined = require('./isUndefined.js');
6
7
 
7
8
  function uniq(array, iteratee, strickCheck) {
8
9
  if (strickCheck === void 0) { strickCheck = false; }
9
10
  if (!isArray(array)) {
10
11
  return [];
11
12
  }
12
- var internalIteratee = createIteratee(iteratee);
13
- return array.filter(function (value, index, arr) {
14
- var current = internalIteratee(value);
15
- return arr.findIndex(function (item) { return eq(internalIteratee(item), current, strickCheck); }) === index;
16
- });
13
+ if (isUndefined(iteratee)) {
14
+ return array.filter(function (value, index, arr) {
15
+ return arr.findIndex(function (item) { return eq(item, value, strickCheck); }) === index;
16
+ });
17
+ }
18
+ else {
19
+ var internalIteratee_1 = createIteratee(iteratee);
20
+ return array.filter(function (value, index, arr) {
21
+ var current = internalIteratee_1(value);
22
+ return arr.findIndex(function (item) { return eq(internalIteratee_1(item), current, strickCheck); }) === index;
23
+ });
24
+ }
17
25
  }
18
26
 
19
27
  module.exports = uniq;
package/lib/upperFirst.js CHANGED
@@ -2,8 +2,7 @@
2
2
 
3
3
  var createCaseFirst = require('./internals/createCaseFirst.js');
4
4
 
5
- function upperFirst(string) {
6
- return createCaseFirst('toUpperCase')(string);
7
- }
5
+ var upperFirst = createCaseFirst('toUpperCase');
6
+ var upperFirst$1 = upperFirst;
8
7
 
9
- module.exports = upperFirst;
8
+ module.exports = upperFirst$1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ut2",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "author": "caijf",
5
5
  "license": "MIT",
6
6
  "main": "lib/index.js",
@@ -12,6 +12,7 @@
12
12
  "test": "jest",
13
13
  "test:coverage": "jest --coverage",
14
14
  "test:coverage:local": "cross-env COVERAGE_LOCAL=1 jest --coverage --detectOpenHandles && open ./coverage/lcov-report/index.html",
15
+ "benchmark": "node benchmark/node.js",
15
16
  "build": "npm run build:module && npm run build:umd && npm run build:types",
16
17
  "build:module": "rm -rf es && rm -rf lib && rollup -c rollup.module.config.mjs",
17
18
  "build:umd": "rm -rf dist && rollup -c rollup.umd.config.mjs",
@@ -71,20 +72,24 @@
71
72
  "@types/node": "^20.6.2",
72
73
  "@typescript-eslint/eslint-plugin": "^5.62.0",
73
74
  "@typescript-eslint/parser": "^5.62.0",
75
+ "benchmark": "^2.1.4",
74
76
  "cross-env": "^7.0.3",
75
77
  "cz-conventional-changelog": "^3.3.0",
78
+ "dayjs": "^1.11.10",
76
79
  "docdash": "^2.0.2",
77
80
  "eslint": "^8.48.0",
81
+ "husky": "^8.0.0",
78
82
  "jest": "^29.6.4",
79
83
  "jest-environment-jsdom": "^29.6.4",
80
84
  "jsdoc": "^4.0.2",
81
85
  "lint-staged": "^13.3.0",
86
+ "lodash": "^4.17.21",
82
87
  "prettier": "^2.8.8",
83
88
  "rollup": "^3.28.1",
84
89
  "ts-jest": "^29.1.1",
85
90
  "tslib": "^2.6.2",
86
91
  "typescript": "^5.2.2",
87
- "husky": "^8.0.0"
92
+ "underscore": "^1.13.6"
88
93
  },
89
94
  "engines": {
90
95
  "node": ">=10"
package/types/gt.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 检查 `value` 是否大于 `other` 。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:Util.gt
6
6
  * @since 1.0.0
7
7
  * @param {*} value 要比较的值。
@@ -16,5 +16,5 @@
16
16
  * gt(3, 1); // true
17
17
  *
18
18
  */
19
- declare function gt(value: any, other: any): boolean;
19
+ declare const gt: (value: any, other: any) => boolean;
20
20
  export default gt;
package/types/gte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 检查 `value` 是否大于或等于 `other` 。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:Util.gte
6
6
  * @since 1.0.0
7
7
  * @param {*} value 要比较的值。
@@ -16,5 +16,5 @@
16
16
  * gte(3, 1); // true
17
17
  *
18
18
  */
19
- declare function gte(value: any, other: any): boolean;
19
+ declare const gte: (value: any, other: any) => boolean;
20
20
  export default gte;
@@ -10,7 +10,7 @@
10
10
  *
11
11
  * const obj = { a: 1, b: 2 };
12
12
  *
13
- * console.log(identity(obj, 1) === obj); // true
13
+ * console.log(identity(obj) === obj); // true
14
14
  *
15
15
  */
16
16
  declare function identity<T>(value?: T): T;
@@ -1,2 +1,2 @@
1
- declare function createExtremum<T, F extends (item: T) => any, K extends keyof T>(array: T[], iteratee: F | K, comparator: (value: any, other: any) => boolean): T | undefined;
1
+ declare function createExtremum<T, F extends (item: T) => any, K extends keyof T>(array: T[], comparator: (value: any, other: any) => boolean, iteratee?: F | K): T | undefined;
2
2
  export default createExtremum;
@@ -1,3 +1,4 @@
1
+ import identity from '../identity';
1
2
  /**
2
3
  * 创建迭代函数。
3
4
  *
@@ -5,5 +6,5 @@
5
6
  * @param {Function} iteratee 迭代函数或对象属性。
6
7
  * @returns {Function} 如果参数为函数,返回该函数,否则包装一个返回对象属性的函数。
7
8
  */
8
- declare function createIteratee<T, F extends (value: T) => any, K extends keyof T>(iteratee?: F | K): F | ((value: any) => any);
9
+ declare function createIteratee<T, F extends (value: T) => any, K extends keyof T>(iteratee?: F | K): typeof identity | F;
9
10
  export default createIteratee;
@@ -4,7 +4,7 @@
4
4
  * @private
5
5
  * @param {'floor' | 'ceil' | 'round'} type 调整的类型。
6
6
  * @param {number} value 要调整的数字。
7
- * @param {number} precision 指数(调整基数的10个对数)。
7
+ * @param {number} [precision=0] 指数(调整基数的10个对数)。
8
8
  * @returns {number} 调整后的数字。
9
9
  */
10
10
  declare function decimalAdjust(type: 'floor' | 'ceil' | 'round', value: number, precision?: number): number;
@@ -1,5 +1,5 @@
1
1
  /**
2
- * 获取值的 `Object.prototype.toString` ,忽略 `Symbol.toStringTag` 影响。
2
+ * 获取值的 `Object.prototype.toString`
3
3
  *
4
4
  * @private
5
5
  * @param value 要查询的值
@@ -8,3 +8,4 @@ export declare const VERSION: string;
8
8
  export declare const supportedArgumentsType: boolean;
9
9
  export declare const FUNC_ERROR_TEXT = "Expected a function";
10
10
  export declare function toSource(func: any): string;
11
+ export declare const stubFlase: () => boolean;
@@ -0,0 +1,26 @@
1
+ type Customizer = (objValue: any, othValue: any, key?: number | string | symbol, object?: any, other?: any, valueStack?: any[], otherStack?: any[]) => void | boolean;
2
+ /**
3
+ *
4
+ * 深度比较两个值是否相等。
5
+ *
6
+ * 支持比较 `boolean` `number` `string` `symbol` `array` `array buffer` `date` `error` `map` `object` `regexp` `set` `typed array` 类型。对象只比较自身的属性,不包括继承和不可枚举的属性。
7
+ *
8
+ * 如果 `strictCheck=true` , 以下值不相等:
9
+ *
10
+ * 1. `0` `-0`
11
+ * 2. `typeof` 不同类型,如 `1` `Object(1)`
12
+ * 3. 无效日期对象,如 `new Date('')` `new Date('abc')`
13
+ *
14
+ * @static
15
+ * @alias module:Language.isEqual
16
+ * @since 1.3.0
17
+ * @param {*} value 要比较的值。
18
+ * @param {*} other 另一个要比较的值。
19
+ * @param {Function} [customizer] 自定义比较。
20
+ * @param {boolean} [strictCheck=false] 严格比较,默认 `false` 。
21
+ * @param {*[]} [valueStack] 值的堆栈。
22
+ * @param {*[]} [otherStack] 另一个值的堆栈。
23
+ * @returns {boolean} 如果两个值相等,返回 `true` ,否则返回 `false` 。
24
+ */
25
+ declare function isEqualDeep(value: any, other: any, customizer?: Customizer, strictCheck?: boolean, valueStack?: any[], otherStack?: any[]): boolean;
26
+ export default isEqualDeep;
@@ -11,10 +11,8 @@ export declare const objectKeys: {
11
11
  export declare const functionProto: Function;
12
12
  export declare const functionProtoToString: () => string;
13
13
  export declare const symbolProto: Symbol | undefined;
14
- export declare const symbolToStringTag: typeof Symbol.toStringTag | undefined;
15
14
  export declare const arrayProto: any[];
16
15
  export declare const arrayProtoSlice: (start?: number | undefined, end?: number | undefined) => any[];
17
- export declare const arrayProtoAt: (index: number) => any;
18
16
  export declare const mathMin: (...values: number[]) => number;
19
17
  export declare const mathMax: (...values: number[]) => number;
20
18
  export declare const mathRandom: () => number;
@@ -1,4 +1,4 @@
1
- type Customizer = (objValue: any, othValue: any, key?: number | string | symbol, object?: any, other?: any, valueStack?: any[], otherStack?: any[]) => void | boolean;
1
+ import isEqualDeep from './internals/isEqualDeep';
2
2
  /**
3
3
  * 深度比较两个值是否相等。
4
4
  *
@@ -40,5 +40,5 @@ type Customizer = (objValue: any, othValue: any, key?: number | string | symbol,
40
40
  * isEqual({foo: 'a'}, {foo: 'b'}, customizer); // true
41
41
  *
42
42
  */
43
- declare function isEqual(value: any, other: any, customizer?: Customizer, strictCheck?: boolean): boolean;
43
+ declare function isEqual(value: any, other: any, customizer?: Parameters<typeof isEqualDeep>[2], strictCheck?: boolean): boolean;
44
44
  export default isEqual;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 转换字符串第一个字符为小写。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:String.lowerFirst
6
6
  * @since 1.0.0
7
7
  * @param {string} string 要转换的字符串。
@@ -13,5 +13,5 @@
13
13
  * lowerFirst('BAR'); // 'bAR'
14
14
  *
15
15
  */
16
- declare function lowerFirst(string: string): string;
16
+ declare const lowerFirst: (string: string) => string;
17
17
  export default lowerFirst;
package/types/lt.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 检查 `value` 是否小于 `other` 。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:Util.lt
6
6
  * @since 1.0.0
7
7
  * @param {*} value 要比较的值。
@@ -16,5 +16,5 @@
16
16
  * lt(3, 1); // false
17
17
  *
18
18
  */
19
- declare function lt(value: any, other: any): boolean;
19
+ declare const lt: (value: any, other: any) => boolean;
20
20
  export default lt;
package/types/lte.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 检查 `value` 是否小于或等于 `other` 。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:Util.lte
6
6
  * @since 1.0.0
7
7
  * @param {*} value 要比较的值。
@@ -16,5 +16,5 @@
16
16
  * lte(3, 1); // false
17
17
  *
18
18
  */
19
- declare function lte(value: any, other: any): boolean;
19
+ declare const lte: (value: any, other: any) => boolean;
20
20
  export default lte;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * 转换字符串第一个字符为大写。
3
3
  *
4
- * @static
4
+ * @function
5
5
  * @alias module:String.upperFirst
6
6
  * @since 1.0.0
7
7
  * @param {string} string 要转换的字符串。
@@ -13,5 +13,5 @@
13
13
  * upperFirst('BAR'); // 'BAR'
14
14
  *
15
15
  */
16
- declare function upperFirst(string: string): string;
16
+ declare const upperFirst: (string: string) => string;
17
17
  export default upperFirst;