@zag-js/utils 2.0.0-next.2 → 2.0.0-next.4
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/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 -2
- package/dist/equal.d.ts +1 -2
- package/dist/equal.js +23 -46
- package/dist/equal.mjs +19 -23
- 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 -10
- package/dist/index.d.ts +10 -10
- package/dist/index.js +97 -41
- package/dist/index.mjs +9 -11
- package/dist/lifecycle.d.mts +2 -4
- package/dist/lifecycle.d.ts +2 -4
- package/dist/lifecycle.js +4 -18
- package/dist/lifecycle.mjs +1 -0
- 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/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 +2 -2
- package/dist/chunk-MXGZDBDQ.mjs +0 -15
- package/dist/timers.d.mts +0 -26
- package/dist/timers.d.ts +0 -26
- package/dist/timers.js +0 -119
- package/dist/timers.mjs +0 -90
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 {};
|
package/dist/guard.d.ts
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 {};
|
package/dist/guard.js
CHANGED
|
@@ -1,72 +1,39 @@
|
|
|
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/guard.ts
|
|
21
|
-
var guard_exports = {};
|
|
22
|
-
__export(guard_exports, {
|
|
23
|
-
hasProp: () => hasProp,
|
|
24
|
-
isArray: () => isArray,
|
|
25
|
-
isBoolean: () => isBoolean,
|
|
26
|
-
isDev: () => isDev,
|
|
27
|
-
isFunction: () => isFunction,
|
|
28
|
-
isNull: () => isNull,
|
|
29
|
-
isNumber: () => isNumber,
|
|
30
|
-
isObject: () => isObject,
|
|
31
|
-
isObjectLike: () => isObjectLike,
|
|
32
|
-
isPlainObject: () => isPlainObject,
|
|
33
|
-
isString: () => isString
|
|
1
|
+
Object.defineProperties(exports, {
|
|
2
|
+
__esModule: { value: true },
|
|
3
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
34
4
|
});
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
5
|
+
// src/guard.ts
|
|
6
|
+
const isDev = () => process.env.NODE_ENV !== "production";
|
|
7
|
+
const isArray = (v) => Array.isArray(v);
|
|
8
|
+
const isBoolean = (v) => v === true || v === false;
|
|
9
|
+
const isObjectLike = (v) => v != null && typeof v === "object";
|
|
10
|
+
const isObject = (v) => isObjectLike(v) && !isArray(v);
|
|
11
|
+
const isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
12
|
+
const isString = (v) => typeof v === "string";
|
|
13
|
+
const isFunction = (v) => typeof v === "function";
|
|
14
|
+
const isNull = (v) => v == null;
|
|
15
|
+
const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
16
|
+
const baseGetTag = (v) => Object.prototype.toString.call(v);
|
|
17
|
+
const fnToString = Function.prototype.toString;
|
|
18
|
+
const objectCtorString = fnToString.call(Object);
|
|
19
|
+
const isPlainObject = (v) => {
|
|
20
|
+
if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
|
|
21
|
+
const proto = Object.getPrototypeOf(v);
|
|
22
|
+
if (proto === null) return true;
|
|
23
|
+
const Ctor = hasProp(proto, "constructor") && proto.constructor;
|
|
24
|
+
return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
|
|
55
25
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
isPlainObject,
|
|
71
|
-
isString
|
|
72
|
-
});
|
|
26
|
+
const isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
|
|
27
|
+
const isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
|
|
28
|
+
const isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
|
|
29
|
+
exports.hasProp = hasProp;
|
|
30
|
+
exports.isArray = isArray;
|
|
31
|
+
exports.isBoolean = isBoolean;
|
|
32
|
+
exports.isDev = isDev;
|
|
33
|
+
exports.isFunction = isFunction;
|
|
34
|
+
exports.isNull = isNull;
|
|
35
|
+
exports.isNumber = isNumber;
|
|
36
|
+
exports.isObject = isObject;
|
|
37
|
+
exports.isObjectLike = isObjectLike;
|
|
38
|
+
exports.isPlainObject = isPlainObject;
|
|
39
|
+
exports.isString = isString;
|
package/dist/guard.mjs
CHANGED
|
@@ -1,39 +1,25 @@
|
|
|
1
|
-
import "./chunk-MXGZDBDQ.mjs";
|
|
2
|
-
|
|
3
1
|
// src/guard.ts
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
var isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
|
|
25
|
-
var isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
|
|
26
|
-
var isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
|
|
27
|
-
export {
|
|
28
|
-
hasProp,
|
|
29
|
-
isArray,
|
|
30
|
-
isBoolean,
|
|
31
|
-
isDev,
|
|
32
|
-
isFunction,
|
|
33
|
-
isNull,
|
|
34
|
-
isNumber,
|
|
35
|
-
isObject,
|
|
36
|
-
isObjectLike,
|
|
37
|
-
isPlainObject,
|
|
38
|
-
isString
|
|
2
|
+
const isDev = () => process.env.NODE_ENV !== "production";
|
|
3
|
+
const isArray = (v) => Array.isArray(v);
|
|
4
|
+
const isBoolean = (v) => v === true || v === false;
|
|
5
|
+
const isObjectLike = (v) => v != null && typeof v === "object";
|
|
6
|
+
const isObject = (v) => isObjectLike(v) && !isArray(v);
|
|
7
|
+
const isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
8
|
+
const isString = (v) => typeof v === "string";
|
|
9
|
+
const isFunction = (v) => typeof v === "function";
|
|
10
|
+
const isNull = (v) => v == null;
|
|
11
|
+
const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
12
|
+
const baseGetTag = (v) => Object.prototype.toString.call(v);
|
|
13
|
+
const fnToString = Function.prototype.toString;
|
|
14
|
+
const objectCtorString = fnToString.call(Object);
|
|
15
|
+
const isPlainObject = (v) => {
|
|
16
|
+
if (!isObjectLike(v) || baseGetTag(v) != "[object Object]" || isFrameworkElement(v)) return false;
|
|
17
|
+
const proto = Object.getPrototypeOf(v);
|
|
18
|
+
if (proto === null) return true;
|
|
19
|
+
const Ctor = hasProp(proto, "constructor") && proto.constructor;
|
|
20
|
+
return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
|
|
39
21
|
};
|
|
22
|
+
const isReactElement = (x) => typeof x === "object" && x !== null && "$$typeof" in x && "props" in x;
|
|
23
|
+
const isVueElement = (x) => typeof x === "object" && x !== null && "__v_isVNode" in x;
|
|
24
|
+
const isFrameworkElement = (x) => isReactElement(x) || isVueElement(x);
|
|
25
|
+
export { hasProp, isArray, isBoolean, isDev, isFunction, isNull, isNumber, isObject, isObjectLike, isPlainObject, isString };
|