@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.
- package/dist/@types/GetFieldType.d.ts +2 -3
- package/dist/@types/Many.d.ts +2 -3
- package/dist/@types/PropertyPath.d.ts +2 -4
- package/dist/_internal/isDeepKey.js +1 -2
- package/dist/_internal/toKey.js +1 -2
- package/dist/createChainedFunction.d.ts +3 -3
- package/dist/createChainedFunction.js +7 -2
- package/dist/debounce.d.ts +4 -8
- package/dist/debounce.js +1 -1
- package/dist/get.d.ts +21 -23
- package/dist/get.js +3 -3
- package/dist/hasValue.d.ts +2 -2
- package/dist/isArray.d.ts +2 -3
- package/dist/isArrayBuffer.d.ts +2 -3
- package/dist/isArrayEmpty.d.ts +8 -0
- package/dist/isArrayEmpty.js +12 -0
- package/dist/isBlob.d.ts +2 -3
- package/dist/isBoolean.d.ts +2 -3
- package/dist/isFormData.d.ts +2 -3
- package/dist/isFunction.d.ts +2 -3
- package/dist/isNil.d.ts +2 -3
- package/dist/isNull.d.ts +2 -3
- package/dist/isNumber.d.ts +2 -3
- package/dist/isObject.d.ts +2 -3
- package/dist/isPlainObject.d.ts +2 -3
- package/dist/isPlainObject.js +1 -2
- package/dist/isPromise.d.ts +2 -3
- package/dist/isPromise.js +2 -1
- package/dist/isString.d.ts +2 -3
- package/dist/isStringEmpty.d.ts +8 -0
- package/dist/isStringEmpty.js +12 -0
- package/dist/isSymbol.d.ts +2 -3
- package/dist/isURLSearchParameters.d.ts +2 -3
- package/dist/isUndefined.d.ts +2 -3
- package/dist/main.d.ts +3 -1
- package/dist/main.js +6 -4
- package/dist/parseJson.d.ts +2 -3
- package/dist/parseJson.js +2 -1
- package/dist/resolveValue.d.ts +2 -2
- package/dist/resolveValue.js +1 -2
- package/dist/throttle.d.ts +4 -8
- package/dist/uniqueId.d.ts +2 -3
- package/dist/utils/toPath.js +16 -13
- package/dist/utils/toString.js +1 -2
- 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
|
package/dist/@types/Many.d.ts
CHANGED
|
@@ -18,8 +18,7 @@ import { isString } from "../isString.js";
|
|
|
18
18
|
* isDeepKey('a[b][c]') // true
|
|
19
19
|
*/
|
|
20
20
|
function isDeepKey(key) {
|
|
21
|
-
|
|
22
|
-
return false;
|
|
21
|
+
return isString(key) ? key.includes(".") || key.includes("[") || key.includes("]") : false;
|
|
23
22
|
}
|
|
24
23
|
//#endregion
|
|
25
24
|
export { isDeepKey };
|
package/dist/_internal/toKey.js
CHANGED
|
@@ -15,8 +15,7 @@ function normalizeKey(path) {
|
|
|
15
15
|
* @returns {string|symbol} Returns the key.
|
|
16
16
|
*/
|
|
17
17
|
function toKey(value) {
|
|
18
|
-
|
|
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 {
|
|
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
|
|
17
|
-
if (validFuncs.length === 1)
|
|
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
|
};
|
package/dist/debounce.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
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;
|
package/dist/hasValue.d.ts
CHANGED
|
@@ -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
|
|
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
|
package/dist/isArrayBuffer.d.ts
CHANGED
|
@@ -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
|
package/dist/isBoolean.d.ts
CHANGED
package/dist/isFormData.d.ts
CHANGED
|
@@ -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
|
package/dist/isFunction.d.ts
CHANGED
|
@@ -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
package/dist/isNumber.d.ts
CHANGED
package/dist/isObject.d.ts
CHANGED
|
@@ -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
|
package/dist/isPlainObject.d.ts
CHANGED
|
@@ -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
|
package/dist/isPlainObject.js
CHANGED
|
@@ -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
|
-
|
|
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 };
|
package/dist/isPromise.d.ts
CHANGED
|
@@ -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
|
|
23
|
+
return hasValue(value) && (isObject(value) || isFunction(value)) && isFunction(value.then);
|
|
23
24
|
}
|
|
24
25
|
//#endregion
|
|
25
26
|
export { isPromise };
|
package/dist/isString.d.ts
CHANGED
|
@@ -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 };
|
package/dist/isSymbol.d.ts
CHANGED
|
@@ -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
|
package/dist/isUndefined.d.ts
CHANGED
|
@@ -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,
|
|
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,
|
|
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 };
|
package/dist/parseJson.d.ts
CHANGED
|
@@ -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 (
|
|
10
|
+
if (isStringEmpty(text)) return;
|
|
10
11
|
try {
|
|
11
12
|
return JSON.parse(text);
|
|
12
13
|
} catch (error) {
|
package/dist/resolveValue.d.ts
CHANGED
|
@@ -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
|
|
17
|
+
export { resolveValue as default };
|
package/dist/resolveValue.js
CHANGED
|
@@ -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
|
-
|
|
18
|
-
return value;
|
|
17
|
+
return isFunction(value) ? value(...arguments_) : value;
|
|
19
18
|
}
|
|
20
19
|
//#endregion
|
|
21
20
|
export { resolveValue as default, resolveValue };
|
package/dist/throttle.d.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
package/dist/uniqueId.d.ts
CHANGED
package/dist/utils/toPath.js
CHANGED
|
@@ -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 (
|
|
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)
|
|
39
|
-
index
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
else if (
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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);
|
package/dist/utils/toString.js
CHANGED
|
@@ -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
|
-
|
|
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
|
+
"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
|
+
}
|