@omnific/utils 0.2.0 → 0.3.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 (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 +7 -2
  8. package/dist/debounce.d.ts +4 -8
  9. package/dist/debounce.js +1 -1
  10. package/dist/get.d.ts +21 -23
  11. package/dist/get.js +3 -3
  12. package/dist/hasValue.d.ts +2 -2
  13. package/dist/isArray.d.ts +2 -3
  14. package/dist/isArrayBuffer.d.ts +2 -3
  15. package/dist/isArrayEmpty.d.ts +8 -0
  16. package/dist/isArrayEmpty.js +12 -0
  17. package/dist/isBlob.d.ts +2 -3
  18. package/dist/isBoolean.d.ts +2 -3
  19. package/dist/isFormData.d.ts +2 -3
  20. package/dist/isFunction.d.ts +2 -3
  21. package/dist/isNil.d.ts +2 -3
  22. package/dist/isNull.d.ts +2 -3
  23. package/dist/isNumber.d.ts +2 -3
  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/isPromise.js +2 -1
  29. package/dist/isString.d.ts +2 -3
  30. package/dist/isStringEmpty.d.ts +8 -0
  31. package/dist/isStringEmpty.js +12 -0
  32. package/dist/isSymbol.d.ts +2 -3
  33. package/dist/isURLSearchParameters.d.ts +2 -3
  34. package/dist/isUndefined.d.ts +2 -3
  35. package/dist/main.d.ts +3 -1
  36. package/dist/main.js +6 -4
  37. package/dist/parseJson.d.ts +2 -3
  38. package/dist/parseJson.js +2 -1
  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 +16 -13
  44. package/dist/utils/toString.js +1 -2
  45. package/package.json +5 -2
@@ -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,3 +1,5 @@
1
+ import { isArrayEmpty } from "./isArrayEmpty.js";
2
+ import hasValue from "./hasValue.js";
1
3
  import { isFunction } from "./isFunction.js";
2
4
  //#region createChainedFunction.ts
3
5
  /**
@@ -13,8 +15,11 @@ import { isFunction } from "./isFunction.js";
13
15
  */
14
16
  function createChainedFunction(...funcs) {
15
17
  const validFuncs = funcs.filter((function_) => isFunction(function_));
16
- if (validFuncs.length === 0) return function() {};
17
- if (validFuncs.length === 1) return validFuncs[0];
18
+ if (isArrayEmpty(validFuncs)) return function() {};
19
+ if (validFuncs.length === 1) {
20
+ const [onlyFunction] = validFuncs;
21
+ if (hasValue(onlyFunction)) return onlyFunction;
22
+ }
18
23
  return function(...arguments_) {
19
24
  for (const function_ of validFuncs) function_.apply(this, arguments_);
20
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/debounce.js CHANGED
@@ -1,6 +1,6 @@
1
- import hasValue from "./hasValue.js";
2
1
  import { isUndefined } from "./isUndefined.js";
3
2
  import { isNil } from "./isNil.js";
3
+ import hasValue from "./hasValue.js";
4
4
  //#region debounce.ts
5
5
  /**
6
6
  * Creates a debounced function that delays invoking the provided function until after `debounceMs` milliseconds
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
@@ -1,5 +1,6 @@
1
1
  import { isUndefined } from "./isUndefined.js";
2
2
  import { isNil } from "./isNil.js";
3
+ import { isArrayEmpty } from "./isArrayEmpty.js";
3
4
  import { isNumber } from "./isNumber.js";
4
5
  import { isString } from "./isString.js";
5
6
  import { isUnsafeProperty } from "./_internal/isUnsafeProperty.js";
@@ -37,11 +38,10 @@ function get(object, path, defaultValue) {
37
38
  return result;
38
39
  }
39
40
  if (isNumber(path)) return getDirect(object, toKey(path), defaultValue);
40
- if (isSymbol(path)) return getDirect(object, path, defaultValue);
41
- return getDirect(object, normalizeKey(path), defaultValue);
41
+ return isSymbol(path) ? getDirect(object, path, defaultValue) : getDirect(object, normalizeKey(path), defaultValue);
42
42
  }
43
43
  function getWithPath(object, path, defaultValue) {
44
- if (path.length === 0) return defaultValue;
44
+ if (isArrayEmpty(path)) return defaultValue;
45
45
  let current = object;
46
46
  for (const element of path) {
47
47
  if (isNil(current) || isUnsafeProperty(element)) 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
@@ -0,0 +1,8 @@
1
+ //#region isArrayEmpty.d.ts
2
+ /**
3
+ * Checks whether a value is nullish or an empty array.
4
+ *
5
+ * `null`, `undefined`, and arrays without elements are considered empty.
6
+ */
7
+ export declare function isArrayEmpty<T>(value: readonly T[] | null | undefined): value is null | undefined | readonly [];
8
+ //#endregion
@@ -0,0 +1,12 @@
1
+ import { isNil } from "./isNil.js";
2
+ //#region isArrayEmpty.ts
3
+ /**
4
+ * Checks whether a value is nullish or an empty array.
5
+ *
6
+ * `null`, `undefined`, and arrays without elements are considered empty.
7
+ */
8
+ function isArrayEmpty(value) {
9
+ return isNil(value) ? true : value.length === 0;
10
+ }
11
+ //#endregion
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
@@ -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
package/dist/isPromise.js CHANGED
@@ -1,3 +1,4 @@
1
+ import hasValue from "./hasValue.js";
1
2
  import { isFunction } from "./isFunction.js";
2
3
  import { isObject } from "./isObject.js";
3
4
  //#region isPromise.ts
@@ -19,7 +20,7 @@ import { isObject } from "./isObject.js";
19
20
  * console.log(isPromise(value3)); // false
20
21
  */
21
22
  function isPromise(value) {
22
- return value !== null && (isObject(value) || isFunction(value)) && typeof value.then === "function";
23
+ return hasValue(value) && (isObject(value) || isFunction(value)) && isFunction(value.then);
23
24
  }
24
25
  //#endregion
25
26
  export { isPromise };
@@ -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
@@ -0,0 +1,8 @@
1
+ //#region isStringEmpty.d.ts
2
+ /**
3
+ * Checks whether a value is nullish or an empty string.
4
+ *
5
+ * `null`, `undefined`, and whitespace-only strings are considered empty.
6
+ */
7
+ export declare function isStringEmpty(value: string | null | undefined): value is '' | null | undefined;
8
+ //#endregion
@@ -0,0 +1,12 @@
1
+ import { isNil } from "./isNil.js";
2
+ //#region isStringEmpty.ts
3
+ /**
4
+ * Checks whether a value is nullish or an empty string.
5
+ *
6
+ * `null`, `undefined`, and whitespace-only strings are considered empty.
7
+ */
8
+ function isStringEmpty(value) {
9
+ return isNil(value) ? true : value.trim().length === 0;
10
+ }
11
+ //#endregion
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
package/dist/main.d.ts CHANGED
@@ -4,6 +4,7 @@ import { get } from "./get.js";
4
4
  import hasValue from "./hasValue.js";
5
5
  import { isArray } from "./isArray.js";
6
6
  import { isArrayBuffer } from "./isArrayBuffer.js";
7
+ import { isArrayEmpty } from "./isArrayEmpty.js";
7
8
  import { isBlob } from "./isBlob.js";
8
9
  import { isBoolean } from "./isBoolean.js";
9
10
  import { isFormData } from "./isFormData.js";
@@ -15,6 +16,7 @@ import { isObject } from "./isObject.js";
15
16
  import { isPlainObject } from "./isPlainObject.js";
16
17
  import { isPromise } from "./isPromise.js";
17
18
  import { isString } from "./isString.js";
19
+ import { isStringEmpty } from "./isStringEmpty.js";
18
20
  import { isSymbol } from "./isSymbol.js";
19
21
  import { isURLSearchParameters } from "./isURLSearchParameters.js";
20
22
  import { isUndefined } from "./isUndefined.js";
@@ -22,4 +24,4 @@ import { parseJson } from "./parseJson.js";
22
24
  import { ThrottleOptions, ThrottledFunction, throttle } from "./throttle.js";
23
25
  import resolveValue from "./resolveValue.js";
24
26
  import { uniqueId } from "./uniqueId.js";
25
- export { type ChainedFunction, type DebounceOptions, type DebouncedFunction, type ThrottleOptions, type ThrottledFunction, createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isSymbol, isURLSearchParameters, isURLSearchParameters as isURLSearchParams, isUndefined, parseJson, resolveValue, throttle, uniqueId };
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 };
package/dist/main.js CHANGED
@@ -1,18 +1,20 @@
1
1
  import { isArray } from "./isArray.js";
2
+ import { isUndefined } from "./isUndefined.js";
3
+ import { isNull } from "./isNull.js";
4
+ import { isNil } from "./isNil.js";
5
+ import { isArrayEmpty } from "./isArrayEmpty.js";
2
6
  import { isBoolean } from "./isBoolean.js";
3
7
  import hasValue from "./hasValue.js";
4
8
  import { isBlob } from "./isBlob.js";
5
9
  import { isFunction } from "./isFunction.js";
6
10
  import { createChainedFunction } from "./createChainedFunction.js";
7
- import { isUndefined } from "./isUndefined.js";
8
- import { isNull } from "./isNull.js";
9
- import { isNil } from "./isNil.js";
10
11
  import { debounce } from "./debounce.js";
11
12
  import { isFormData } from "./isFormData.js";
12
13
  import { isNumber } from "./isNumber.js";
13
14
  import { isObject } from "./isObject.js";
14
15
  import { isPlainObject } from "./isPlainObject.js";
15
16
  import { isString } from "./isString.js";
17
+ import { isStringEmpty } from "./isStringEmpty.js";
16
18
  import { isPromise } from "./isPromise.js";
17
19
  import { isArrayBuffer } from "./isArrayBuffer.js";
18
20
  import { isURLSearchParameters } from "./isURLSearchParameters.js";
@@ -22,4 +24,4 @@ import { get } from "./get.js";
22
24
  import { throttle } from "./throttle.js";
23
25
  import resolveValue from "./resolveValue.js";
24
26
  import { uniqueId } from "./uniqueId.js";
25
- export { createChainedFunction, debounce, get, hasValue, isArray, isArrayBuffer, isBlob, isBoolean, isFormData, isFunction, isNil, isNull, isNumber, isObject, isPlainObject, isPromise, isString, isSymbol, isURLSearchParameters, isURLSearchParameters as isURLSearchParams, isUndefined, parseJson, resolveValue, throttle, uniqueId };
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 };
@@ -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
package/dist/parseJson.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { isStringEmpty } from "./isStringEmpty.js";
1
2
  //#region parseJson.ts
2
3
  /**
3
4
  * Parses JSON text into a value.
@@ -6,7 +7,7 @@
6
7
  * returns the fallback instead of throwing.
7
8
  */
8
9
  function parseJson(text, fallback) {
9
- if (!text.trim()) return;
10
+ if (isStringEmpty(text)) return;
10
11
  try {
11
12
  return JSON.parse(text);
12
13
  } catch (error) {
@@ -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
@@ -1,3 +1,4 @@
1
+ import { isSymbol } from "../isSymbol.js";
1
2
  import { toKey } from "../_internal/toKey.js";
2
3
  import { toString } from "./toString.js";
3
4
  //#region utils/toPath.ts
@@ -20,7 +21,7 @@ import { toString } from "./toString.js";
20
21
  */
21
22
  function toPath(deepKey) {
22
23
  if (Array.isArray(deepKey)) return deepKey.map((item) => toKey(item));
23
- if (typeof deepKey === "symbol") return [deepKey];
24
+ if (isSymbol(deepKey)) return [deepKey];
24
25
  deepKey = toString(deepKey);
25
26
  const result = [];
26
27
  const length = deepKey.length;
@@ -35,18 +36,20 @@ function toPath(deepKey) {
35
36
  }
36
37
  while (index < length) {
37
38
  const char = deepKey[index];
38
- if (quoteChar) if (char === "\\" && index + 1 < length) {
39
- index++;
40
- key += deepKey[index];
41
- } else if (char === quoteChar) quoteChar = "";
42
- else key += char;
43
- else if (isBracket) if (char === "\"" || char === "'") quoteChar = char;
44
- else if (char === "]") {
45
- isBracket = false;
46
- result.push(key);
47
- key = "";
48
- } else key += char;
49
- 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 === "[") {
50
53
  isBracket = true;
51
54
  if (key) {
52
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.2.0",
3
+ "version": "0.3.1",
4
4
  "description": "Shared utility predicates for Omnific packages",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -41,5 +41,8 @@
41
41
  "scripts": {
42
42
  "build": "tsdown -c tsdown.config.mjs",
43
43
  "typecheck": "tsc -p tsconfig.json --noEmit"
44
+ },
45
+ "devDependencies": {
46
+ "@omnific/tsconfig": "workspace:*"
44
47
  }
45
- }
48
+ }