@omnific/utils 0.3.0 → 0.4.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 (45) hide show
  1. package/dist/@types/GetFieldType.d.ts +2 -3
  2. package/dist/@types/Many.d.ts +2 -3
  3. package/dist/@types/PropertyPath.d.ts +2 -4
  4. package/dist/_internal/isDeepKey.js +1 -2
  5. package/dist/_internal/toKey.js +1 -2
  6. package/dist/createChainedFunction.d.ts +3 -3
  7. package/dist/createChainedFunction.js +5 -1
  8. package/dist/debounce.d.ts +4 -8
  9. package/dist/get.d.ts +21 -23
  10. package/dist/get.js +1 -2
  11. package/dist/hasValue.d.ts +2 -2
  12. package/dist/isArray.d.ts +2 -3
  13. package/dist/isArrayBuffer.d.ts +2 -3
  14. package/dist/isArrayEmpty.d.ts +2 -3
  15. package/dist/isArrayEmpty.js +1 -2
  16. package/dist/isBlob.d.ts +2 -3
  17. package/dist/isBoolean.d.ts +2 -3
  18. package/dist/isFormData.d.ts +2 -3
  19. package/dist/isFunction.d.ts +2 -3
  20. package/dist/isNil.d.ts +2 -3
  21. package/dist/isNull.d.ts +2 -3
  22. package/dist/isNumber.d.ts +2 -3
  23. package/dist/isNumber.js +1 -2
  24. package/dist/isObject.d.ts +2 -3
  25. package/dist/isPlainObject.d.ts +2 -3
  26. package/dist/isPlainObject.js +1 -2
  27. package/dist/isPromise.d.ts +2 -3
  28. package/dist/isString.d.ts +2 -3
  29. package/dist/isStringEmpty.d.ts +2 -3
  30. package/dist/isStringEmpty.js +1 -2
  31. package/dist/isSymbol.d.ts +2 -3
  32. package/dist/isURLSearchParameters.d.ts +2 -3
  33. package/dist/isUndefined.d.ts +2 -3
  34. package/dist/kebabCase.d.ts +14 -0
  35. package/dist/kebabCase.js +30 -0
  36. package/dist/main.d.ts +2 -1
  37. package/dist/main.js +2 -1
  38. package/dist/parseJson.d.ts +2 -3
  39. package/dist/resolveValue.d.ts +2 -2
  40. package/dist/resolveValue.js +1 -2
  41. package/dist/throttle.d.ts +4 -8
  42. package/dist/uniqueId.d.ts +2 -3
  43. package/dist/utils/toPath.js +14 -12
  44. package/dist/utils/toString.js +1 -2
  45. package/package.json +4 -1
@@ -11,6 +11,5 @@ type GetFieldTypeOfPrimitive<T, X, XT extends 'DotPath' | 'Key' | 'Path'> = Extr
11
11
  /**
12
12
  * 解析指定键、点路径或括号路径对应的值类型。
13
13
  */
14
- type GetFieldType<T, X, XT extends 'DotPath' | 'Key' | 'Path' = 'Path'> = Extract<T, object> extends never ? GetFieldTypeOfPrimitive<T, X, XT> : GetFieldTypeOfPrimitive<Exclude<T, object>, X, XT> | GetFieldTypeOfObject<Extract<T, object>, X, XT>;
15
- //#endregion
16
- export { GetFieldType };
14
+ export type GetFieldType<T, X, XT extends 'DotPath' | 'Key' | 'Path' = 'Path'> = Extract<T, object> extends never ? GetFieldTypeOfPrimitive<T, X, XT> : GetFieldTypeOfPrimitive<Exclude<T, object>, X, XT> | GetFieldTypeOfObject<Extract<T, object>, X, XT>;
15
+ //#endregion
@@ -2,6 +2,5 @@
2
2
  /**
3
3
  * 表示单个值或只读值列表。
4
4
  */
5
- type Many<T> = T | readonly T[];
6
- //#endregion
7
- export { Many };
5
+ export type Many<T> = T | readonly T[];
6
+ //#endregion
@@ -1,9 +1,7 @@
1
1
  import { Many } from "./Many.js";
2
-
3
2
  //#region @types/PropertyPath.d.ts
4
3
  /**
5
4
  * 用于对象路径访问的单个属性键或只读属性键列表。
6
5
  */
7
- type PropertyPath = Many<PropertyKey>;
8
- //#endregion
9
- export { PropertyPath };
6
+ export type PropertyPath = Many<PropertyKey>;
7
+ //#endregion
@@ -18,8 +18,7 @@ import { isString } from "../isString.js";
18
18
  * isDeepKey('a[b][c]') // true
19
19
  */
20
20
  function isDeepKey(key) {
21
- if (isString(key)) return key.includes(".") || key.includes("[") || key.includes("]");
22
- return false;
21
+ return isString(key) ? key.includes(".") || key.includes("[") || key.includes("]") : false;
23
22
  }
24
23
  //#endregion
25
24
  export { isDeepKey };
@@ -15,8 +15,7 @@ function normalizeKey(path) {
15
15
  * @returns {string|symbol} Returns the key.
16
16
  */
17
17
  function toKey(value) {
18
- if (isString(value) || isSymbol(value)) return value;
19
- return normalizeKey(value);
18
+ return isString(value) || isSymbol(value) ? value : normalizeKey(value);
20
19
  }
21
20
  //#endregion
22
21
  export { normalizeKey, toKey };
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * A function with a bound `this` context and variadic arguments.
4
4
  */
5
- type ChainedFunction<TArguments extends any[], TThis> = (this: TThis, ...arguments_: TArguments) => void;
5
+ export type ChainedFunction<TArguments extends any[], TThis> = (this: TThis, ...arguments_: TArguments) => void;
6
6
  /**
7
7
  * Composes multiple callbacks into a single callback while preserving `this`.
8
8
  *
@@ -14,6 +14,6 @@ type ChainedFunction<TArguments extends any[], TThis> = (this: TThis, ...argumen
14
14
  * @param {...(ChainedFunction<TArgs, TThis> | null | undefined)[]} funcs - The callbacks to chain.
15
15
  * @returns {ChainedFunction<TArgs, TThis>} A single chained callback.
16
16
  */
17
- declare function createChainedFunction<TArguments extends any[], TThis>(...funcs: Array<ChainedFunction<TArguments, TThis> | null | undefined>): ChainedFunction<TArguments, TThis>;
17
+ export declare function createChainedFunction<TArguments extends any[], TThis>(...funcs: Array<ChainedFunction<TArguments, TThis> | null | undefined>): ChainedFunction<TArguments, TThis>;
18
18
  //#endregion
19
- export { ChainedFunction, createChainedFunction, createChainedFunction as default };
19
+ export { createChainedFunction as default };
@@ -1,4 +1,5 @@
1
1
  import { isArrayEmpty } from "./isArrayEmpty.js";
2
+ import hasValue from "./hasValue.js";
2
3
  import { isFunction } from "./isFunction.js";
3
4
  //#region createChainedFunction.ts
4
5
  /**
@@ -15,7 +16,10 @@ import { isFunction } from "./isFunction.js";
15
16
  function createChainedFunction(...funcs) {
16
17
  const validFuncs = funcs.filter((function_) => isFunction(function_));
17
18
  if (isArrayEmpty(validFuncs)) return function() {};
18
- if (validFuncs.length === 1) return validFuncs[0];
19
+ if (validFuncs.length === 1) {
20
+ const [onlyFunction] = validFuncs;
21
+ if (hasValue(onlyFunction)) return onlyFunction;
22
+ }
19
23
  return function(...arguments_) {
20
24
  for (const function_ of validFuncs) function_.apply(this, arguments_);
21
25
  };
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * 控制防抖函数何时调用或取消的选项。
4
4
  */
5
- interface DebounceOptions {
5
+ export interface DebounceOptions {
6
6
  /**
7
7
  * An optional AbortSignal to cancel the debounced function.
8
8
  */
@@ -19,7 +19,7 @@ interface DebounceOptions {
19
19
  /**
20
20
  * 带有调度、取消和立即执行控制能力的防抖函数。
21
21
  */
22
- interface DebouncedFunction<F extends (...arguments_: any[]) => void> {
22
+ export interface DebouncedFunction<F extends (...arguments_: any[]) => void> {
23
23
  (...arguments_: Parameters<F>): void;
24
24
  /**
25
25
  * Schedules the execution of the debounced function after the specified debounce delay.
@@ -76,9 +76,5 @@ interface DebouncedFunction<F extends (...arguments_: any[]) => void> {
76
76
  * // Will cancel the debounced function call
77
77
  * controller.abort();
78
78
  */
79
- declare function debounce<F extends (...arguments_: any[]) => void>(function_: F, debounceMs: number, {
80
- signal,
81
- edges
82
- }?: DebounceOptions): DebouncedFunction<F>;
83
- //#endregion
84
- export { DebounceOptions, DebouncedFunction, debounce };
79
+ export declare function debounce<F extends (...arguments_: any[]) => void>(function_: F, debounceMs: number, { signal, edges }?: DebounceOptions): DebouncedFunction<F>;
80
+ //#endregion
package/dist/get.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { GetFieldType } from "./@types/GetFieldType.js";
2
2
  import { PropertyPath } from "./@types/PropertyPath.js";
3
-
4
3
  //#region get.d.ts
5
4
  /**
6
5
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
@@ -16,7 +15,7 @@ import { PropertyPath } from "./@types/PropertyPath.js";
16
15
  * get(object, 'a[0].b.c');
17
16
  * // => 3
18
17
  */
19
- declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey];
18
+ export declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject, path: TKey | [TKey]): TObject[TKey];
20
19
  /**
21
20
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
22
21
  *
@@ -31,7 +30,7 @@ declare function get<TObject extends object, TKey extends keyof TObject>(object:
31
30
  * get(object, 'a[0].b.c');
32
31
  * // => 3
33
32
  */
34
- declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject | null | undefined, path: TKey | [TKey]): TObject[TKey] | undefined;
33
+ export declare function get<TObject extends object, TKey extends keyof TObject>(object: TObject | null | undefined, path: TKey | [TKey]): TObject[TKey] | undefined;
35
34
  /**
36
35
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
37
36
  *
@@ -48,7 +47,7 @@ declare function get<TObject extends object, TKey extends keyof TObject>(object:
48
47
  * get(object, 'a[0].b.c', 'default');
49
48
  * // => 3
50
49
  */
51
- declare function get<TObject extends object, TKey extends keyof TObject, TDefault>(object: TObject | null | undefined, path: TKey | [TKey], defaultValue: TDefault): Exclude<TObject[TKey], undefined> | TDefault;
50
+ export declare function get<TObject extends object, TKey extends keyof TObject, TDefault>(object: TObject | null | undefined, path: TKey | [TKey], defaultValue: TDefault): Exclude<TObject[TKey], undefined> | TDefault;
52
51
  /**
53
52
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
54
53
  *
@@ -64,7 +63,7 @@ declare function get<TObject extends object, TKey extends keyof TObject, TDefaul
64
63
  * get(object, ['a', 'b']);
65
64
  * // => 2
66
65
  */
67
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(object: TObject, path: [TKey1, TKey2]): TObject[TKey1][TKey2];
66
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1]>(object: TObject, path: [TKey1, TKey2]): TObject[TKey1][TKey2];
68
67
  /**
69
68
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
70
69
  *
@@ -80,7 +79,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
80
79
  * get(object, ['a', 'b']);
81
80
  * // => 2
82
81
  */
83
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>>(object: TObject | null | undefined, path: [TKey1, TKey2]): NonNullable<TObject[TKey1]>[TKey2] | undefined;
82
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>>(object: TObject | null | undefined, path: [TKey1, TKey2]): NonNullable<TObject[TKey1]>[TKey2] | undefined;
84
83
  /**
85
84
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
86
85
  *
@@ -98,7 +97,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
98
97
  * get(object, ['a', 'b'], 'default');
99
98
  * // => 2
100
99
  */
101
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2], defaultValue: TDefault): Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault;
100
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2], defaultValue: TDefault): Exclude<NonNullable<TObject[TKey1]>[TKey2], undefined> | TDefault;
102
101
  /**
103
102
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
104
103
  *
@@ -115,7 +114,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
115
114
  * get(object, ['a', 'b', 'c']);
116
115
  * // => 3
117
116
  */
118
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3];
117
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2]>(object: TObject, path: [TKey1, TKey2, TKey3]): TObject[TKey1][TKey2][TKey3];
119
118
  /**
120
119
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
121
120
  *
@@ -132,7 +131,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
132
131
  * get(object, ['a', 'b', 'c']);
133
132
  * // => 3
134
133
  */
135
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined;
134
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3]): NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3] | undefined;
136
135
  /**
137
136
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
138
137
  *
@@ -151,7 +150,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
151
150
  * get(object, ['a', 'b', 'c'], 'default');
152
151
  * // => 3
153
152
  */
154
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3], defaultValue: TDefault): Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault;
153
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3], defaultValue: TDefault): Exclude<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3], undefined> | TDefault;
155
154
  /**
156
155
  * Gets the value at path of object.
157
156
  *
@@ -169,7 +168,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
169
168
  * get(object, ['a', 'b', 'c', 'd']);
170
169
  * // => 4
171
170
  */
172
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2], TKey4 extends keyof TObject[TKey1][TKey2][TKey3]>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4];
171
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof TObject[TKey1], TKey3 extends keyof TObject[TKey1][TKey2], TKey4 extends keyof TObject[TKey1][TKey2][TKey3]>(object: TObject, path: [TKey1, TKey2, TKey3, TKey4]): TObject[TKey1][TKey2][TKey3][TKey4];
173
172
  /**
174
173
  * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
175
174
  *
@@ -187,7 +186,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
187
186
  * get(object, ['a', 'b', 'c', 'd']);
188
187
  * // => 4
189
188
  */
190
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4]): NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined;
189
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4]): NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4] | undefined;
191
190
  /**
192
191
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
193
192
  *
@@ -207,7 +206,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
207
206
  * get(object, ['a', 'b', 'c', 'd'], 'default');
208
207
  * // => 4
209
208
  */
210
- declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4], defaultValue: TDefault): Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault;
209
+ export declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2 extends keyof NonNullable<TObject[TKey1]>, TKey3 extends keyof NonNullable<NonNullable<TObject[TKey1]>[TKey2]>, TKey4 extends keyof NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>, TDefault>(object: TObject | null | undefined, path: [TKey1, TKey2, TKey3, TKey4], defaultValue: TDefault): Exclude<NonNullable<NonNullable<NonNullable<TObject[TKey1]>[TKey2]>[TKey3]>[TKey4], undefined> | TDefault;
211
210
  /**
212
211
  * Gets the value at path of object.
213
212
  *
@@ -221,7 +220,7 @@ declare function get<TObject extends object, TKey1 extends keyof TObject, TKey2
221
220
  * get(object, 1);
222
221
  * // => 'b'
223
222
  */
224
- declare function get<T>(object: Record<number, T>, path: number): T;
223
+ export declare function get<T>(object: Record<number, T>, path: number): T;
225
224
  /**
226
225
  * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
227
226
  *
@@ -235,7 +234,7 @@ declare function get<T>(object: Record<number, T>, path: number): T;
235
234
  * get(object, 1);
236
235
  * // => 'b'
237
236
  */
238
- declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
237
+ export declare function get<T>(object: Record<number, T> | null | undefined, path: number): T | undefined;
239
238
  /**
240
239
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
241
240
  *
@@ -251,7 +250,7 @@ declare function get<T>(object: Record<number, T> | null | undefined, path: numb
251
250
  * get(object, 1, 'default');
252
251
  * // => 'b'
253
252
  */
254
- declare function get<T, TDefault>(object: Record<number, T> | null | undefined, path: number, defaultValue: TDefault): T | TDefault;
253
+ export declare function get<T, TDefault>(object: Record<number, T> | null | undefined, path: number, defaultValue: TDefault): T | TDefault;
255
254
  /**
256
255
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
257
256
  *
@@ -265,7 +264,7 @@ declare function get<T, TDefault>(object: Record<number, T> | null | undefined,
265
264
  * get(null, 'a.b.c', 'default');
266
265
  * // => 'default'
267
266
  */
268
- declare function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault;
267
+ export declare function get<TDefault>(object: null | undefined, path: PropertyPath, defaultValue: TDefault): TDefault;
269
268
  /**
270
269
  * Gets the value at path of object. If the resolved value is undefined, undefined is returned.
271
270
  *
@@ -277,7 +276,7 @@ declare function get<TDefault>(object: null | undefined, path: PropertyPath, def
277
276
  * get(null, 'a.b.c');
278
277
  * // => undefined
279
278
  */
280
- declare function get(object: null | undefined, path: PropertyPath): undefined;
279
+ export declare function get(object: null | undefined, path: PropertyPath): undefined;
281
280
  /**
282
281
  * Gets the value at path of object using type-safe path.
283
282
  *
@@ -292,7 +291,7 @@ declare function get(object: null | undefined, path: PropertyPath): undefined;
292
291
  * get(object, 'a.b.c');
293
292
  * // => 1
294
293
  */
295
- declare function get<TObject, TPath extends string>(data: TObject, path: TPath): string extends TPath ? any : GetFieldType<TObject, TPath>;
294
+ export declare function get<TObject, TPath extends string>(data: TObject, path: TPath): string extends TPath ? any : GetFieldType<TObject, TPath>;
296
295
  /**
297
296
  * Gets the value at path of object using type-safe path. If the resolved value is undefined, the defaultValue is returned.
298
297
  *
@@ -309,7 +308,7 @@ declare function get<TObject, TPath extends string>(data: TObject, path: TPath):
309
308
  * get(object, 'a.b.d', 'default');
310
309
  * // => 'default'
311
310
  */
312
- declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(data: TObject, path: TPath, defaultValue: TDefault): Exclude<GetFieldType<TObject, TPath>, undefined> | TDefault;
311
+ export declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObject, TPath>>(data: TObject, path: TPath, defaultValue: TDefault): Exclude<GetFieldType<TObject, TPath>, undefined> | TDefault;
313
312
  /**
314
313
  * Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned.
315
314
  *
@@ -323,6 +322,5 @@ declare function get<TObject, TPath extends string, TDefault = GetFieldType<TObj
323
322
  * get(object, 'a.b.c', 'default');
324
323
  * // => 1
325
324
  */
326
- declare function get(object: any, path: PropertyPath, defaultValue?: any): any;
327
- //#endregion
328
- export { get };
325
+ export declare function get(object: any, path: PropertyPath, defaultValue?: any): any;
326
+ //#endregion
package/dist/get.js CHANGED
@@ -38,8 +38,7 @@ function get(object, path, defaultValue) {
38
38
  return result;
39
39
  }
40
40
  if (isNumber(path)) return getDirect(object, toKey(path), defaultValue);
41
- if (isSymbol(path)) return getDirect(object, path, defaultValue);
42
- return getDirect(object, normalizeKey(path), defaultValue);
41
+ return isSymbol(path) ? getDirect(object, path, defaultValue) : getDirect(object, normalizeKey(path), defaultValue);
43
42
  }
44
43
  function getWithPath(object, path, defaultValue) {
45
44
  if (isArrayEmpty(path)) return defaultValue;
@@ -15,6 +15,6 @@
15
15
  * value;
16
16
  * }
17
17
  */
18
- declare function hasValue<T>(value: T): value is NonNullable<T>;
18
+ export declare function hasValue<T>(value: T): value is NonNullable<T>;
19
19
  //#endregion
20
- export { hasValue as default, hasValue };
20
+ export { hasValue as default };
package/dist/isArray.d.ts CHANGED
@@ -19,6 +19,5 @@
19
19
  * console.log(isArray(value2)); // false
20
20
  * console.log(isArray(value3)); // false
21
21
  */
22
- declare function isArray<T = unknown>(value: unknown): value is T[];
23
- //#endregion
24
- export { isArray };
22
+ export declare function isArray<T = unknown>(value: unknown): value is T[];
23
+ //#endregion
@@ -16,6 +16,5 @@
16
16
  * console.log(isArrayBuffer(value2)); // false
17
17
  * console.log(isArrayBuffer(value3)); // false
18
18
  */
19
- declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
20
- //#endregion
21
- export { isArrayBuffer };
19
+ export declare function isArrayBuffer(value: unknown): value is ArrayBuffer;
20
+ //#endregion
@@ -4,6 +4,5 @@
4
4
  *
5
5
  * `null`, `undefined`, and arrays without elements are considered empty.
6
6
  */
7
- declare function isArrayEmpty<T>(value: readonly T[] | null | undefined): value is null | undefined | readonly [];
8
- //#endregion
9
- export { isArrayEmpty };
7
+ export declare function isArrayEmpty<T>(value: readonly T[] | null | undefined): value is null | undefined | readonly [];
8
+ //#endregion
@@ -6,8 +6,7 @@ import { isNil } from "./isNil.js";
6
6
  * `null`, `undefined`, and arrays without elements are considered empty.
7
7
  */
8
8
  function isArrayEmpty(value) {
9
- if (isNil(value)) return true;
10
- return value.length === 0;
9
+ return isNil(value) ? true : value.length === 0;
11
10
  }
12
11
  //#endregion
13
12
  export { isArrayEmpty };
package/dist/isBlob.d.ts CHANGED
@@ -16,6 +16,5 @@
16
16
  * console.log(isBlob(value2)); // false
17
17
  * console.log(isBlob(value3)); // false
18
18
  */
19
- declare function isBlob(value: unknown): value is Blob;
20
- //#endregion
21
- export { isBlob };
19
+ export declare function isBlob(value: unknown): value is Blob;
20
+ //#endregion
@@ -21,6 +21,5 @@
21
21
  * console.log(isBoolean(value3)); // false
22
22
  *
23
23
  */
24
- declare function isBoolean(x: unknown): x is boolean;
25
- //#endregion
26
- export { isBoolean };
24
+ export declare function isBoolean(x: unknown): x is boolean;
25
+ //#endregion
@@ -16,6 +16,5 @@
16
16
  * console.log(isFormData(value2)); // false
17
17
  * console.log(isFormData(value3)); // false
18
18
  */
19
- declare function isFormData(value: unknown): value is FormData;
20
- //#endregion
21
- export { isFormData };
19
+ export declare function isFormData(value: unknown): value is FormData;
20
+ //#endregion
@@ -12,6 +12,5 @@
12
12
  * isFunction(Proxy); // true
13
13
  * isFunction(Int8Array); // true
14
14
  */
15
- declare function isFunction(value: any): value is (...arguments_: any[]) => any;
16
- //#endregion
17
- export { isFunction };
15
+ export declare function isFunction(value: any): value is (...arguments_: any[]) => any;
16
+ //#endregion
package/dist/isNil.d.ts CHANGED
@@ -18,6 +18,5 @@
18
18
  * const result2 = isNil(value2); // true
19
19
  * const result3 = isNil(value3); // false
20
20
  */
21
- declare function isNil(x: unknown): x is null | undefined;
22
- //#endregion
23
- export { isNil };
21
+ export declare function isNil(x: unknown): x is null | undefined;
22
+ //#endregion
package/dist/isNull.d.ts CHANGED
@@ -19,6 +19,5 @@
19
19
  * console.log(isNull(value2)); // false
20
20
  * console.log(isNull(value3)); // false
21
21
  */
22
- declare function isNull(x: unknown): x is null;
23
- //#endregion
24
- export { isNull };
22
+ export declare function isNull(x: unknown): x is null;
23
+ //#endregion
@@ -21,6 +21,5 @@
21
21
  * console.log(isNumber(value3)); // false
22
22
  *
23
23
  */
24
- declare function isNumber(value: unknown): value is number;
25
- //#endregion
26
- export { isNumber };
24
+ export declare function isNumber(value: unknown): value is number;
25
+ //#endregion
package/dist/isNumber.js CHANGED
@@ -22,8 +22,7 @@
22
22
  *
23
23
  */
24
24
  function isNumber(value) {
25
- if (Number.isNaN(value)) return false;
26
- return typeof value === "number";
25
+ return typeof value === "number" && !Number.isNaN(value);
27
26
  }
28
27
  //#endregion
29
28
  export { isNumber };
@@ -22,6 +22,5 @@
22
22
  * console.log(isObject(value3)); // true
23
23
  * console.log(isObject(value4)); // false
24
24
  */
25
- declare function isObject(value?: any): value is object;
26
- //#endregion
27
- export { isObject };
25
+ export declare function isObject(value?: any): value is object;
26
+ //#endregion
@@ -41,6 +41,5 @@
41
41
  * isPlainObject(globalThis); // ❌
42
42
  * ```
43
43
  */
44
- declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
45
- //#endregion
46
- export { isPlainObject };
44
+ export declare function isPlainObject(value: unknown): value is Record<PropertyKey, any>;
45
+ //#endregion
@@ -46,8 +46,7 @@ import { isObject } from "./isObject.js";
46
46
  function isPlainObject(value) {
47
47
  if (!isObject(value)) return false;
48
48
  const prototype = Object.getPrototypeOf(value);
49
- if (!(isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype)))) return false;
50
- return Object.prototype.toString.call(value) === "[object Object]";
49
+ return isNull(prototype) || prototype === Object.prototype || isNull(Object.getPrototypeOf(prototype)) ? Object.prototype.toString.call(value) === "[object Object]" : false;
51
50
  }
52
51
  //#endregion
53
52
  export { isPlainObject };
@@ -16,6 +16,5 @@
16
16
  * console.log(isPromise(value2)); // false
17
17
  * console.log(isPromise(value3)); // false
18
18
  */
19
- declare function isPromise(value: unknown): value is Promise<any>;
20
- //#endregion
21
- export { isPromise };
19
+ export declare function isPromise(value: unknown): value is Promise<any>;
20
+ //#endregion
@@ -16,6 +16,5 @@
16
16
  * console.log(isString(value2)); // false
17
17
  * console.log(isString(value3)); // false
18
18
  */
19
- declare function isString(value: unknown): value is string;
20
- //#endregion
21
- export { isString };
19
+ export declare function isString(value: unknown): value is string;
20
+ //#endregion
@@ -4,6 +4,5 @@
4
4
  *
5
5
  * `null`, `undefined`, and whitespace-only strings are considered empty.
6
6
  */
7
- declare function isStringEmpty(value: string | null | undefined): value is null | undefined;
8
- //#endregion
9
- export { isStringEmpty };
7
+ export declare function isStringEmpty(value: string | null | undefined): value is '' | null | undefined;
8
+ //#endregion
@@ -6,8 +6,7 @@ import { isNil } from "./isNil.js";
6
6
  * `null`, `undefined`, and whitespace-only strings are considered empty.
7
7
  */
8
8
  function isStringEmpty(value) {
9
- if (isNil(value)) return true;
10
- return value.trim().length === 0;
9
+ return isNil(value) ? true : value.trim().length === 0;
11
10
  }
12
11
  //#endregion
13
12
  export { isStringEmpty };
@@ -22,6 +22,5 @@
22
22
  * isSymbol({}); // false
23
23
  * isSymbol([1, 2, 3]); // false
24
24
  */
25
- declare function isSymbol(value: unknown): value is symbol;
26
- //#endregion
27
- export { isSymbol };
25
+ export declare function isSymbol(value: unknown): value is symbol;
26
+ //#endregion
@@ -16,6 +16,5 @@
16
16
  * console.log(isURLSearchParameters(value2)); // false
17
17
  * console.log(isURLSearchParameters(value3)); // false
18
18
  */
19
- declare function isURLSearchParameters(value: unknown): value is URLSearchParams;
20
- //#endregion
21
- export { isURLSearchParameters };
19
+ export declare function isURLSearchParameters(value: unknown): value is URLSearchParams;
20
+ //#endregion
@@ -19,6 +19,5 @@
19
19
  * console.log(isUndefined(value2)); // false
20
20
  * console.log(isUndefined(value3)); // false
21
21
  */
22
- declare const isUndefined: (value: unknown) => value is undefined;
23
- //#endregion
24
- export { isUndefined };
22
+ export declare const isUndefined: (value: unknown) => value is undefined;
23
+ //#endregion
@@ -0,0 +1,14 @@
1
+ //#region kebabCase.d.ts
2
+ /**
3
+ * 将字符串转换为 kebab-case。
4
+ *
5
+ * @param value 待转换字符串。
6
+ * @returns 转换后的 kebab-case 字符串。
7
+ *
8
+ * @example
9
+ * kebabCase('camelCase') // 'camel-case'
10
+ * kebabCase('some whitespace') // 'some-whitespace'
11
+ * kebabCase('HTTPRequest') // 'http-request'
12
+ */
13
+ export declare function kebabCase(value: string): string;
14
+ //#endregion
@@ -0,0 +1,30 @@
1
+ //#region kebabCase.ts
2
+ /**
3
+ * 用于拆分常见命名格式的正则;实现参考 es-toolkit 的 `kebabCase`。
4
+ */
5
+ const CASE_SPLIT_PATTERN = /\p{Lu}?\p{Ll}+|[0-9]+|\p{Lu}+(?!\p{Ll})|\p{Emoji_Presentation}|\p{Extended_Pictographic}|\p{L}+/gu;
6
+ /**
7
+ * 将字符串拆分为单词。
8
+ *
9
+ * @param value 待拆分字符串。
10
+ * @returns 拆分后的单词数组。
11
+ */
12
+ function words(value) {
13
+ return [...value.match(CASE_SPLIT_PATTERN) ?? []];
14
+ }
15
+ /**
16
+ * 将字符串转换为 kebab-case。
17
+ *
18
+ * @param value 待转换字符串。
19
+ * @returns 转换后的 kebab-case 字符串。
20
+ *
21
+ * @example
22
+ * kebabCase('camelCase') // 'camel-case'
23
+ * kebabCase('some whitespace') // 'some-whitespace'
24
+ * kebabCase('HTTPRequest') // 'http-request'
25
+ */
26
+ function kebabCase(value) {
27
+ return words(value).map((word) => word.toLowerCase()).join("-");
28
+ }
29
+ //#endregion
30
+ export { kebabCase };
package/dist/main.d.ts CHANGED
@@ -20,8 +20,9 @@ import { isStringEmpty } from "./isStringEmpty.js";
20
20
  import { isSymbol } from "./isSymbol.js";
21
21
  import { isURLSearchParameters } from "./isURLSearchParameters.js";
22
22
  import { isUndefined } from "./isUndefined.js";
23
+ import { kebabCase } from "./kebabCase.js";
23
24
  import { parseJson } from "./parseJson.js";
24
25
  import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
25
26
  import resolveValue from "./resolveValue.js";
26
27
  import { uniqueId } from "./uniqueId.js";
27
- export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
28
+ export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
package/dist/main.js CHANGED
@@ -21,7 +21,8 @@ import { isURLSearchParameters } from "./isURLSearchParameters.js";
21
21
  import { parseJson } from "./parseJson.js";
22
22
  import { isSymbol } from "./isSymbol.js";
23
23
  import { get } from "./get.js";
24
+ import { kebabCase } from "./kebabCase.js";
24
25
  import { throttle } from "./throttle.js";
25
26
  import resolveValue from "./resolveValue.js";
26
27
  import { uniqueId } from "./uniqueId.js";
27
- export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, parseJson, resolveValue, throttle, uniqueId };
28
+ export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isArrayEmpty, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isStringEmpty, isSymbol, isURLSearchParameters, isUndefined, kebabCase, parseJson, resolveValue, throttle, uniqueId };
@@ -5,6 +5,5 @@
5
5
  * Returns `undefined` for blank strings. When `fallback` is provided, invalid JSON
6
6
  * returns the fallback instead of throwing.
7
7
  */
8
- declare function parseJson<T>(text: string, fallback?: T): T | undefined;
9
- //#endregion
10
- export { parseJson };
8
+ export declare function parseJson<T>(text: string, fallback?: T): T | undefined;
9
+ //#endregion
@@ -12,6 +12,6 @@
12
12
  * resolveValue('ready');
13
13
  * resolveValue(status => status === 'error' ? 'retry' : 'ok', 'error');
14
14
  */
15
- declare function resolveValue<TValue, TArguments extends any[]>(value: TValue | ((...arguments_: TArguments) => TValue), ...arguments_: TArguments): TValue;
15
+ export declare function resolveValue<TValue, TArguments extends any[]>(value: TValue | ((...arguments_: TArguments) => TValue), ...arguments_: TArguments): TValue;
16
16
  //#endregion
17
- export { resolveValue as default, resolveValue };
17
+ export { resolveValue as default };
@@ -14,8 +14,7 @@ import { isFunction } from "./isFunction.js";
14
14
  * resolveValue(status => status === 'error' ? 'retry' : 'ok', 'error');
15
15
  */
16
16
  function resolveValue(value, ...arguments_) {
17
- if (isFunction(value)) return value(...arguments_);
18
- return value;
17
+ return isFunction(value) ? value(...arguments_) : value;
19
18
  }
20
19
  //#endregion
21
20
  export { resolveValue as default, resolveValue };
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * 控制节流函数何时调用或取消的选项。
4
4
  */
5
- interface ThrottleOptions {
5
+ export interface ThrottleOptions {
6
6
  /**
7
7
  * An optional AbortSignal to cancel the throttled function.
8
8
  */
@@ -19,7 +19,7 @@ interface ThrottleOptions {
19
19
  /**
20
20
  * 带有取消和立即执行控制能力的节流函数。
21
21
  */
22
- interface ThrottledFunction<F extends (...arguments_: any[]) => void> {
22
+ export interface ThrottledFunction<F extends (...arguments_: any[]) => void> {
23
23
  (...arguments_: Parameters<F>): void;
24
24
  cancel: () => void;
25
25
  flush: () => void;
@@ -50,9 +50,5 @@ interface ThrottledFunction<F extends (...arguments_: any[]) => void> {
50
50
  * throttledFunction(); // Will log 'Function executed'
51
51
  * }, 1000);
52
52
  */
53
- declare function throttle<F extends (...arguments_: any[]) => void>(function_: F, throttleMs: number, {
54
- signal,
55
- edges
56
- }?: ThrottleOptions): ThrottledFunction<F>;
57
- //#endregion
58
- export { ThrottleOptions, ThrottledFunction, throttle };
53
+ export declare function throttle<F extends (...arguments_: any[]) => void>(function_: F, throttleMs: number, { signal, edges }?: ThrottleOptions): ThrottledFunction<F>;
54
+ //#endregion
@@ -12,6 +12,5 @@
12
12
  * uniqueId('contact_'); // 'contact_2'
13
13
  * uniqueId('contact_'); // 'contact_3'
14
14
  */
15
- declare function uniqueId(prefix?: string): string;
16
- //#endregion
17
- export { uniqueId };
15
+ export declare function uniqueId(prefix?: string): string;
16
+ //#endregion
@@ -36,18 +36,20 @@ function toPath(deepKey) {
36
36
  }
37
37
  while (index < length) {
38
38
  const char = deepKey[index];
39
- if (quoteChar) if (char === "\\" && index + 1 < length) {
40
- index++;
41
- key += deepKey[index];
42
- } else if (char === quoteChar) quoteChar = "";
43
- else key += char;
44
- else if (isBracket) if (char === "\"" || char === "'") quoteChar = char;
45
- else if (char === "]") {
46
- isBracket = false;
47
- result.push(key);
48
- key = "";
49
- } else key += char;
50
- else if (char === "[") {
39
+ if (quoteChar) {
40
+ if (char === "\\" && index + 1 < length) {
41
+ index++;
42
+ key += deepKey[index];
43
+ } else if (char === quoteChar) quoteChar = "";
44
+ else key += char;
45
+ } else if (isBracket) {
46
+ if (char === "\"" || char === "'") quoteChar = char;
47
+ else if (char === "]") {
48
+ isBracket = false;
49
+ result.push(key);
50
+ key = "";
51
+ } else key += char;
52
+ } else if (char === "[") {
51
53
  isBracket = true;
52
54
  if (key) {
53
55
  result.push(key);
@@ -21,8 +21,7 @@ import { normalizeKey } from "../_internal/toKey.js";
21
21
  function toString(value) {
22
22
  if (isNil(value)) return "";
23
23
  if (isString(value)) return value;
24
- if (Array.isArray(value)) return value.map((item) => toString(item)).join(",");
25
- return normalizeKey(value);
24
+ return Array.isArray(value) ? value.map((item) => toString(item)).join(",") : normalizeKey(value);
26
25
  }
27
26
  //#endregion
28
27
  export { toString };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnific/utils",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "Shared utility predicates for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -38,6 +38,9 @@
38
38
  "dist",
39
39
  "README.md"
40
40
  ],
41
+ "devDependencies": {
42
+ "@omnific/tsconfig": "0.2.0"
43
+ },
41
44
  "scripts": {
42
45
  "build": "tsdown -c tsdown.config.mjs",
43
46
  "typecheck": "tsc -p tsconfig.json --noEmit"