ut2 1.7.2 → 1.8.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 (82) hide show
  1. package/README.md +6 -2
  2. package/dist/ut2.js +127 -64
  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/before.js +2 -1
  7. package/es/clamp.js +7 -6
  8. package/es/conforms.js +4 -3
  9. package/es/conformsTo.js +2 -1
  10. package/es/curry.js +32 -0
  11. package/es/index.js +4 -0
  12. package/es/internals/baseDebounce.js +15 -14
  13. package/es/internals/createExtremum.js +2 -1
  14. package/es/internals/getTagWithBugfix.js +7 -7
  15. package/es/internals/helpers.js +3 -2
  16. package/es/internals/isEqualDeep.js +4 -4
  17. package/es/internals/native.js +10 -6
  18. package/es/internals/nodeUtil.js +4 -2
  19. package/es/invert.js +22 -0
  20. package/es/isBigInt.js +8 -0
  21. package/es/isBlob.js +2 -2
  22. package/es/isEqual.js +2 -1
  23. package/es/isMatch.js +5 -5
  24. package/es/isUndefined.js +3 -1
  25. package/es/merge.js +4 -3
  26. package/es/nth.js +2 -1
  27. package/es/omit.js +4 -3
  28. package/es/orderBy.js +3 -2
  29. package/es/partial.js +1 -1
  30. package/es/pascalCase.js +11 -0
  31. package/es/pick.js +4 -3
  32. package/es/toString.js +2 -2
  33. package/lib/before.js +2 -1
  34. package/lib/clamp.js +7 -6
  35. package/lib/conforms.js +4 -3
  36. package/lib/conformsTo.js +2 -1
  37. package/lib/curry.js +34 -0
  38. package/lib/index.js +8 -0
  39. package/lib/internals/baseDebounce.js +15 -14
  40. package/lib/internals/createExtremum.js +2 -1
  41. package/lib/internals/getTagWithBugfix.js +6 -6
  42. package/lib/internals/helpers.js +2 -1
  43. package/lib/internals/isEqualDeep.js +3 -3
  44. package/lib/internals/native.js +9 -5
  45. package/lib/internals/nodeUtil.js +4 -2
  46. package/lib/invert.js +24 -0
  47. package/lib/isBigInt.js +10 -0
  48. package/lib/isBlob.js +1 -1
  49. package/lib/isEqual.js +2 -1
  50. package/lib/isMatch.js +4 -4
  51. package/lib/isUndefined.js +3 -1
  52. package/lib/merge.js +4 -3
  53. package/lib/nth.js +2 -1
  54. package/lib/omit.js +4 -3
  55. package/lib/orderBy.js +3 -2
  56. package/lib/partial.js +1 -1
  57. package/lib/pascalCase.js +13 -0
  58. package/lib/pick.js +4 -3
  59. package/lib/toString.js +1 -1
  60. package/package.json +1 -1
  61. package/types/allKeys.d.ts +1 -1
  62. package/types/allKeysIn.d.ts +1 -1
  63. package/types/conforms.d.ts +7 -2
  64. package/types/conformsTo.d.ts +3 -3
  65. package/types/curry.d.ts +123 -0
  66. package/types/delay.d.ts +1 -1
  67. package/types/index.d.ts +4 -0
  68. package/types/internals/compare.d.ts +4 -4
  69. package/types/internals/helpers.d.ts +1 -0
  70. package/types/internals/native.d.ts +4 -0
  71. package/types/internals/types.d.ts +2 -0
  72. package/types/invert.d.ts +19 -0
  73. package/types/isBigInt.d.ts +22 -0
  74. package/types/keys.d.ts +1 -1
  75. package/types/keysIn.d.ts +1 -1
  76. package/types/omit.d.ts +6 -1
  77. package/types/omitBy.d.ts +3 -2
  78. package/types/orderBy.d.ts +3 -3
  79. package/types/partial.d.ts +5 -5
  80. package/types/pascalCase.d.ts +27 -0
  81. package/types/pick.d.ts +6 -1
  82. package/types/pickBy.d.ts +3 -2
@@ -1,7 +1,12 @@
1
+ import { PropertyName, WithNullable } from './internals/types';
2
+ interface ConformsFunction {
3
+ <T extends object, K extends keyof T>(source: Record<PropertyName, (value: T[K]) => boolean>): (object: WithNullable<T>) => boolean;
4
+ (source: object): (object: any) => boolean;
5
+ }
1
6
  /**
2
7
  * 创建一个函数,调用 `source` 的属性名对应的断言函数与传入对象相对应属性名的值进行断言处理。如果都符合返回 `true`,否则返回 `false` 。
3
8
  *
4
- * @static
9
+ * @function
5
10
  * @alias module:Util.conforms
6
11
  * @since 1.0.0
7
12
  * @param {Object} source 要断言属性是否符合的对象。
@@ -15,5 +20,5 @@
15
20
  *
16
21
  * objs.filter(conforms({ b: value => value > 1 })); // [{ a: 2: b: 2 }]
17
22
  */
18
- declare function conforms<T extends object, K extends keyof T, S extends object = Record<string, (value: T[K]) => any>>(source: S): (object: T) => boolean;
23
+ declare const conforms: ConformsFunction;
19
24
  export default conforms;
@@ -1,7 +1,7 @@
1
- import { WithNullable } from './internals/types';
1
+ import { PropertyName, WithNullable } from './internals/types';
2
2
  interface ConformsTo {
3
- <T extends object, K extends keyof T>(object: T, source: Record<K, (value: T[K]) => any>): boolean;
4
- <T extends WithNullable<object>>(object: T, source: Record<string | symbol, (value: any) => any>): boolean;
3
+ <T extends object, K extends keyof T>(object: T, source: Record<K, (value: T[K]) => boolean>): boolean;
4
+ (object: WithNullable<object>, source: Record<PropertyName, (value: any) => boolean>): boolean;
5
5
  }
6
6
  /**
7
7
  * 通过调用断言 `source` 的属性与 `object` 的相应属性值,检查 `object` 是否符合 `source` 。
@@ -0,0 +1,123 @@
1
+ declare const PLACEHOLDER: {
2
+ __ut2_curry_ph__: null;
3
+ };
4
+ type Placeholder = typeof PLACEHOLDER;
5
+ interface Curry {
6
+ <T1, R>(func: (t1: T1) => R, arity?: number): CurriedFunction1<T1, R>;
7
+ <T1, T2, R>(func: (t1: T1, t2: T2) => R, arity?: number): CurriedFunction2<T1, T2, R>;
8
+ <T1, T2, T3, R>(func: (t1: T1, t2: T2, t3: T3) => R, arity?: number): CurriedFunction3<T1, T2, T3, R>;
9
+ <T1, T2, T3, T4, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4) => R, arity?: number): CurriedFunction4<T1, T2, T3, T4, R>;
10
+ <T1, T2, T3, T4, T5, R>(func: (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5) => R, arity?: number): CurriedFunction5<T1, T2, T3, T4, T5, R>;
11
+ (func: (...args: any[]) => any, arity?: number): (...args: any[]) => any;
12
+ placeholder: Placeholder;
13
+ _: Placeholder;
14
+ }
15
+ interface CurriedFunction1<T1, R> {
16
+ (t1: T1): R;
17
+ (t1: Placeholder): CurriedFunction1<T1, R>;
18
+ (): CurriedFunction1<T1, R>;
19
+ }
20
+ interface CurriedFunction2<T1, T2, R> {
21
+ (t1: Placeholder, t2: T2): CurriedFunction1<T1, R>;
22
+ (t1: T1, t2: T2): R;
23
+ (t1: T1): CurriedFunction1<T2, R>;
24
+ (t1: Placeholder): CurriedFunction2<T1, T2, R>;
25
+ (): CurriedFunction2<T1, T2, R>;
26
+ }
27
+ interface CurriedFunction3<T1, T2, T3, R> {
28
+ (t1: Placeholder, t2: Placeholder, t3: T3): CurriedFunction2<T1, T2, R>;
29
+ (t1: Placeholder, t2: T2, t3: T3): CurriedFunction1<T1, R>;
30
+ (t1: T1, t2: Placeholder, t3: T3): CurriedFunction1<T2, R>;
31
+ (t1: T1, t2: T2, t3: T3): R;
32
+ (t1: Placeholder, t2: T2): CurriedFunction2<T1, T3, R>;
33
+ (t1: T1, t2: T2): CurriedFunction1<T3, R>;
34
+ (t1: T1): CurriedFunction2<T2, T3, R>;
35
+ (t1: Placeholder): CurriedFunction3<T1, T2, T3, R>;
36
+ (): CurriedFunction3<T1, T2, T3, R>;
37
+ }
38
+ interface CurriedFunction4<T1, T2, T3, T4, R> {
39
+ (t1: Placeholder, t2: Placeholder, t3: Placeholder, t4: T4): CurriedFunction3<T1, T2, T3, R>;
40
+ (t1: Placeholder, t2: Placeholder, t3: T3, t4: T4): CurriedFunction2<T1, T2, R>;
41
+ (t1: Placeholder, t2: T2, t3: Placeholder, t4: T4): CurriedFunction2<T1, T3, R>;
42
+ (t1: T1, t2: Placeholder, t3: Placeholder, t4: T4): CurriedFunction2<T2, T3, R>;
43
+ (t1: T1, t2: T2, t3: Placeholder, t4: T4): CurriedFunction1<T3, R>;
44
+ (t1: T1, t2: Placeholder, t3: T3, t4: T4): CurriedFunction1<T2, R>;
45
+ (t1: Placeholder, t2: T2, t3: T3, t4: T4): CurriedFunction1<T1, R>;
46
+ (t1: T1, t2: T2, t3: T3, t4: T4): R;
47
+ (t1: Placeholder, t2: Placeholder, t3: T3): CurriedFunction3<T1, T2, T4, R>;
48
+ (t1: T1, t2: Placeholder, t3: T3): CurriedFunction2<T2, T4, R>;
49
+ (t1: Placeholder, t2: T2, t3: T3): CurriedFunction2<T1, T4, R>;
50
+ (t1: T1, t2: T2, t3: T3): CurriedFunction1<T4, R>;
51
+ (t1: Placeholder, t2: T2): CurriedFunction3<T1, T3, T4, R>;
52
+ (t1: T1, t2: T2): CurriedFunction2<T3, T4, R>;
53
+ (t1: T1): CurriedFunction3<T2, T3, T4, R>;
54
+ (t1: Placeholder): CurriedFunction4<T1, T2, T3, T4, R>;
55
+ (): CurriedFunction4<T1, T2, T3, T4, R>;
56
+ }
57
+ interface CurriedFunction5<T1, T2, T3, T4, T5, R> {
58
+ (t1: Placeholder, t2: Placeholder, t3: Placeholder, t4: Placeholder, t5: T5): CurriedFunction4<T1, T2, T3, T4, R>;
59
+ (t1: Placeholder, t2: Placeholder, t3: Placeholder, t4: T4, t5: T5): CurriedFunction3<T1, T2, T3, R>;
60
+ (t1: Placeholder, t2: Placeholder, t3: T3, t4: Placeholder, t5: T5): CurriedFunction3<T1, T2, T4, R>;
61
+ (t1: Placeholder, t2: T2, t3: Placeholder, t4: Placeholder, t5: T5): CurriedFunction3<T1, T3, T4, R>;
62
+ (t1: T1, t2: Placeholder, t3: Placeholder, t4: Placeholder, t5: T5): CurriedFunction3<T2, T3, T4, R>;
63
+ (t1: Placeholder, t2: Placeholder, t3: T3, t4: T4, t5: T5): CurriedFunction2<T1, T2, R>;
64
+ (t1: Placeholder, t2: T2, t3: Placeholder, t4: T4, t5: T5): CurriedFunction2<T1, T3, R>;
65
+ (t1: Placeholder, t2: T2, t3: T3, t4: Placeholder, t5: T5): CurriedFunction2<T1, T4, R>;
66
+ (t1: T1, t2: Placeholder, t3: Placeholder, t4: T4, t5: T5): CurriedFunction2<T2, T3, R>;
67
+ (t1: T1, t2: Placeholder, t3: T3, t4: Placeholder, t5: T5): CurriedFunction2<T2, T4, R>;
68
+ (t1: T1, t2: T2, t3: Placeholder, t4: Placeholder, t5: T5): CurriedFunction2<T3, T4, R>;
69
+ (t1: T1, t2: T2, t3: T3, t4: Placeholder, t5: T5): CurriedFunction1<T4, R>;
70
+ (t1: T1, t2: T2, t3: Placeholder, t4: T4, t5: T5): CurriedFunction1<T3, R>;
71
+ (t1: T1, t2: Placeholder, t3: T3, t4: T4, t5: T5): CurriedFunction1<T2, R>;
72
+ (t1: Placeholder, t2: T2, t3: T3, t4: T4, t5: T5): CurriedFunction1<T1, R>;
73
+ (t1: T1, t2: T2, t3: T3, t4: T4, t5: T5): R;
74
+ (t1: Placeholder, t2: Placeholder, t3: Placeholder, t4: T4): CurriedFunction4<T1, T2, T3, T5, R>;
75
+ (t1: Placeholder, t2: Placeholder, t3: T3, t4: T4): CurriedFunction3<T1, T2, T5, R>;
76
+ (t1: Placeholder, t2: T2, t3: Placeholder, t4: T4): CurriedFunction3<T1, T3, T5, R>;
77
+ (t1: T1, t2: Placeholder, t3: Placeholder, t4: T4): CurriedFunction3<T2, T3, T5, R>;
78
+ (t1: T1, t2: T2, t3: Placeholder, t4: T4): CurriedFunction2<T3, T5, R>;
79
+ (t1: T1, t2: Placeholder, t3: T3, t4: T4): CurriedFunction2<T2, T5, R>;
80
+ (t1: Placeholder, t2: T2, t3: T3, t4: T4): CurriedFunction2<T1, T5, R>;
81
+ (t1: T1, t2: T2, t3: T3, t4: T4): CurriedFunction1<T5, R>;
82
+ (t1: Placeholder, t2: Placeholder, t3: T3): CurriedFunction4<T1, T2, T4, T5, R>;
83
+ (t1: T1, t2: Placeholder, t3: T3): CurriedFunction3<T2, T4, T5, R>;
84
+ (t1: Placeholder, t2: T2, t3: T3): CurriedFunction3<T1, T4, T5, R>;
85
+ (t1: T1, t2: T2, t3: T3): CurriedFunction2<T4, T5, R>;
86
+ (t1: Placeholder, t2: T2): CurriedFunction4<T1, T3, T4, T5, R>;
87
+ (t1: T1, t2: T2): CurriedFunction3<T3, T4, T5, R>;
88
+ (t1: T1): CurriedFunction4<T2, T3, T4, T5, R>;
89
+ (t1: Placeholder): CurriedFunction5<T1, T2, T3, T4, T5, R>;
90
+ (): CurriedFunction5<T1, T2, T3, T4, T5, R>;
91
+ }
92
+ /**
93
+ * 创建一个函数。该函数接受 `func` 参数,在提供的参数数量达到 `arity` 后调用 `func` 并返回其结果。
94
+ *
95
+ * `curry._` 或 `curry.placeholder` 可用作参数的占位符。
96
+ *
97
+ * @function
98
+ * @alias module:Function.curry
99
+ * @since 1.8.0
100
+ * @param {Function} func 需要柯里化的函数。
101
+ * @param {number} [arity] 指定参数数量,默认值为 `func.length`。
102
+ * @returns {Function} 新的柯里化函数。
103
+ * @example
104
+ *
105
+ * function abc(a, b, c){
106
+ * return [a, b, c];
107
+ * }
108
+ *
109
+ * var curried = curry(abc);
110
+ *
111
+ * curried(1)(2)(3); // [1, 2, 3]
112
+ *
113
+ * curried(1, 2)(3); // [1, 2, 3]
114
+ *
115
+ * curried(1, 2, 3); // [1, 2, 3]
116
+ *
117
+ * curried(1)(curry._, 3)(2); // [1, 2, 3]
118
+ *
119
+ * curried(curry._, curry._, 3)(curry._, 2)(1); // [1, 2, 3]
120
+ *
121
+ */
122
+ declare const curry: Curry;
123
+ export default curry;
package/types/delay.d.ts CHANGED
@@ -20,5 +20,5 @@ import { FunctionAny } from './internals/types';
20
20
  * // 'hello world'
21
21
  *
22
22
  */
23
- declare function delay<T extends FunctionAny>(func: T, wait: number, ...args: Parameters<T>): NodeJS.Timeout;
23
+ declare function delay<T extends FunctionAny>(this: any, func: T, wait: number, ...args: Parameters<T>): NodeJS.Timeout;
24
24
  export default delay;
package/types/index.d.ts CHANGED
@@ -44,6 +44,7 @@ export { default as some } from './some';
44
44
  */
45
45
  export { default as after } from './after';
46
46
  export { default as before } from './before';
47
+ export { default as curry } from './curry';
47
48
  export { default as debounce } from './debounce';
48
49
  export { default as delay } from './delay';
49
50
  export { default as negate } from './negate';
@@ -61,6 +62,7 @@ export { default as isArray } from './isArray';
61
62
  export { default as isArrayBuffer } from './isArrayBuffer';
62
63
  export { default as isArrayLike } from './isArrayLike';
63
64
  export { default as isArrayLikeObject } from './isArrayLikeObject';
65
+ export { default as isBigInt } from './isBigInt';
64
66
  export { default as isBlob } from './isBlob';
65
67
  export { default as isBoolean } from './isBoolean';
66
68
  export { default as isBuffer } from './isBuffer';
@@ -122,6 +124,7 @@ export { default as randomInt } from './randomInt';
122
124
  */
123
125
  export { default as allKeys } from './allKeys';
124
126
  export { default as allKeysIn } from './allKeysIn';
127
+ export { default as invert } from './invert';
125
128
  export { default as keys } from './keys';
126
129
  export { default as keysIn } from './keysIn';
127
130
  export { default as merge } from './merge';
@@ -142,6 +145,7 @@ export { default as escapeRegExp } from './escapeRegExp';
142
145
  export { default as kebabCase } from './kebabCase';
143
146
  export { default as lowerCase } from './lowerCase';
144
147
  export { default as lowerFirst } from './lowerFirst';
148
+ export { default as pascalCase } from './pascalCase';
145
149
  export { default as snakeCase } from './snakeCase';
146
150
  export { default as unescape } from './unescape';
147
151
  export { default as upperCase } from './upperCase';
@@ -1,10 +1,10 @@
1
1
  export declare function compareAsc(value: any, other: any): 0 | 1 | -1;
2
2
  export declare function compareDesc(value: any, other: any): 0 | 1 | -1;
3
- export type OrderData<T> = {
3
+ export type CompareOrderData<T> = {
4
4
  criteria: any[];
5
5
  index: number;
6
6
  value: T;
7
7
  };
8
- export type OrderBase = 'asc' | 'desc';
9
- export type Order = OrderBase | ((a: any, b: any) => number);
10
- export declare function compareMultiple<T>(object: OrderData<T>, other: OrderData<T>, orders: Order[]): number;
8
+ export type CompareOrderBase = 'asc' | 'desc';
9
+ export type CompareOrder = CompareOrderBase | ((a: any, b: any) => number);
10
+ export declare function compareMultiple<T>(object: CompareOrderData<T>, other: CompareOrderData<T>, orders: CompareOrder[]): number;
@@ -9,3 +9,4 @@ 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
11
  export declare const stubFlase: () => boolean;
12
+ export declare const stubTrue: () => boolean;
@@ -1,3 +1,6 @@
1
+ export declare const nativeUndefined: undefined;
2
+ export declare const stringUndefined = "undefined";
3
+ export declare const stringObject = "object";
1
4
  export declare const objectProto: Object;
2
5
  export declare const objectProtoToString: () => string;
3
6
  export declare const objectProtoHasOwnProperty: (v: PropertyKey) => boolean;
@@ -49,6 +52,7 @@ export declare const MIN_SAFE_INTEGER: number;
49
52
  * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/length | length}
50
53
  */
51
54
  export declare const MAX_ARRAY_LENGTH = 4294967295;
55
+ export declare const bigIntTag = "[object BigInt]";
52
56
  export declare const numberTag = "[object Number]";
53
57
  export declare const booleanTag = "[object Boolean]";
54
58
  export declare const stringTag = "[object String]";
@@ -4,6 +4,8 @@ export type FunctionAny = (...args: any[]) => any;
4
4
  */
5
5
  export type Many<T> = T | T[];
6
6
  export type WithNullable<T> = T | null | undefined;
7
+ export type PropertyName = string | number | symbol;
8
+ export type ObjectPredicate<T extends object, K extends keyof T = keyof T> = (value: T[K], key: K) => boolean;
7
9
  /**
8
10
  * 迭代参数
9
11
  */
@@ -0,0 +1,19 @@
1
+ import { ObjectPredicate, PropertyName, WithNullable } from './internals/types';
2
+ /**
3
+ * 创建一个对象,该对象由 `object` 自身可枚举属性(不包含 `Symbol` 属性)和值反转组成。
4
+ *
5
+ * @static
6
+ * @alias module:Object.invert
7
+ * @since 1.8.0
8
+ * @param {Object} object 来源对象。
9
+ * @param {Function} [predicate] 调用每一个属性的函数,返回 `truthy` 表示要反转,否则不反转。
10
+ * @returns {Object} 新对象。
11
+ * @example
12
+ *
13
+ * invert({ a: 1, b: 2 }); // { 1: 'a', 2: 'b' }
14
+ *
15
+ * invert({ a: undefined, b: null }); // { undefined: 'a', null: 'b' }
16
+ *
17
+ */
18
+ declare function invert<T extends object>(object: WithNullable<T>, predicate?: ObjectPredicate<T>): Record<PropertyName, any>;
19
+ export default invert;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 检查值是否为 bigint 类型或对象。
3
+ *
4
+ * @static
5
+ * @alias module:Language.isBigInt
6
+ * @since 1.8.0
7
+ * @param {*} value 要检查的值。
8
+ * @returns {boolean} 如果值为 bigint 类型或对象,返回 `true` 否则返回 `false` 。
9
+ * @example
10
+ *
11
+ * isBigInt(0n); // true
12
+ *
13
+ * isBigInt(1n); // true
14
+ *
15
+ * isBigInt(BigInt(1)); // true
16
+ *
17
+ * isBigInt(Object(1n)); // true
18
+ *
19
+ * isBigInt(1); // false
20
+ */
21
+ declare function isBigInt(value: any): value is bigint;
22
+ export default isBigInt;
package/types/keys.d.ts CHANGED
@@ -20,5 +20,5 @@
20
20
  * keys(new Foo); // ['a']
21
21
  *
22
22
  */
23
- declare function keys<T extends object>(object: T): string[];
23
+ declare function keys(object?: any): string[];
24
24
  export default keys;
package/types/keysIn.d.ts CHANGED
@@ -20,5 +20,5 @@
20
20
  * keysIn(new Foo); // ['a', 'c']
21
21
  *
22
22
  */
23
- declare function keysIn<T extends object>(object: T): string[];
23
+ declare function keysIn(object?: any): string[];
24
24
  export default keysIn;
package/types/omit.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ import { PropertyName, WithNullable } from './internals/types';
2
+ interface OmitFunction {
3
+ <T extends object, K extends keyof T>(object: WithNullable<T>, fields?: K | K[]): Omit<T, K>;
4
+ <T extends object, K extends PropertyName>(object: WithNullable<T>, fields?: K | K[]): Omit<T, K>;
5
+ }
1
6
  /**
2
7
  * 创建一个对象,该对象由忽略属性之外的 `object` 自身和继承的可枚举属性组成。与 [`pick`](#.pick) 相反。
3
8
  *
@@ -21,5 +26,5 @@
21
26
  * omit(obj, ['name', 'age']); // {}
22
27
  *
23
28
  */
24
- declare function omit<T extends object, K extends keyof T>(object: T, fields?: K | K[]): Omit<T, K>;
29
+ declare const omit: OmitFunction;
25
30
  export default omit;
package/types/omitBy.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ObjectPredicate, WithNullable } from './internals/types';
1
2
  /**
2
3
  * 创建一个对象,该对象忽略 `predicate` (断言函数)判断不是真值的属性后,`object` 自身和继承的可枚举属性组成。与 [`pickBy`](#.pickBy) 相反。
3
4
  *
@@ -7,7 +8,7 @@
7
8
  * @alias module:Object.omitBy
8
9
  * @since 1.0.0
9
10
  * @param {Object} object 来源对象。
10
- * @param {Function} [predicate] 调用每一个属性的函数。
11
+ * @param {Function} [predicate] 调用每一个属性的函数,返回 `truthy` 表示要忽略该属性,否则不忽略。
11
12
  * @returns {Object} 新对象。
12
13
  * @example
13
14
  *
@@ -20,5 +21,5 @@
20
21
  * omitBy(obj, (value) => value); // {}
21
22
  *
22
23
  */
23
- declare function omitBy<T extends object>(object: T, predicate?: (value: any, key: any) => any): Partial<T>;
24
+ declare function omitBy<T extends object>(object: WithNullable<T>, predicate?: ObjectPredicate<T>): Partial<T>;
24
25
  export default omitBy;
@@ -1,8 +1,8 @@
1
- import { Order } from './internals/compare';
1
+ import { CompareOrder } from './internals/compare';
2
2
  import { CollectionList, CollectionObject, IterateeParam, Many } from './internals/types';
3
3
  interface OrderBy {
4
- <T>(collection: CollectionList<T>, iteratee?: Many<IterateeParam<T>>, orders?: Many<Order>): T[];
5
- <T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: Many<IterateeParam<V>>, orders?: Many<Order>): V[];
4
+ <T>(collection: CollectionList<T>, iteratee?: Many<IterateeParam<T>>, orders?: Many<CompareOrder>): T[];
5
+ <T extends object, V extends T[keyof T]>(collection: CollectionObject<T>, iteratee?: Many<IterateeParam<V>>, orders?: Many<CompareOrder>): V[];
6
6
  }
7
7
  /**
8
8
  * 创建一个元素数组,以迭代函数处理的结果排序。如果没有指定排序,默认为升序排序。
@@ -1,7 +1,7 @@
1
- interface PartialPlaceholder {
2
- __ut2_partial__: number;
3
- }
4
- type Placeholder = PartialPlaceholder;
1
+ declare const PLACEHOLDER: {
2
+ __ut2_partial_ph__: null;
3
+ };
4
+ type Placeholder = typeof PLACEHOLDER;
5
5
  type Function0<R> = () => R;
6
6
  type Function1<T1, R> = (t1: T1) => R;
7
7
  type Function2<T1, T2, R> = (t1: T1, t2: T2) => R;
@@ -39,7 +39,7 @@ interface Partial {
39
39
  /**
40
40
  * 创建一个函数。该函数调用 `func` ,并传入预设的 `args` 参数。
41
41
  *
42
- * `partial._` 或 `partial.placeholder` 可用作部分参数的占位符。
42
+ * `partial._` 或 `partial.placeholder` 可用作参数的占位符。
43
43
  *
44
44
  * @function
45
45
  * @alias module:Function.partial
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 转换字符串为帕斯卡写法。又名为大驼峰写法。
3
+ *
4
+ * @static
5
+ * @alias module:String.pascalCase
6
+ * @since 1.8.0
7
+ * @see {@link https://en.wikipedia.org/wiki/Camel_case | Camel_case}
8
+ * @param {string} string 要转换的字符串。
9
+ * @param {RegExp | string} [pattern] 拆分词组的匹配模式。
10
+ * @returns {string} 帕斯卡写法的字符串。
11
+ * @example
12
+ *
13
+ * pascalCase('foo bar'); // 'FooBar'
14
+ *
15
+ * pascalCase('foo-bar'); // 'FooBar'
16
+ *
17
+ * pascalCase('Foo Bar'); // 'FooBar'
18
+ *
19
+ * pascalCase('FOO BAR'); // 'FooBar'
20
+ *
21
+ * pascalCase('--FOO-BAR--'); // 'FooBar'
22
+ *
23
+ * pascalCase('__FOO_BAR__'); // 'FooBar'
24
+ *
25
+ */
26
+ declare function pascalCase(string: string, pattern?: RegExp | string): string;
27
+ export default pascalCase;
package/types/pick.d.ts CHANGED
@@ -1,3 +1,8 @@
1
+ import { PropertyName, WithNullable } from './internals/types';
2
+ interface PickFunction {
3
+ <T extends object, K extends keyof T>(object: WithNullable<T>, fields?: K | K[]): Pick<T, K>;
4
+ <T extends object, K extends PropertyName>(object: WithNullable<T>, fields?: K | K[]): Record<PropertyName, any>;
5
+ }
1
6
  /**
2
7
  * 创建一个从 `object` 选中的属性的对象。
3
8
  *
@@ -21,5 +26,5 @@
21
26
  * // 选取多个属性
22
27
  * pick(obj, ['name', 'age']); // { name: "jeff", age: 18 }
23
28
  */
24
- declare function pick<T extends object, K extends keyof T>(object: T, fields?: K | K[]): Pick<T, K>;
29
+ declare const pick: PickFunction;
25
30
  export default pick;
package/types/pickBy.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { ObjectPredicate, WithNullable } from './internals/types';
1
2
  /**
2
3
  * 创建一个对象,该对象的属性从 `object` 中经 `predicate` (断言函数)判断为真值的属性。
3
4
  *
@@ -7,7 +8,7 @@
7
8
  * @alias module:Object.pickBy
8
9
  * @since 1.0.0
9
10
  * @param {Object} obj 来源对象。
10
- * @param {Function} [predicate] 调用每一个属性的函数。
11
+ * @param {Function} [predicate] 调用每一个属性的函数,返回 `truthy` 表示要提取该属性,否则不提取。
11
12
  * @returns {Object} 新对象。
12
13
  * @example
13
14
  *
@@ -20,5 +21,5 @@
20
21
  * pickBy(obj, (value) => value); // { name: "jeff", age: 18 }
21
22
  *
22
23
  */
23
- declare function pickBy<T extends object>(object: T, predicate?: (value: any, key: any) => any): Partial<T>;
24
+ declare function pickBy<T extends object>(object: WithNullable<T>, predicate?: ObjectPredicate<T>): Partial<T>;
24
25
  export default pickBy;