ut2 1.1.3 → 1.2.1

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 (67) hide show
  1. package/README.md +2 -0
  2. package/dist/ut2.js +55 -37
  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/difference.js +3 -2
  7. package/es/eq.js +7 -1
  8. package/es/index.js +2 -0
  9. package/es/internals/helpers.js +3 -2
  10. package/es/internals/sameValue.js +10 -0
  11. package/es/intersection.js +3 -3
  12. package/es/isDataView.js +7 -0
  13. package/es/isPlainObject.js +1 -3
  14. package/es/merge.js +1 -3
  15. package/es/once.js +7 -0
  16. package/es/orderBy.js +2 -6
  17. package/es/union.js +3 -2
  18. package/es/uniq.js +3 -2
  19. package/es/xor.js +6 -5
  20. package/lib/difference.js +3 -2
  21. package/lib/eq.js +7 -1
  22. package/lib/index.js +4 -0
  23. package/lib/internals/helpers.js +2 -1
  24. package/lib/internals/sameValue.js +12 -0
  25. package/lib/intersection.js +3 -3
  26. package/lib/isDataView.js +9 -0
  27. package/lib/isPlainObject.js +1 -3
  28. package/lib/merge.js +1 -3
  29. package/lib/once.js +9 -0
  30. package/lib/orderBy.js +2 -6
  31. package/lib/union.js +3 -2
  32. package/lib/uniq.js +3 -2
  33. package/lib/xor.js +6 -5
  34. package/package.json +1 -1
  35. package/types/before.d.ts +0 -7
  36. package/types/countBy.d.ts +1 -1
  37. package/types/difference.d.ts +9 -2
  38. package/types/eq.d.ts +8 -2
  39. package/types/groupBy.d.ts +1 -1
  40. package/types/index.d.ts +2 -0
  41. package/types/internals/decimalAdjust.d.ts +3 -3
  42. package/types/internals/helpers.d.ts +1 -0
  43. package/types/internals/isType.d.ts +1 -1
  44. package/types/internals/sameValue.d.ts +12 -0
  45. package/types/internals/splitCaseWords.d.ts +1 -1
  46. package/types/intersection.d.ts +9 -2
  47. package/types/isArrayLikeObject.d.ts +4 -4
  48. package/types/isBuffer.d.ts +1 -1
  49. package/types/isDataView.d.ts +15 -0
  50. package/types/isPlainObject.d.ts +3 -3
  51. package/types/isTypedArray.d.ts +2 -2
  52. package/types/kebabCase.d.ts +1 -1
  53. package/types/keyBy.d.ts +1 -1
  54. package/types/lowerCase.d.ts +1 -1
  55. package/types/merge.d.ts +2 -2
  56. package/types/omit.d.ts +1 -1
  57. package/types/once.d.ts +24 -0
  58. package/types/orderBy.d.ts +2 -2
  59. package/types/partition.d.ts +1 -1
  60. package/types/pick.d.ts +1 -1
  61. package/types/snakeCase.d.ts +1 -1
  62. package/types/toFinite.d.ts +8 -8
  63. package/types/union.d.ts +11 -4
  64. package/types/uniq.d.ts +10 -3
  65. package/types/upperCase.d.ts +1 -1
  66. package/types/words.d.ts +1 -1
  67. package/types/xor.d.ts +13 -6
@@ -1,14 +1,17 @@
1
1
  /**
2
- * 创建唯一值的数组,该数组包含 2 个数组参数都包含的元素(交集)。使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
2
+ * 创建唯一值的数组,该数组包含 2 个数组参数都包含的元素(交集)。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
3
3
  *
4
4
  * `iteratee` 调用时会传入 1 个参数 `value` 。
5
5
  *
6
+ * 默认使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果 `strictCheck=true` 将使用 [`SameValue`](https://tc39.es/ecma262/#sec-samevalue) 做等值比较。
7
+ *
6
8
  * @static
7
9
  * @alias module:Array.intersection
8
10
  * @since 1.0.0
9
11
  * @param {Array} array 要检查的数组。
10
12
  * @param {Array} other 另一个要检查的数组。
11
13
  * @param {Function | string} [iteratee] 迭代函数,调用每个元素。
14
+ * @param {boolean} [strictCheck=false] 严格比较,区分 `+0` `-0`。
12
15
  * @returns {Array} 包含所有传入数组交集元素的新数组。
13
16
  * @example
14
17
  *
@@ -21,6 +24,10 @@
21
24
  * // 迭代函数可以直接写入属性。
22
25
  * intersection([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], 'x'); // [{x: 1}]
23
26
  *
27
+ * intersection([-0, 0], [0]); // [-0]
28
+ *
29
+ * intersection([-0, 0], [0], undefined, true); // [0]
30
+ *
24
31
  */
25
- declare function intersection<T, F extends (value: T) => any, K extends keyof T>(array: T[], other: T[], iteratee?: F | K): T[];
32
+ declare function intersection<T, F extends (value: T) => any, K extends keyof T>(array: T[], other: T[], iteratee?: F | K, strictCheck?: boolean): T[];
26
33
  export default intersection;
@@ -8,13 +8,13 @@
8
8
  * @returns {boolean} 如果值为类数组对象,返回 `true` ,否则返回 `false` 。
9
9
  * @example
10
10
  *
11
- * isArrayLike([1, 2, 3]); // true
11
+ * isArrayLikeObject([1, 2, 3]); // true
12
12
  *
13
- * isArrayLike(document.body.children); // true
13
+ * isArrayLikeObject(document.body.children); // true
14
14
  *
15
- * isArrayLike('abc'); // false
15
+ * isArrayLikeObject('abc'); // false
16
16
  *
17
- * isArrayLike(()=>{}); // false
17
+ * isArrayLikeObject(()=>{}); // false
18
18
  *
19
19
  */
20
20
  declare function isArrayLikeObject(value: any): boolean;
@@ -11,7 +11,7 @@
11
11
  * @returns {boolean} 如果值为 `buffer` ,返回 `true` ,否则返回 `false` 。
12
12
  * @example
13
13
  *
14
- * isBuffer(new Blob(['a'])); // true
14
+ * isBuffer(new Buffer(2)); // true
15
15
  *
16
16
  * isBuffer({}); // false
17
17
  *
@@ -0,0 +1,15 @@
1
+ /**
2
+ * 检查值是否为 `DataView` 对象。
3
+ *
4
+ * @static
5
+ * @alias module:Type.isDataView
6
+ * @since 1.2.0
7
+ * @param {*} value 要检查的值。
8
+ * @returns {boolean} 如果值为 `DataView` 对象,返回 `true` ,否则返回 `false` 。
9
+ * @example
10
+ *
11
+ * isDataView(new DataView(new ArrayBuffer(8))); // true
12
+ *
13
+ */
14
+ declare function isDataView(value: any): boolean;
15
+ export default isDataView;
@@ -14,11 +14,11 @@
14
14
  *
15
15
  * isPlainObject(new Foo); // false
16
16
  *
17
- * isObject([1,2,3]); // false
17
+ * isPlainObject([1,2,3]); // false
18
18
  *
19
- * isObject({ a: 1, b: 2 }); // true
19
+ * isPlainObject({ a: 1, b: 2 }); // true
20
20
  *
21
- * isObject(Object.create(null)); // true
21
+ * isPlainObject(Object.create(null)); // true
22
22
  *
23
23
  */
24
24
  declare function isPlainObject(value: any): boolean;
@@ -9,9 +9,9 @@
9
9
  * @returns {boolean} 如果值为类型化数组,返回 `true` ,否则返回 `false` 。
10
10
  * @example
11
11
  *
12
- * ut2.isTypedArray(new Uint8Array); // true
12
+ * isTypedArray(new Uint8Array); // true
13
13
  *
14
- * ut2.isTypedArray([]); // false
14
+ * isTypedArray([]); // false
15
15
  *
16
16
  */
17
17
  declare function isTypedArray(value: any): boolean;
@@ -6,7 +6,7 @@
6
6
  * @since 1.0.0
7
7
  * @see {@link https://en.wikipedia.org/wiki/Letter_case#Special_case_styles | kebab case}
8
8
  * @param {string} string 要转换的字符串。
9
- * @param {RegExp|string} [pattern] 拆分词组的匹配模式。
9
+ * @param {RegExp | string} [pattern] 拆分词组的匹配模式。
10
10
  * @returns {string} 转换后的字符串。
11
11
  * @example
12
12
  *
package/types/keyBy.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * @alias module:Collection.keyBy
8
8
  * @since 1.0.0
9
9
  * @param {Array} collection 一个用来迭代的集合。
10
- * @param {Function|string} [iteratee] 迭代函数,用来转换键。
10
+ * @param {Function | string} [iteratee] 迭代函数,用来转换键。
11
11
  * @returns {Object} 组成聚合对象。
12
12
  * @example
13
13
  *
@@ -5,7 +5,7 @@
5
5
  * @alias module:String.lowerCase
6
6
  * @since 1.0.0
7
7
  * @param {string} string 要转换的字符串。
8
- * @param {RegExp|string} [pattern] 拆分词组的匹配模式。
8
+ * @param {RegExp | string} [pattern] 拆分词组的匹配模式。
9
9
  * @returns {string} 小写字符串。
10
10
  * @example
11
11
  *
package/types/merge.d.ts CHANGED
@@ -7,8 +7,8 @@ type Customizer = (objValue: any, srcValue: any, key: string | symbol, object: a
7
7
  * @static
8
8
  * @alias module:Object.merge
9
9
  * @since 1.0.0
10
- * @param {Object|Array} object 目标对象。
11
- * @param {Object|Array} source 来源对象。
10
+ * @param {Object | Array} object 目标对象。
11
+ * @param {Object | Array} source 来源对象。
12
12
  * @param {Function} [customizer] 自定义赋值函数。
13
13
  * @returns {Object} 目标对象。
14
14
  * @example
package/types/omit.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * @alias module:Object.omit
6
6
  * @since 1.0.0
7
7
  * @param {Object} object 来源对象。
8
- * @param {string|string[]} [fields] 要被忽略的属性。
8
+ * @param {string | string[]} [fields] 要被忽略的属性。
9
9
  * @returns {Object} 新对象。
10
10
  * @example
11
11
  *
@@ -0,0 +1,24 @@
1
+ /**
2
+ * 创建一个只能调用 `func` 一次的函数。重复调用将返回第一次调用 `func` 的结果。
3
+ *
4
+ * @static
5
+ * @alias module:Function.once
6
+ * @since 1.2.0
7
+ * @requires module:Function.before
8
+ * @param {Function} func 限制执行的函数。
9
+ * @returns {Function} 新的限定函数。
10
+ * @example
11
+ *
12
+ * let count = 0;
13
+ *
14
+ * const increment = _.once(()=>{
15
+ * return ++count;
16
+ * });
17
+ *
18
+ * increment(); // 1
19
+ * increment(); // 1
20
+ * increment(); // 1
21
+ *
22
+ */
23
+ declare function once<T extends (...args: any[]) => any>(func: T): T;
24
+ export default once;
@@ -11,8 +11,8 @@ import { Order } from './internals/compare';
11
11
  * @since 1.0.0
12
12
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort | sort}
13
13
  * @param {Array} collection 一个用来迭代的集合。
14
- * @param {Function|string|Array} [iteratees] 排序的迭代函数。
15
- * @param {'asc'|'desc'|Array} [orders] 迭代函数的排序顺序。
14
+ * @param {Function | string | Array} [iteratees] 排序的迭代函数。
15
+ * @param {'asc' | 'desc' | Array} [orders] 迭代函数的排序顺序。
16
16
  * @returns {Array} 排序后的新数组。
17
17
  * @example
18
18
  *
@@ -7,7 +7,7 @@
7
7
  * @alias module:Collection.partition
8
8
  * @since 1.0.0
9
9
  * @param {Array} collection 一个用来迭代的集合。
10
- * @param {Function|string} [predicate=identity] 每次迭代调用的断言函数。
10
+ * @param {Function | string} [predicate=identity] 每次迭代调用的断言函数。
11
11
  * @returns {Array} 分组后的数组。
12
12
  * @example
13
13
  *
package/types/pick.d.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  * @alias module:Object.pick
8
8
  * @since 1.0.0
9
9
  * @param {Object} object 来源对象。
10
- * @param {string|string[]} [fields] 选中的属性。
10
+ * @param {string | string[]} [fields] 选中的属性。
11
11
  * @returns {Object} 新对象。
12
12
  * @example
13
13
  *
@@ -6,7 +6,7 @@
6
6
  * @since 1.0.0
7
7
  * @see {@link https://en.wikipedia.org/wiki/Snake_case | snake case}
8
8
  * @param {string} string 要转换的字符串。
9
- * @param {RegExp|string} [pattern] 拆分词组的匹配模式。
9
+ * @param {RegExp | string} [pattern] 拆分词组的匹配模式。
10
10
  * @returns {string} 转换后的字符串。
11
11
  * @example
12
12
  *
@@ -8,21 +8,21 @@
8
8
  * @returns {number} 转换后的数字。
9
9
  * @example
10
10
  *
11
- * toSafeInteger(3.2); // 3.2
11
+ * toFinite(3.2); // 3.2
12
12
  *
13
- * toSafeInteger('3.2'); // 3.2
13
+ * toFinite('3.2'); // 3.2
14
14
  *
15
- * toSafeInteger(-0); // -0
15
+ * toFinite(-0); // -0
16
16
  *
17
- * toSafeInteger('-0'); // -0
17
+ * toFinite('-0'); // -0
18
18
  *
19
- * toSafeInteger('0'); // 0
19
+ * toFinite('0'); // 0
20
20
  *
21
- * toSafeInteger(NaN); // 0
21
+ * toFinite(NaN); // 0
22
22
  *
23
- * toSafeInteger(Infinity); // 1.7976931348623157e+308
23
+ * toFinite(Infinity); // 1.7976931348623157e+308
24
24
  *
25
- * toSafeInteger(-Infinity); // -1.7976931348623157e+308
25
+ * toFinite(-Infinity); // -1.7976931348623157e+308
26
26
  *
27
27
  */
28
28
  declare function toFinite(value: any): number;
package/types/union.d.ts CHANGED
@@ -1,14 +1,17 @@
1
1
  /**
2
- * 创建一个按顺序排列的唯一值的数组(并集)。使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。与 [`uniq`](#.uniq) 相似。
2
+ * 创建一个按顺序排列的唯一值的数组(并集)。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。与 [`uniq`](#.uniq) 相似。
3
3
  *
4
4
  * `iteratee` 调用时会传入 1 个参数 `value` 。
5
5
  *
6
+ * 默认使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果 `strictCheck=true` 将使用 [`SameValue`](https://tc39.es/ecma262/#sec-samevalue) 做等值比较。
7
+ *
6
8
  * @static
7
9
  * @alias module:Array.union
8
10
  * @since 1.0.0
9
11
  * @param {Array} array 要检查的数组。
10
12
  * @param {Array} [other=[]] 另一个要检查的数组。
11
13
  * @param {Function | string} [iteratee] 迭代函数,调用每个元素。
14
+ * @param {boolean} [strictCheck=false] 严格比较,区分 `+0` `-0`。
12
15
  * @returns {Array} 新的联合数组。
13
16
  * @example
14
17
  *
@@ -16,11 +19,15 @@
16
19
  *
17
20
  * union([2.1], [1.2, 2.3], Math.floor); // [2.1, 1.2]
18
21
  *
19
- * intersection([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], item=>item.x); // [{x: 1}, {x: 2}]
22
+ * union([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], item=>item.x); // [{x: 1}, {x: 2}]
20
23
  *
21
24
  * // 迭代函数可以直接写入属性。
22
- * intersection([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], 'x'); // [{x: 1}, {x: 2}]
25
+ * union([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], 'x'); // [{x: 1}, {x: 2}]
26
+ *
27
+ * union([-0, 0], [-0]); // [-0]
28
+ *
29
+ * union([-0, 0], [-0], undefined, true); // [-0, 0]
23
30
  *
24
31
  */
25
- declare function union<T, F extends (value: T) => any, K extends keyof T>(array: T[], other?: T[], iteratee?: F | K): T[];
32
+ declare function union<T, F extends (value: T) => any, K extends keyof T>(array: T[], other?: T[], iteratee?: F | K, strickCheck?: boolean): T[];
26
33
  export default union;
package/types/uniq.d.ts CHANGED
@@ -1,13 +1,16 @@
1
1
  /**
2
- * 创建一个去重后的数组副本。使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。只有第一次出现的元素才会被保留。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
2
+ * 创建一个去重后的数组副本。只有第一次出现的元素才会被保留。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
3
3
  *
4
4
  * `iteratee` 调用时会传入 1 个参数 `value` 。
5
5
  *
6
+ * 默认使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果 `strictCheck=true` 将使用 [`SameValue`](https://tc39.es/ecma262/#sec-samevalue) 做等值比较。
7
+ *
6
8
  * @static
7
9
  * @alias module:Array.uniq
8
10
  * @since 1.0.0
9
- * @param {Array} array 要检查的数组。
11
+ * @param {Array} array 要检查的数组。
10
12
  * @param {Function | string} [iteratee] 迭代函数,调用每个元素。
13
+ * @param {boolean} [strictCheck=false] 严格比较,区分 `+0` `-0`。
11
14
  * @returns {Array} 去重后的新数组。
12
15
  * @example
13
16
  *
@@ -20,6 +23,10 @@
20
23
  * // 迭代函数可以直接写入属性。
21
24
  * uniq([{x: 1}, {x: 2}, {x: 1}], 'x'); // [{x: 1}, {x: 2}]
22
25
  *
26
+ * uniq([-0, 0]); // [-0]
27
+ *
28
+ * uniq([-0, 0], undefined, true); // [-0, 0]
29
+ *
23
30
  */
24
- declare function uniq<T, F extends (value: T) => any, K extends keyof T>(array: T[], iteratee?: F | K): T[];
31
+ declare function uniq<T, F extends (value: T) => any, K extends keyof T>(array: T[], iteratee?: F | K, strickCheck?: boolean): T[];
25
32
  export default uniq;
@@ -5,7 +5,7 @@
5
5
  * @alias module:String.upperCase
6
6
  * @since 1.0.0
7
7
  * @param {string} string 要转换的字符串。
8
- * @param {RegExp|string} [pattern] 拆分词组的匹配模式。
8
+ * @param {RegExp | string} [pattern] 拆分词组的匹配模式。
9
9
  * @returns {string} 大写字符串。
10
10
  * @example
11
11
  *
package/types/words.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * @since 1.0.0
7
7
  * @see {@link https://zh.wikipedia.org/wiki/ASCII | ASCII}
8
8
  * @param {string} string 要拆分的字符串。
9
- * @param {RegExp|string} [pattern=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g] 匹配模式。
9
+ * @param {RegExp | string} [pattern=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g] 匹配模式。
10
10
  * @returns {string[]} 拆分后的数组。
11
11
  * @example
12
12
  *
package/types/xor.d.ts CHANGED
@@ -1,26 +1,33 @@
1
1
  /**
2
- * 创建一个唯一值的数组(并集-交集),该数组包含 2 个数组参数中不相同的元素。使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
2
+ * 创建一个唯一值的数组(并集-交集),该数组包含 2 个数组参数中不相同的元素。如果传入迭代函数,会调用数组的每个元素以产生唯一性计算的标准。
3
3
  *
4
4
  * `iteratee` 调用时会传入 1 个参数 `value` 。
5
5
  *
6
+ * 默认使用了 [`SameValueZero`](https://tc39.es/ecma262/#sec-samevaluezero) 做等值比较。如果 `strictCheck=true` 将使用 [`SameValue`](https://tc39.es/ecma262/#sec-samevalue) 做等值比较。
7
+ *
6
8
  * @static
7
9
  * @alias module:Array.xor
8
10
  * @since 1.0.0
9
11
  * @param {Array} array 要检查的数组。
10
12
  * @param {Array} [other=[]] 另一个要检查的数组。
11
13
  * @param {Function | string} [iteratee] 迭代函数,调用每个元素。
14
+ * @param {boolean} [strictCheck=false] 严格比较,区分 `+0` `-0`。
12
15
  * @returns {Array} 过滤值后的新数组。
13
16
  * @example
14
17
  *
15
- * intersection([2, 1, 1], [4, 2]); // [1, 4]
18
+ * xor([2, 1, 1], [4, 2]); // [1, 4]
16
19
  *
17
- * intersection([2.1, 1.2], [4.3, 2.4], Math.floor); // [1.2, 4.3]
20
+ * xor([2.1, 1.2], [4.3, 2.4], Math.floor); // [1.2, 4.3]
18
21
  *
19
- * intersection([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], item=>item.x); // [{x: 2}]
22
+ * xor([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], item=>item.x); // [{x: 2}]
20
23
  *
21
24
  * // 迭代函数可以直接写入属性。
22
- * intersection([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], 'x'); // [{x: 2}]
25
+ * xor([{x: 1}, {x: 1}, {x: 2}, {x: 2}], [{x: 1}], 'x'); // [{x: 2}]
26
+ *
27
+ * xor([-0, 0],[0]); // []
28
+ *
29
+ * xor([-0, 0],[0], undefined, true); // [-0]
23
30
  *
24
31
  */
25
- declare function xor<T, F extends (value: T) => any, K extends keyof T>(array: T[], other?: T[], iteratee?: F | K): T[];
32
+ declare function xor<T, F extends (value: T) => any, K extends keyof T>(array: T[], other?: T[], iteratee?: F | K, strickCheck?: boolean): T[];
26
33
  export default xor;