@zag-js/utils 0.3.1 → 0.3.3
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.ts +21 -0
- package/dist/array.js +112 -0
- package/dist/array.mjs +34 -0
- package/dist/chunk-27EXK2DH.mjs +74 -0
- package/dist/chunk-7DKPTIZF.mjs +20 -0
- package/dist/chunk-FZD3QLPB.mjs +20 -0
- package/dist/chunk-JEERFXPQ.mjs +20 -0
- package/dist/chunk-YKQM3BDH.mjs +28 -0
- package/dist/functions.d.ts +7 -0
- package/dist/functions.js +56 -0
- package/dist/functions.mjs +14 -0
- package/dist/guard.d.ts +10 -0
- package/dist/guard.js +51 -0
- package/dist/guard.mjs +20 -0
- package/dist/index.d.ts +5 -44
- package/dist/index.js +3 -4
- package/dist/index.mjs +42 -116
- package/dist/object.d.ts +4 -0
- package/dist/object.js +47 -0
- package/dist/object.mjs +9 -0
- package/dist/warning.d.ts +6 -0
- package/dist/warning.js +45 -0
- package/dist/warning.mjs +8 -0
- package/package.json +18 -6
package/dist/array.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare function toArray<T>(v: T | T[] | undefined | null): T[];
|
|
2
|
+
declare const fromLength: (length: number) => number[];
|
|
3
|
+
declare const first: <T>(v: T[]) => T | undefined;
|
|
4
|
+
declare const last: <T>(v: T[]) => T | undefined;
|
|
5
|
+
declare const isEmpty: <T>(v: T[]) => boolean;
|
|
6
|
+
declare const has: <T>(v: T[], t: any) => boolean;
|
|
7
|
+
declare const add: <T>(v: T[], ...items: T[]) => T[];
|
|
8
|
+
declare const remove: <T>(v: T[], item: T) => T[];
|
|
9
|
+
declare const removeAt: <T>(v: T[], i: number) => T[];
|
|
10
|
+
declare function clear<T>(v: T[]): T[];
|
|
11
|
+
type IndexOptions = {
|
|
12
|
+
step?: number;
|
|
13
|
+
loop?: boolean;
|
|
14
|
+
};
|
|
15
|
+
declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
|
|
16
|
+
declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
|
|
17
|
+
declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
|
|
18
|
+
declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
|
|
19
|
+
declare const chunk: <T>(v: T[], size: number) => T[][];
|
|
20
|
+
|
|
21
|
+
export { IndexOptions, add, chunk, clear, first, fromLength, has, isEmpty, last, next, nextIndex, prev, prevIndex, remove, removeAt, toArray };
|
package/dist/array.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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/array.ts
|
|
21
|
+
var array_exports = {};
|
|
22
|
+
__export(array_exports, {
|
|
23
|
+
add: () => add,
|
|
24
|
+
chunk: () => chunk,
|
|
25
|
+
clear: () => clear,
|
|
26
|
+
first: () => first,
|
|
27
|
+
fromLength: () => fromLength,
|
|
28
|
+
has: () => has,
|
|
29
|
+
isEmpty: () => isEmpty,
|
|
30
|
+
last: () => last,
|
|
31
|
+
next: () => next,
|
|
32
|
+
nextIndex: () => nextIndex,
|
|
33
|
+
prev: () => prev,
|
|
34
|
+
prevIndex: () => prevIndex,
|
|
35
|
+
remove: () => remove,
|
|
36
|
+
removeAt: () => removeAt,
|
|
37
|
+
toArray: () => toArray
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(array_exports);
|
|
40
|
+
function toArray(v) {
|
|
41
|
+
if (!v)
|
|
42
|
+
return [];
|
|
43
|
+
return Array.isArray(v) ? v : [v];
|
|
44
|
+
}
|
|
45
|
+
var fromLength = (length) => Array.from(Array(length).keys());
|
|
46
|
+
var first = (v) => v[0];
|
|
47
|
+
var last = (v) => v[v.length - 1];
|
|
48
|
+
var isEmpty = (v) => v.length === 0;
|
|
49
|
+
var has = (v, t) => v.indexOf(t) !== -1;
|
|
50
|
+
var add = (v, ...items) => v.concat(items);
|
|
51
|
+
var remove = (v, item) => removeAt(v, v.indexOf(item));
|
|
52
|
+
var removeAt = (v, i) => {
|
|
53
|
+
if (i > -1)
|
|
54
|
+
v.splice(i, 1);
|
|
55
|
+
return v;
|
|
56
|
+
};
|
|
57
|
+
function clear(v) {
|
|
58
|
+
while (v.length > 0)
|
|
59
|
+
v.pop();
|
|
60
|
+
return v;
|
|
61
|
+
}
|
|
62
|
+
function nextIndex(v, idx, opts = {}) {
|
|
63
|
+
const { step = 1, loop = true } = opts;
|
|
64
|
+
const next2 = idx + step;
|
|
65
|
+
const len = v.length;
|
|
66
|
+
const last2 = len - 1;
|
|
67
|
+
if (idx === -1)
|
|
68
|
+
return step > 0 ? 0 : last2;
|
|
69
|
+
if (next2 < 0)
|
|
70
|
+
return loop ? last2 : 0;
|
|
71
|
+
if (next2 >= len)
|
|
72
|
+
return loop ? 0 : idx > len ? len : idx;
|
|
73
|
+
return next2;
|
|
74
|
+
}
|
|
75
|
+
function next(v, idx, opts = {}) {
|
|
76
|
+
return v[nextIndex(v, idx, opts)];
|
|
77
|
+
}
|
|
78
|
+
function prevIndex(v, idx, opts = {}) {
|
|
79
|
+
const { step = 1, loop = true } = opts;
|
|
80
|
+
return nextIndex(v, idx, { step: -step, loop });
|
|
81
|
+
}
|
|
82
|
+
function prev(v, index, opts = {}) {
|
|
83
|
+
return v[prevIndex(v, index, opts)];
|
|
84
|
+
}
|
|
85
|
+
var chunk = (v, size) => {
|
|
86
|
+
const res = [];
|
|
87
|
+
return v.reduce((rows, value, index) => {
|
|
88
|
+
if (index % size === 0)
|
|
89
|
+
rows.push([value]);
|
|
90
|
+
else
|
|
91
|
+
last(rows)?.push(value);
|
|
92
|
+
return rows;
|
|
93
|
+
}, res);
|
|
94
|
+
};
|
|
95
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
96
|
+
0 && (module.exports = {
|
|
97
|
+
add,
|
|
98
|
+
chunk,
|
|
99
|
+
clear,
|
|
100
|
+
first,
|
|
101
|
+
fromLength,
|
|
102
|
+
has,
|
|
103
|
+
isEmpty,
|
|
104
|
+
last,
|
|
105
|
+
next,
|
|
106
|
+
nextIndex,
|
|
107
|
+
prev,
|
|
108
|
+
prevIndex,
|
|
109
|
+
remove,
|
|
110
|
+
removeAt,
|
|
111
|
+
toArray
|
|
112
|
+
});
|
package/dist/array.mjs
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
add,
|
|
3
|
+
chunk,
|
|
4
|
+
clear,
|
|
5
|
+
first,
|
|
6
|
+
fromLength,
|
|
7
|
+
has,
|
|
8
|
+
isEmpty,
|
|
9
|
+
last,
|
|
10
|
+
next,
|
|
11
|
+
nextIndex,
|
|
12
|
+
prev,
|
|
13
|
+
prevIndex,
|
|
14
|
+
remove,
|
|
15
|
+
removeAt,
|
|
16
|
+
toArray
|
|
17
|
+
} from "./chunk-27EXK2DH.mjs";
|
|
18
|
+
export {
|
|
19
|
+
add,
|
|
20
|
+
chunk,
|
|
21
|
+
clear,
|
|
22
|
+
first,
|
|
23
|
+
fromLength,
|
|
24
|
+
has,
|
|
25
|
+
isEmpty,
|
|
26
|
+
last,
|
|
27
|
+
next,
|
|
28
|
+
nextIndex,
|
|
29
|
+
prev,
|
|
30
|
+
prevIndex,
|
|
31
|
+
remove,
|
|
32
|
+
removeAt,
|
|
33
|
+
toArray
|
|
34
|
+
};
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/array.ts
|
|
2
|
+
function toArray(v) {
|
|
3
|
+
if (!v)
|
|
4
|
+
return [];
|
|
5
|
+
return Array.isArray(v) ? v : [v];
|
|
6
|
+
}
|
|
7
|
+
var fromLength = (length) => Array.from(Array(length).keys());
|
|
8
|
+
var first = (v) => v[0];
|
|
9
|
+
var last = (v) => v[v.length - 1];
|
|
10
|
+
var isEmpty = (v) => v.length === 0;
|
|
11
|
+
var has = (v, t) => v.indexOf(t) !== -1;
|
|
12
|
+
var add = (v, ...items) => v.concat(items);
|
|
13
|
+
var remove = (v, item) => removeAt(v, v.indexOf(item));
|
|
14
|
+
var removeAt = (v, i) => {
|
|
15
|
+
if (i > -1)
|
|
16
|
+
v.splice(i, 1);
|
|
17
|
+
return v;
|
|
18
|
+
};
|
|
19
|
+
function clear(v) {
|
|
20
|
+
while (v.length > 0)
|
|
21
|
+
v.pop();
|
|
22
|
+
return v;
|
|
23
|
+
}
|
|
24
|
+
function nextIndex(v, idx, opts = {}) {
|
|
25
|
+
const { step = 1, loop = true } = opts;
|
|
26
|
+
const next2 = idx + step;
|
|
27
|
+
const len = v.length;
|
|
28
|
+
const last2 = len - 1;
|
|
29
|
+
if (idx === -1)
|
|
30
|
+
return step > 0 ? 0 : last2;
|
|
31
|
+
if (next2 < 0)
|
|
32
|
+
return loop ? last2 : 0;
|
|
33
|
+
if (next2 >= len)
|
|
34
|
+
return loop ? 0 : idx > len ? len : idx;
|
|
35
|
+
return next2;
|
|
36
|
+
}
|
|
37
|
+
function next(v, idx, opts = {}) {
|
|
38
|
+
return v[nextIndex(v, idx, opts)];
|
|
39
|
+
}
|
|
40
|
+
function prevIndex(v, idx, opts = {}) {
|
|
41
|
+
const { step = 1, loop = true } = opts;
|
|
42
|
+
return nextIndex(v, idx, { step: -step, loop });
|
|
43
|
+
}
|
|
44
|
+
function prev(v, index, opts = {}) {
|
|
45
|
+
return v[prevIndex(v, index, opts)];
|
|
46
|
+
}
|
|
47
|
+
var chunk = (v, size) => {
|
|
48
|
+
const res = [];
|
|
49
|
+
return v.reduce((rows, value, index) => {
|
|
50
|
+
if (index % size === 0)
|
|
51
|
+
rows.push([value]);
|
|
52
|
+
else
|
|
53
|
+
last(rows)?.push(value);
|
|
54
|
+
return rows;
|
|
55
|
+
}, res);
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export {
|
|
59
|
+
toArray,
|
|
60
|
+
fromLength,
|
|
61
|
+
first,
|
|
62
|
+
last,
|
|
63
|
+
isEmpty,
|
|
64
|
+
has,
|
|
65
|
+
add,
|
|
66
|
+
remove,
|
|
67
|
+
removeAt,
|
|
68
|
+
clear,
|
|
69
|
+
nextIndex,
|
|
70
|
+
next,
|
|
71
|
+
prevIndex,
|
|
72
|
+
prev,
|
|
73
|
+
chunk
|
|
74
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isObject
|
|
3
|
+
} from "./chunk-FZD3QLPB.mjs";
|
|
4
|
+
|
|
5
|
+
// src/object.ts
|
|
6
|
+
function compact(obj) {
|
|
7
|
+
if (obj === void 0)
|
|
8
|
+
return obj;
|
|
9
|
+
return Object.fromEntries(
|
|
10
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function json(value) {
|
|
14
|
+
return JSON.parse(JSON.stringify(value));
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
compact,
|
|
19
|
+
json
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/guard.ts
|
|
2
|
+
var isDev = () => process.env.NODE_ENV !== "production";
|
|
3
|
+
var isArray = (v) => Array.isArray(v);
|
|
4
|
+
var isBoolean = (v) => v === true || v === false;
|
|
5
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
6
|
+
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
7
|
+
var isString = (v) => typeof v === "string";
|
|
8
|
+
var isFunction = (v) => typeof v === "function";
|
|
9
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
isDev,
|
|
13
|
+
isArray,
|
|
14
|
+
isBoolean,
|
|
15
|
+
isObject,
|
|
16
|
+
isNumber,
|
|
17
|
+
isString,
|
|
18
|
+
isFunction,
|
|
19
|
+
hasProp
|
|
20
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/warning.ts
|
|
2
|
+
function warn(...a) {
|
|
3
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
4
|
+
const c = a.length === 2 ? a[0] : true;
|
|
5
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
6
|
+
console.warn(m);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
function invariant(...a) {
|
|
10
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
11
|
+
const c = a.length === 2 ? a[0] : true;
|
|
12
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
13
|
+
throw new Error(m);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
warn,
|
|
19
|
+
invariant
|
|
20
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/functions.ts
|
|
2
|
+
var runIfFn = (v, ...a) => {
|
|
3
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
4
|
+
return res ?? void 0;
|
|
5
|
+
};
|
|
6
|
+
var cast = (v) => v;
|
|
7
|
+
var noop = () => {
|
|
8
|
+
};
|
|
9
|
+
var callAll = (...fns) => (...a) => {
|
|
10
|
+
fns.forEach(function(fn) {
|
|
11
|
+
fn?.(...a);
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
var uuid = /* @__PURE__ */ (() => {
|
|
15
|
+
let id = 0;
|
|
16
|
+
return () => {
|
|
17
|
+
id++;
|
|
18
|
+
return id.toString(36);
|
|
19
|
+
};
|
|
20
|
+
})();
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
runIfFn,
|
|
24
|
+
cast,
|
|
25
|
+
noop,
|
|
26
|
+
callAll,
|
|
27
|
+
uuid
|
|
28
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
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>;
|
|
2
|
+
declare const cast: <T>(v: unknown) => T;
|
|
3
|
+
declare const noop: () => void;
|
|
4
|
+
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
|
|
5
|
+
declare const uuid: () => string;
|
|
6
|
+
|
|
7
|
+
export { callAll, cast, noop, runIfFn, uuid };
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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
|
+
noop: () => noop,
|
|
26
|
+
runIfFn: () => runIfFn,
|
|
27
|
+
uuid: () => uuid
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(functions_exports);
|
|
30
|
+
var runIfFn = (v, ...a) => {
|
|
31
|
+
const res = typeof v === "function" ? v(...a) : v;
|
|
32
|
+
return res ?? void 0;
|
|
33
|
+
};
|
|
34
|
+
var cast = (v) => v;
|
|
35
|
+
var noop = () => {
|
|
36
|
+
};
|
|
37
|
+
var callAll = (...fns) => (...a) => {
|
|
38
|
+
fns.forEach(function(fn) {
|
|
39
|
+
fn?.(...a);
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
var uuid = /* @__PURE__ */ (() => {
|
|
43
|
+
let id = 0;
|
|
44
|
+
return () => {
|
|
45
|
+
id++;
|
|
46
|
+
return id.toString(36);
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
callAll,
|
|
52
|
+
cast,
|
|
53
|
+
noop,
|
|
54
|
+
runIfFn,
|
|
55
|
+
uuid
|
|
56
|
+
});
|
package/dist/guard.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const isDev: () => boolean;
|
|
2
|
+
declare const isArray: (v: any) => v is any[];
|
|
3
|
+
declare const isBoolean: (v: any) => v is boolean;
|
|
4
|
+
declare const isObject: (v: any) => v is Record<string, any>;
|
|
5
|
+
declare const isNumber: (v: any) => v is number;
|
|
6
|
+
declare const isString: (v: any) => v is string;
|
|
7
|
+
declare const isFunction: (v: any) => v is Function;
|
|
8
|
+
declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
9
|
+
|
|
10
|
+
export { hasProp, isArray, isBoolean, isDev, isFunction, isNumber, isObject, isString };
|
package/dist/guard.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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
|
+
isNumber: () => isNumber,
|
|
29
|
+
isObject: () => isObject,
|
|
30
|
+
isString: () => isString
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(guard_exports);
|
|
33
|
+
var isDev = () => process.env.NODE_ENV !== "production";
|
|
34
|
+
var isArray = (v) => Array.isArray(v);
|
|
35
|
+
var isBoolean = (v) => v === true || v === false;
|
|
36
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
37
|
+
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
38
|
+
var isString = (v) => typeof v === "string";
|
|
39
|
+
var isFunction = (v) => typeof v === "function";
|
|
40
|
+
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
hasProp,
|
|
44
|
+
isArray,
|
|
45
|
+
isBoolean,
|
|
46
|
+
isDev,
|
|
47
|
+
isFunction,
|
|
48
|
+
isNumber,
|
|
49
|
+
isObject,
|
|
50
|
+
isString
|
|
51
|
+
});
|
package/dist/guard.mjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
hasProp,
|
|
3
|
+
isArray,
|
|
4
|
+
isBoolean,
|
|
5
|
+
isDev,
|
|
6
|
+
isFunction,
|
|
7
|
+
isNumber,
|
|
8
|
+
isObject,
|
|
9
|
+
isString
|
|
10
|
+
} from "./chunk-FZD3QLPB.mjs";
|
|
11
|
+
export {
|
|
12
|
+
hasProp,
|
|
13
|
+
isArray,
|
|
14
|
+
isBoolean,
|
|
15
|
+
isDev,
|
|
16
|
+
isFunction,
|
|
17
|
+
isNumber,
|
|
18
|
+
isObject,
|
|
19
|
+
isString
|
|
20
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const has: <T>(v: T[], t: any) => boolean;
|
|
7
|
-
declare const add: <T>(v: T[], ...items: T[]) => T[];
|
|
8
|
-
declare const remove: <T>(v: T[], item: T) => T[];
|
|
9
|
-
declare const removeAt: <T>(v: T[], i: number) => T[];
|
|
10
|
-
declare function clear<T>(v: T[]): T[];
|
|
11
|
-
declare type IndexOptions = {
|
|
12
|
-
step?: number;
|
|
13
|
-
loop?: boolean;
|
|
14
|
-
};
|
|
15
|
-
declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
|
|
16
|
-
declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
|
|
17
|
-
declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
|
|
18
|
-
declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
|
|
19
|
-
declare const chunk: <T>(v: T[], size: number) => T[][];
|
|
20
|
-
|
|
21
|
-
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>;
|
|
22
|
-
declare const cast: <T>(v: unknown) => T;
|
|
23
|
-
declare const noop: () => void;
|
|
24
|
-
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
|
|
25
|
-
declare const uuid: () => string;
|
|
26
|
-
|
|
27
|
-
declare const isDev: () => boolean;
|
|
28
|
-
declare const isArray: (v: any) => v is any[];
|
|
29
|
-
declare const isBoolean: (v: any) => v is boolean;
|
|
30
|
-
declare const isObject: (v: any) => v is Record<string, any>;
|
|
31
|
-
declare const isNumber: (v: any) => v is number;
|
|
32
|
-
declare const isString: (v: any) => v is string;
|
|
33
|
-
declare const isFunction: (v: any) => v is Function;
|
|
34
|
-
declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
35
|
-
|
|
36
|
-
declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
|
|
37
|
-
declare function json(value: any): any;
|
|
38
|
-
|
|
39
|
-
declare function warn(m: string): void;
|
|
40
|
-
declare function warn(c: boolean, m: string): void;
|
|
41
|
-
declare function invariant(m: string): void;
|
|
42
|
-
declare function invariant(c: boolean, m: string): void;
|
|
43
|
-
|
|
44
|
-
export { IndexOptions, add, callAll, cast, chunk, clear, compact, first, fromLength, has, hasProp, invariant, isArray, isBoolean, isDev, isEmpty, isFunction, isNumber, isObject, isString, json, last, next, nextIndex, noop, prev, prevIndex, remove, removeAt, runIfFn, toArray, uuid, warn };
|
|
1
|
+
export { IndexOptions, add, chunk, clear, first, fromLength, has, isEmpty, last, next, nextIndex, prev, prevIndex, remove, removeAt, toArray } from './array.js';
|
|
2
|
+
export { callAll, cast, noop, runIfFn, uuid } from './functions.js';
|
|
3
|
+
export { hasProp, isArray, isBoolean, isDev, isFunction, isNumber, isObject, isString } from './guard.js';
|
|
4
|
+
export { compact, json } from './object.js';
|
|
5
|
+
export { invariant, warn } from './warning.js';
|
package/dist/index.js
CHANGED
|
@@ -104,11 +104,10 @@ function prev(v, index, opts = {}) {
|
|
|
104
104
|
var chunk = (v, size) => {
|
|
105
105
|
const res = [];
|
|
106
106
|
return v.reduce((rows, value, index) => {
|
|
107
|
-
var _a;
|
|
108
107
|
if (index % size === 0)
|
|
109
108
|
rows.push([value]);
|
|
110
109
|
else
|
|
111
|
-
|
|
110
|
+
last(rows)?.push(value);
|
|
112
111
|
return rows;
|
|
113
112
|
}, res);
|
|
114
113
|
};
|
|
@@ -116,14 +115,14 @@ var chunk = (v, size) => {
|
|
|
116
115
|
// src/functions.ts
|
|
117
116
|
var runIfFn = (v, ...a) => {
|
|
118
117
|
const res = typeof v === "function" ? v(...a) : v;
|
|
119
|
-
return res
|
|
118
|
+
return res ?? void 0;
|
|
120
119
|
};
|
|
121
120
|
var cast = (v) => v;
|
|
122
121
|
var noop = () => {
|
|
123
122
|
};
|
|
124
123
|
var callAll = (...fns) => (...a) => {
|
|
125
124
|
fns.forEach(function(fn) {
|
|
126
|
-
fn
|
|
125
|
+
fn?.(...a);
|
|
127
126
|
});
|
|
128
127
|
};
|
|
129
128
|
var uuid = /* @__PURE__ */ (() => {
|
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,45 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
function prev(v, index, opts = {}) {
|
|
45
|
-
return v[prevIndex(v, index, opts)];
|
|
46
|
-
}
|
|
47
|
-
var chunk = (v, size) => {
|
|
48
|
-
const res = [];
|
|
49
|
-
return v.reduce((rows, value, index) => {
|
|
50
|
-
var _a;
|
|
51
|
-
if (index % size === 0)
|
|
52
|
-
rows.push([value]);
|
|
53
|
-
else
|
|
54
|
-
(_a = last(rows)) == null ? void 0 : _a.push(value);
|
|
55
|
-
return rows;
|
|
56
|
-
}, res);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
// src/functions.ts
|
|
60
|
-
var runIfFn = (v, ...a) => {
|
|
61
|
-
const res = typeof v === "function" ? v(...a) : v;
|
|
62
|
-
return res != null ? res : void 0;
|
|
63
|
-
};
|
|
64
|
-
var cast = (v) => v;
|
|
65
|
-
var noop = () => {
|
|
66
|
-
};
|
|
67
|
-
var callAll = (...fns) => (...a) => {
|
|
68
|
-
fns.forEach(function(fn) {
|
|
69
|
-
fn == null ? void 0 : fn(...a);
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
var uuid = /* @__PURE__ */ (() => {
|
|
73
|
-
let id = 0;
|
|
74
|
-
return () => {
|
|
75
|
-
id++;
|
|
76
|
-
return id.toString(36);
|
|
77
|
-
};
|
|
78
|
-
})();
|
|
79
|
-
|
|
80
|
-
// src/guard.ts
|
|
81
|
-
var isDev = () => process.env.NODE_ENV !== "production";
|
|
82
|
-
var isArray = (v) => Array.isArray(v);
|
|
83
|
-
var isBoolean = (v) => v === true || v === false;
|
|
84
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
85
|
-
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
86
|
-
var isString = (v) => typeof v === "string";
|
|
87
|
-
var isFunction = (v) => typeof v === "function";
|
|
88
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
89
|
-
|
|
90
|
-
// src/object.ts
|
|
91
|
-
function compact(obj) {
|
|
92
|
-
if (obj === void 0)
|
|
93
|
-
return obj;
|
|
94
|
-
return Object.fromEntries(
|
|
95
|
-
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
function json(value) {
|
|
99
|
-
return JSON.parse(JSON.stringify(value));
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// src/warning.ts
|
|
103
|
-
function warn(...a) {
|
|
104
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
105
|
-
const c = a.length === 2 ? a[0] : true;
|
|
106
|
-
if (c && process.env.NODE_ENV !== "production") {
|
|
107
|
-
console.warn(m);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function invariant(...a) {
|
|
111
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
112
|
-
const c = a.length === 2 ? a[0] : true;
|
|
113
|
-
if (c && process.env.NODE_ENV !== "production") {
|
|
114
|
-
throw new Error(m);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
add,
|
|
3
|
+
chunk,
|
|
4
|
+
clear,
|
|
5
|
+
first,
|
|
6
|
+
fromLength,
|
|
7
|
+
has,
|
|
8
|
+
isEmpty,
|
|
9
|
+
last,
|
|
10
|
+
next,
|
|
11
|
+
nextIndex,
|
|
12
|
+
prev,
|
|
13
|
+
prevIndex,
|
|
14
|
+
remove,
|
|
15
|
+
removeAt,
|
|
16
|
+
toArray
|
|
17
|
+
} from "./chunk-27EXK2DH.mjs";
|
|
18
|
+
import {
|
|
19
|
+
callAll,
|
|
20
|
+
cast,
|
|
21
|
+
noop,
|
|
22
|
+
runIfFn,
|
|
23
|
+
uuid
|
|
24
|
+
} from "./chunk-YKQM3BDH.mjs";
|
|
25
|
+
import {
|
|
26
|
+
compact,
|
|
27
|
+
json
|
|
28
|
+
} from "./chunk-7DKPTIZF.mjs";
|
|
29
|
+
import {
|
|
30
|
+
hasProp,
|
|
31
|
+
isArray,
|
|
32
|
+
isBoolean,
|
|
33
|
+
isDev,
|
|
34
|
+
isFunction,
|
|
35
|
+
isNumber,
|
|
36
|
+
isObject,
|
|
37
|
+
isString
|
|
38
|
+
} from "./chunk-FZD3QLPB.mjs";
|
|
39
|
+
import {
|
|
40
|
+
invariant,
|
|
41
|
+
warn
|
|
42
|
+
} from "./chunk-JEERFXPQ.mjs";
|
|
117
43
|
export {
|
|
118
44
|
add,
|
|
119
45
|
callAll,
|
package/dist/object.d.ts
ADDED
package/dist/object.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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/object.ts
|
|
21
|
+
var object_exports = {};
|
|
22
|
+
__export(object_exports, {
|
|
23
|
+
compact: () => compact,
|
|
24
|
+
json: () => json
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(object_exports);
|
|
27
|
+
|
|
28
|
+
// src/guard.ts
|
|
29
|
+
var isArray = (v) => Array.isArray(v);
|
|
30
|
+
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
31
|
+
|
|
32
|
+
// src/object.ts
|
|
33
|
+
function compact(obj) {
|
|
34
|
+
if (obj === void 0)
|
|
35
|
+
return obj;
|
|
36
|
+
return Object.fromEntries(
|
|
37
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function json(value) {
|
|
41
|
+
return JSON.parse(JSON.stringify(value));
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
compact,
|
|
46
|
+
json
|
|
47
|
+
});
|
package/dist/object.mjs
ADDED
package/dist/warning.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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/warning.ts
|
|
21
|
+
var warning_exports = {};
|
|
22
|
+
__export(warning_exports, {
|
|
23
|
+
invariant: () => invariant,
|
|
24
|
+
warn: () => warn
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(warning_exports);
|
|
27
|
+
function warn(...a) {
|
|
28
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
29
|
+
const c = a.length === 2 ? a[0] : true;
|
|
30
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
31
|
+
console.warn(m);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function invariant(...a) {
|
|
35
|
+
const m = a.length === 1 ? a[0] : a[1];
|
|
36
|
+
const c = a.length === 2 ? a[0] : true;
|
|
37
|
+
if (c && process.env.NODE_ENV !== "production") {
|
|
38
|
+
throw new Error(m);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
+
0 && (module.exports = {
|
|
43
|
+
invariant,
|
|
44
|
+
warn
|
|
45
|
+
});
|
package/dist/warning.mjs
ADDED
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/utils",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.3",
|
|
4
4
|
"description": "",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
5
|
"keywords": [
|
|
9
6
|
"js",
|
|
10
7
|
"utils",
|
|
@@ -24,10 +21,25 @@
|
|
|
24
21
|
"bugs": {
|
|
25
22
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
23
|
},
|
|
24
|
+
"clean-package": "../../../clean-package.config.json",
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"clean-package": "2.2.0"
|
|
28
|
+
},
|
|
29
|
+
"module": "dist/index.mjs",
|
|
30
|
+
"types": "dist/index.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"require": "./dist/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./package.json": "./package.json"
|
|
38
|
+
},
|
|
27
39
|
"scripts": {
|
|
28
|
-
"build-fast": "tsup src
|
|
40
|
+
"build-fast": "tsup src",
|
|
29
41
|
"start": "pnpm build --watch",
|
|
30
|
-
"build": "tsup src
|
|
42
|
+
"build": "tsup src --dts",
|
|
31
43
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
32
44
|
"lint": "eslint src --ext .ts,.tsx",
|
|
33
45
|
"test-ci": "pnpm test --ci --runInBand",
|