@zag-js/utils 1.47.0 → 1.49.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.
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/assertClassBrand.js +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/assertClassBrand.mjs +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/checkPrivateRedeclaration.js +5 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/checkPrivateRedeclaration.mjs +5 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/classPrivateFieldGet2.js +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/classPrivateFieldGet2.mjs +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/classPrivateFieldInitSpec.js +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/classPrivateFieldInitSpec.mjs +6 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/defineProperty.js +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/defineProperty.mjs +11 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/toPrimitive.js +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/toPrimitive.mjs +13 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/toPropertyKey.js +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/toPropertyKey.mjs +8 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/typeof.js +15 -0
- package/dist/_virtual/_@oxc-project_runtime@0.159.0/helpers/esm/typeof.mjs +10 -0
- package/dist/array.d.mts +24 -26
- package/dist/array.d.ts +24 -26
- package/dist/array.js +76 -117
- package/dist/array.mjs +52 -74
- package/dist/equal.d.mts +1 -3
- package/dist/equal.d.ts +1 -3
- package/dist/equal.js +26 -60
- package/dist/equal.mjs +22 -37
- package/dist/functions.d.mts +13 -15
- package/dist/functions.d.ts +13 -15
- package/dist/functions.js +82 -121
- package/dist/functions.mjs +68 -88
- package/dist/guard.d.mts +12 -13
- package/dist/guard.d.ts +12 -13
- package/dist/guard.js +37 -70
- package/dist/guard.mjs +23 -37
- package/dist/index.d.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +101 -39
- package/dist/index.mjs +10 -10
- package/dist/number.d.mts +37 -38
- package/dist/number.d.ts +37 -38
- package/dist/number.js +136 -185
- package/dist/number.mjs +104 -134
- package/dist/object.d.mts +11 -16
- package/dist/object.d.ts +11 -16
- package/dist/object.js +52 -91
- package/dist/object.mjs +41 -61
- package/dist/store.d.mts +10 -12
- package/dist/store.d.ts +10 -12
- package/dist/store.js +42 -67
- package/dist/store.mjs +38 -44
- package/dist/timers.d.mts +21 -22
- package/dist/timers.d.ts +21 -22
- package/dist/timers.js +83 -112
- package/dist/timers.mjs +77 -83
- package/dist/warning.d.mts +7 -8
- package/dist/warning.d.ts +7 -8
- package/dist/warning.js +16 -51
- package/dist/warning.mjs +9 -25
- package/package.json +3 -3
- package/dist/chunk-MXGZDBDQ.mjs +0 -15
package/dist/equal.js
CHANGED
|
@@ -1,63 +1,29 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/equal.ts
|
|
21
|
-
var equal_exports = {};
|
|
22
|
-
__export(equal_exports, {
|
|
23
|
-
isEqual: () => isEqual
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
4
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
return true;
|
|
5
|
+
// src/equal.ts
|
|
6
|
+
const isArrayLike = (value) => value?.constructor.name === "Array";
|
|
7
|
+
const isArrayEqual = (a, b) => {
|
|
8
|
+
if (a.length !== b.length) return false;
|
|
9
|
+
for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
|
|
10
|
+
return true;
|
|
33
11
|
};
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (let i = 0; i < length; i++) {
|
|
51
|
-
const hasKey = Reflect.has(a, keys[i]);
|
|
52
|
-
if (!hasKey) return false;
|
|
53
|
-
}
|
|
54
|
-
for (let i = 0; i < length; i++) {
|
|
55
|
-
const key = keys[i];
|
|
56
|
-
if (!isEqual(a[key], b[key])) return false;
|
|
57
|
-
}
|
|
58
|
-
return true;
|
|
12
|
+
const isEqual = (a, b) => {
|
|
13
|
+
if (Object.is(a, b)) return true;
|
|
14
|
+
if (a == null && b != null || a != null && b == null) return false;
|
|
15
|
+
if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") return a.isEqual(b);
|
|
16
|
+
if (typeof a === "function" && typeof b === "function") return a.toString() === b.toString();
|
|
17
|
+
if (isArrayLike(a) && isArrayLike(b)) return isArrayEqual(Array.from(a), Array.from(b));
|
|
18
|
+
if (!(typeof a === "object") || !(typeof b === "object")) return false;
|
|
19
|
+
const keys = Object.keys(b ?? Object.create(null));
|
|
20
|
+
const length = keys.length;
|
|
21
|
+
if (Object.keys(a).length !== length) return false;
|
|
22
|
+
for (let i = 0; i < length; i++) if (!Reflect.has(a, keys[i])) return false;
|
|
23
|
+
for (let i = 0; i < length; i++) {
|
|
24
|
+
const key = keys[i];
|
|
25
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
59
28
|
};
|
|
60
|
-
|
|
61
|
-
0 && (module.exports = {
|
|
62
|
-
isEqual
|
|
63
|
-
});
|
|
29
|
+
exports.isEqual = isEqual;
|
package/dist/equal.mjs
CHANGED
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
import "./chunk-MXGZDBDQ.mjs";
|
|
2
|
-
|
|
3
1
|
// src/equal.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
return true;
|
|
2
|
+
const isArrayLike = (value) => value?.constructor.name === "Array";
|
|
3
|
+
const isArrayEqual = (a, b) => {
|
|
4
|
+
if (a.length !== b.length) return false;
|
|
5
|
+
for (let i = 0; i < a.length; i++) if (!isEqual(a[i], b[i])) return false;
|
|
6
|
+
return true;
|
|
11
7
|
};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
for (let i = 0; i < length; i++) {
|
|
29
|
-
const hasKey = Reflect.has(a, keys[i]);
|
|
30
|
-
if (!hasKey) return false;
|
|
31
|
-
}
|
|
32
|
-
for (let i = 0; i < length; i++) {
|
|
33
|
-
const key = keys[i];
|
|
34
|
-
if (!isEqual(a[key], b[key])) return false;
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
};
|
|
38
|
-
export {
|
|
39
|
-
isEqual
|
|
8
|
+
const isEqual = (a, b) => {
|
|
9
|
+
if (Object.is(a, b)) return true;
|
|
10
|
+
if (a == null && b != null || a != null && b == null) return false;
|
|
11
|
+
if (typeof a?.isEqual === "function" && typeof b?.isEqual === "function") return a.isEqual(b);
|
|
12
|
+
if (typeof a === "function" && typeof b === "function") return a.toString() === b.toString();
|
|
13
|
+
if (isArrayLike(a) && isArrayLike(b)) return isArrayEqual(Array.from(a), Array.from(b));
|
|
14
|
+
if (!(typeof a === "object") || !(typeof b === "object")) return false;
|
|
15
|
+
const keys = Object.keys(b ?? Object.create(null));
|
|
16
|
+
const length = keys.length;
|
|
17
|
+
if (Object.keys(a).length !== length) return false;
|
|
18
|
+
for (let i = 0; i < length; i++) if (!Reflect.has(a, keys[i])) return false;
|
|
19
|
+
for (let i = 0; i < length; i++) {
|
|
20
|
+
const key = keys[i];
|
|
21
|
+
if (!isEqual(a[key], b[key])) return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
40
24
|
};
|
|
25
|
+
export { isEqual };
|
package/dist/functions.d.mts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
type MaybeFunction<T> = T | (() => T);
|
|
2
|
-
type Nullable<T> = T | null | undefined;
|
|
3
|
-
declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
|
|
4
|
-
declare const cast: <T>(v: unknown) => T;
|
|
5
|
-
declare const identity: (v: VoidFunction) => void;
|
|
6
|
-
declare const noop: () => void;
|
|
7
|
-
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
|
|
8
|
-
declare const uuid: () => string;
|
|
9
|
-
declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
|
|
10
|
-
declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
|
|
11
|
-
declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
12
|
-
declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
13
|
-
declare const hash: (value: string) => string;
|
|
14
|
-
|
|
15
|
-
export { type MaybeFunction, type Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid };
|
|
1
|
+
export type MaybeFunction<T> = T | (() => T);
|
|
2
|
+
export type Nullable<T> = T | null | undefined;
|
|
3
|
+
export declare const runIfFn: <T>(v: T | undefined, ...a: T extends ((...a: any[]) => void) ? Parameters<T> : never) => T extends ((...a: any[]) => void) ? NonNullable<ReturnType<T>> : NonNullable<T>;
|
|
4
|
+
export declare const cast: <T>(v: unknown) => T;
|
|
5
|
+
export declare const identity: (v: VoidFunction) => void;
|
|
6
|
+
export declare const noop: () => void;
|
|
7
|
+
export declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
|
|
8
|
+
export declare const uuid: () => string;
|
|
9
|
+
export declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
|
|
10
|
+
export declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
|
|
11
|
+
export declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
12
|
+
export declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
13
|
+
export declare const hash: (value: string) => string;
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
type MaybeFunction<T> = T | (() => T);
|
|
2
|
-
type Nullable<T> = T | null | undefined;
|
|
3
|
-
declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
|
|
4
|
-
declare const cast: <T>(v: unknown) => T;
|
|
5
|
-
declare const identity: (v: VoidFunction) => void;
|
|
6
|
-
declare const noop: () => void;
|
|
7
|
-
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
|
|
8
|
-
declare const uuid: () => string;
|
|
9
|
-
declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
|
|
10
|
-
declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
|
|
11
|
-
declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
12
|
-
declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
13
|
-
declare const hash: (value: string) => string;
|
|
14
|
-
|
|
15
|
-
export { type MaybeFunction, type Nullable, callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid };
|
|
1
|
+
export type MaybeFunction<T> = T | (() => T);
|
|
2
|
+
export type Nullable<T> = T | null | undefined;
|
|
3
|
+
export declare const runIfFn: <T>(v: T | undefined, ...a: T extends ((...a: any[]) => void) ? Parameters<T> : never) => T extends ((...a: any[]) => void) ? NonNullable<ReturnType<T>> : NonNullable<T>;
|
|
4
|
+
export declare const cast: <T>(v: unknown) => T;
|
|
5
|
+
export declare const identity: (v: VoidFunction) => void;
|
|
6
|
+
export declare const noop: () => void;
|
|
7
|
+
export declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
|
|
8
|
+
export declare const uuid: () => string;
|
|
9
|
+
export declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
|
|
10
|
+
export declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
|
|
11
|
+
export declare function throttle<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
12
|
+
export declare function debounce<T extends (...args: any[]) => void>(fn: T, wait?: number): T;
|
|
13
|
+
export declare const hash: (value: string) => string;
|
package/dist/functions.js
CHANGED
|
@@ -1,136 +1,97 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/functions.ts
|
|
21
|
-
var functions_exports = {};
|
|
22
|
-
__export(functions_exports, {
|
|
23
|
-
callAll: () => callAll,
|
|
24
|
-
cast: () => cast,
|
|
25
|
-
debounce: () => debounce,
|
|
26
|
-
hash: () => hash,
|
|
27
|
-
identity: () => identity,
|
|
28
|
-
match: () => match,
|
|
29
|
-
noop: () => noop,
|
|
30
|
-
runIfFn: () => runIfFn,
|
|
31
|
-
throttle: () => throttle,
|
|
32
|
-
tryCatch: () => tryCatch,
|
|
33
|
-
uuid: () => uuid
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
return res ?? void 0;
|
|
40
|
-
};
|
|
41
|
-
var cast = (v) => v;
|
|
42
|
-
var identity = (v) => v();
|
|
43
|
-
var noop = () => {
|
|
5
|
+
const require_guard = require("./guard.js");
|
|
6
|
+
// src/functions.ts
|
|
7
|
+
const runIfFn = (v, ...a) => {
|
|
8
|
+
return (typeof v === "function" ? v(...a) : v) ?? void 0;
|
|
44
9
|
};
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
10
|
+
const cast = (v) => v;
|
|
11
|
+
const identity = (v) => v();
|
|
12
|
+
const noop = () => {};
|
|
13
|
+
const callAll = (...fns) => (...a) => {
|
|
14
|
+
fns.forEach(function(fn) {
|
|
15
|
+
fn?.(...a);
|
|
16
|
+
});
|
|
49
17
|
};
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
18
|
+
const uuid = /*#__PURE__*/ (() => {
|
|
19
|
+
let id = 0;
|
|
20
|
+
return () => {
|
|
21
|
+
id++;
|
|
22
|
+
return id.toString(36);
|
|
23
|
+
};
|
|
56
24
|
})();
|
|
57
25
|
function match(key, record, ...args) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
26
|
+
if (key in record) {
|
|
27
|
+
const fn = record[key];
|
|
28
|
+
return require_guard.isFunction(fn) ? fn(...args) : fn;
|
|
29
|
+
}
|
|
30
|
+
const error = /* @__PURE__ */ new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
|
|
31
|
+
Error.captureStackTrace?.(error, match);
|
|
32
|
+
throw error;
|
|
65
33
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return fallback?.();
|
|
74
|
-
}
|
|
34
|
+
const tryCatch = (fn, fallback) => {
|
|
35
|
+
try {
|
|
36
|
+
return fn();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (error instanceof Error) Error.captureStackTrace?.(error, tryCatch);
|
|
39
|
+
return fallback?.();
|
|
40
|
+
}
|
|
75
41
|
};
|
|
76
42
|
function throttle(fn, wait = 0) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
});
|
|
43
|
+
let lastCall = 0;
|
|
44
|
+
let timeout = null;
|
|
45
|
+
return ((...args) => {
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
const timeSinceLastCall = now - lastCall;
|
|
48
|
+
if (timeSinceLastCall >= wait) {
|
|
49
|
+
if (timeout) {
|
|
50
|
+
clearTimeout(timeout);
|
|
51
|
+
timeout = null;
|
|
52
|
+
}
|
|
53
|
+
fn(...args);
|
|
54
|
+
lastCall = now;
|
|
55
|
+
} else if (!timeout) timeout = setTimeout(() => {
|
|
56
|
+
fn(...args);
|
|
57
|
+
lastCall = Date.now();
|
|
58
|
+
timeout = null;
|
|
59
|
+
}, wait - timeSinceLastCall);
|
|
60
|
+
});
|
|
97
61
|
}
|
|
98
62
|
function debounce(fn, wait = 0) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
63
|
+
let timeout = null;
|
|
64
|
+
return ((...args) => {
|
|
65
|
+
if (timeout) {
|
|
66
|
+
clearTimeout(timeout);
|
|
67
|
+
timeout = null;
|
|
68
|
+
}
|
|
69
|
+
timeout = setTimeout(() => {
|
|
70
|
+
fn(...args);
|
|
71
|
+
}, wait);
|
|
72
|
+
});
|
|
109
73
|
}
|
|
110
|
-
|
|
74
|
+
const toChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
111
75
|
function toName(code) {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
76
|
+
let name = "";
|
|
77
|
+
let x;
|
|
78
|
+
for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
|
|
79
|
+
return toChar(x % 52) + name;
|
|
116
80
|
}
|
|
117
81
|
function toPhash(h, x) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
82
|
+
let i = x.length;
|
|
83
|
+
while (i) h = h * 33 ^ x.charCodeAt(--i);
|
|
84
|
+
return h;
|
|
121
85
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
tryCatch,
|
|
135
|
-
uuid
|
|
136
|
-
});
|
|
86
|
+
const hash = (value) => toName(toPhash(5381, value) >>> 0);
|
|
87
|
+
exports.callAll = callAll;
|
|
88
|
+
exports.cast = cast;
|
|
89
|
+
exports.debounce = debounce;
|
|
90
|
+
exports.hash = hash;
|
|
91
|
+
exports.identity = identity;
|
|
92
|
+
exports.match = match;
|
|
93
|
+
exports.noop = noop;
|
|
94
|
+
exports.runIfFn = runIfFn;
|
|
95
|
+
exports.throttle = throttle;
|
|
96
|
+
exports.tryCatch = tryCatch;
|
|
97
|
+
exports.uuid = uuid;
|
package/dist/functions.mjs
CHANGED
|
@@ -1,103 +1,83 @@
|
|
|
1
|
-
import "./chunk-MXGZDBDQ.mjs";
|
|
2
|
-
|
|
3
|
-
// src/functions.ts
|
|
4
1
|
import { isFunction } from "./guard.mjs";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
};
|
|
9
|
-
var cast = (v) => v;
|
|
10
|
-
var identity = (v) => v();
|
|
11
|
-
var noop = () => {
|
|
2
|
+
// src/functions.ts
|
|
3
|
+
const runIfFn = (v, ...a) => {
|
|
4
|
+
return (typeof v === "function" ? v(...a) : v) ?? void 0;
|
|
12
5
|
};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
const cast = (v) => v;
|
|
7
|
+
const identity = (v) => v();
|
|
8
|
+
const noop = () => {};
|
|
9
|
+
const callAll = (...fns) => (...a) => {
|
|
10
|
+
fns.forEach(function(fn) {
|
|
11
|
+
fn?.(...a);
|
|
12
|
+
});
|
|
17
13
|
};
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
const uuid = /*#__PURE__*/ (() => {
|
|
15
|
+
let id = 0;
|
|
16
|
+
return () => {
|
|
17
|
+
id++;
|
|
18
|
+
return id.toString(36);
|
|
19
|
+
};
|
|
24
20
|
})();
|
|
25
21
|
function match(key, record, ...args) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
22
|
+
if (key in record) {
|
|
23
|
+
const fn = record[key];
|
|
24
|
+
return isFunction(fn) ? fn(...args) : fn;
|
|
25
|
+
}
|
|
26
|
+
const error = /* @__PURE__ */ new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
|
|
27
|
+
Error.captureStackTrace?.(error, match);
|
|
28
|
+
throw error;
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
return fallback?.();
|
|
42
|
-
}
|
|
30
|
+
const tryCatch = (fn, fallback) => {
|
|
31
|
+
try {
|
|
32
|
+
return fn();
|
|
33
|
+
} catch (error) {
|
|
34
|
+
if (error instanceof Error) Error.captureStackTrace?.(error, tryCatch);
|
|
35
|
+
return fallback?.();
|
|
36
|
+
}
|
|
43
37
|
};
|
|
44
38
|
function throttle(fn, wait = 0) {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
});
|
|
39
|
+
let lastCall = 0;
|
|
40
|
+
let timeout = null;
|
|
41
|
+
return ((...args) => {
|
|
42
|
+
const now = Date.now();
|
|
43
|
+
const timeSinceLastCall = now - lastCall;
|
|
44
|
+
if (timeSinceLastCall >= wait) {
|
|
45
|
+
if (timeout) {
|
|
46
|
+
clearTimeout(timeout);
|
|
47
|
+
timeout = null;
|
|
48
|
+
}
|
|
49
|
+
fn(...args);
|
|
50
|
+
lastCall = now;
|
|
51
|
+
} else if (!timeout) timeout = setTimeout(() => {
|
|
52
|
+
fn(...args);
|
|
53
|
+
lastCall = Date.now();
|
|
54
|
+
timeout = null;
|
|
55
|
+
}, wait - timeSinceLastCall);
|
|
56
|
+
});
|
|
65
57
|
}
|
|
66
58
|
function debounce(fn, wait = 0) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
59
|
+
let timeout = null;
|
|
60
|
+
return ((...args) => {
|
|
61
|
+
if (timeout) {
|
|
62
|
+
clearTimeout(timeout);
|
|
63
|
+
timeout = null;
|
|
64
|
+
}
|
|
65
|
+
timeout = setTimeout(() => {
|
|
66
|
+
fn(...args);
|
|
67
|
+
}, wait);
|
|
68
|
+
});
|
|
77
69
|
}
|
|
78
|
-
|
|
70
|
+
const toChar = (code) => String.fromCharCode(code + (code > 25 ? 39 : 97));
|
|
79
71
|
function toName(code) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
let name = "";
|
|
73
|
+
let x;
|
|
74
|
+
for (x = Math.abs(code); x > 52; x = x / 52 | 0) name = toChar(x % 52) + name;
|
|
75
|
+
return toChar(x % 52) + name;
|
|
84
76
|
}
|
|
85
77
|
function toPhash(h, x) {
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
78
|
+
let i = x.length;
|
|
79
|
+
while (i) h = h * 33 ^ x.charCodeAt(--i);
|
|
80
|
+
return h;
|
|
89
81
|
}
|
|
90
|
-
|
|
91
|
-
export {
|
|
92
|
-
callAll,
|
|
93
|
-
cast,
|
|
94
|
-
debounce,
|
|
95
|
-
hash,
|
|
96
|
-
identity,
|
|
97
|
-
match,
|
|
98
|
-
noop,
|
|
99
|
-
runIfFn,
|
|
100
|
-
throttle,
|
|
101
|
-
tryCatch,
|
|
102
|
-
uuid
|
|
103
|
-
};
|
|
82
|
+
const hash = (value) => toName(toPhash(5381, value) >>> 0);
|
|
83
|
+
export { callAll, cast, debounce, hash, identity, match, noop, runIfFn, throttle, tryCatch, uuid };
|
package/dist/guard.d.mts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
type AnyFunction = (...args: any[]) => any;
|
|
2
|
-
declare const isDev: () => boolean;
|
|
3
|
-
declare const isArray: (v: any) => v is any[];
|
|
4
|
-
declare const isBoolean: (v: any) => v is boolean;
|
|
5
|
-
declare const isObjectLike: (v: any) => v is Record<string, any>;
|
|
6
|
-
declare const isObject: (v: any) => v is Record<string, any>;
|
|
7
|
-
declare const isNumber: (v: any) => v is number;
|
|
8
|
-
declare const isString: (v: any) => v is string;
|
|
9
|
-
declare const isFunction: (v: any) => v is AnyFunction;
|
|
10
|
-
declare const isNull: (v: any) => v is null | undefined;
|
|
11
|
-
declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
12
|
-
declare const isPlainObject: (v: any) => boolean;
|
|
13
|
-
|
|
14
|
-
export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString };
|
|
2
|
+
export declare const isDev: () => boolean;
|
|
3
|
+
export declare const isArray: (v: any) => v is any[];
|
|
4
|
+
export declare const isBoolean: (v: any) => v is boolean;
|
|
5
|
+
export declare const isObjectLike: (v: any) => v is Record<string, any>;
|
|
6
|
+
export declare const isObject: (v: any) => v is Record<string, any>;
|
|
7
|
+
export declare const isNumber: (v: any) => v is number;
|
|
8
|
+
export declare const isString: (v: any) => v is string;
|
|
9
|
+
export declare const isFunction: (v: any) => v is AnyFunction;
|
|
10
|
+
export declare const isNull: (v: any) => v is null | undefined;
|
|
11
|
+
export declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
12
|
+
export declare const isPlainObject: (v: any) => boolean;
|
|
13
|
+
export {};
|