@zag-js/utils 0.1.4 → 0.1.5
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/index.d.ts +1 -2
- package/dist/index.js +2 -76
- package/package.json +4 -4
- package/dist/index.mjs +0 -153
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,6 @@ declare const cast: <T>(v: unknown) => T;
|
|
|
23
23
|
declare const noop: () => void;
|
|
24
24
|
declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
|
|
25
25
|
declare const uuid: () => string;
|
|
26
|
-
declare function merge<T, U>(origin: T, patch: U): T & U;
|
|
27
26
|
|
|
28
27
|
declare const isDev: () => boolean;
|
|
29
28
|
declare const isArray: (v: any) => v is any[];
|
|
@@ -39,4 +38,4 @@ declare function warn(c: boolean, m: string): void;
|
|
|
39
38
|
declare function invariant(m: string): void;
|
|
40
39
|
declare function invariant(c: boolean, m: string): void;
|
|
41
40
|
|
|
42
|
-
export { IndexOptions, add, callAll, cast, chunk, clear, first, fromLength, has, hasProp, invariant, isArray, isBoolean, isDev, isEmpty, isFunction, isNumber, isObject, isString, last,
|
|
41
|
+
export { IndexOptions, add, callAll, cast, chunk, clear, first, fromLength, has, hasProp, invariant, isArray, isBoolean, isDev, isEmpty, isFunction, isNumber, isObject, isString, last, next, nextIndex, noop, prev, prevIndex, remove, removeAt, runIfFn, toArray, uuid, warn };
|
package/dist/index.js
CHANGED
|
@@ -1,59 +1,3 @@
|
|
|
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/index.ts
|
|
21
|
-
var src_exports = {};
|
|
22
|
-
__export(src_exports, {
|
|
23
|
-
add: () => add,
|
|
24
|
-
callAll: () => callAll,
|
|
25
|
-
cast: () => cast,
|
|
26
|
-
chunk: () => chunk,
|
|
27
|
-
clear: () => clear,
|
|
28
|
-
first: () => first,
|
|
29
|
-
fromLength: () => fromLength,
|
|
30
|
-
has: () => has,
|
|
31
|
-
hasProp: () => hasProp,
|
|
32
|
-
invariant: () => invariant,
|
|
33
|
-
isArray: () => isArray,
|
|
34
|
-
isBoolean: () => isBoolean,
|
|
35
|
-
isDev: () => isDev,
|
|
36
|
-
isEmpty: () => isEmpty,
|
|
37
|
-
isFunction: () => isFunction,
|
|
38
|
-
isNumber: () => isNumber,
|
|
39
|
-
isObject: () => isObject,
|
|
40
|
-
isString: () => isString,
|
|
41
|
-
last: () => last,
|
|
42
|
-
merge: () => merge,
|
|
43
|
-
next: () => next,
|
|
44
|
-
nextIndex: () => nextIndex,
|
|
45
|
-
noop: () => noop,
|
|
46
|
-
prev: () => prev,
|
|
47
|
-
prevIndex: () => prevIndex,
|
|
48
|
-
remove: () => remove,
|
|
49
|
-
removeAt: () => removeAt,
|
|
50
|
-
runIfFn: () => runIfFn,
|
|
51
|
-
toArray: () => toArray,
|
|
52
|
-
uuid: () => uuid,
|
|
53
|
-
warn: () => warn
|
|
54
|
-
});
|
|
55
|
-
module.exports = __toCommonJS(src_exports);
|
|
56
|
-
|
|
57
1
|
// src/array.ts
|
|
58
2
|
function toArray(v) {
|
|
59
3
|
if (!v)
|
|
@@ -132,22 +76,6 @@ var uuid = /* @__PURE__ */ (() => {
|
|
|
132
76
|
return id.toString(36);
|
|
133
77
|
};
|
|
134
78
|
})();
|
|
135
|
-
function merge(origin, patch) {
|
|
136
|
-
if (!(typeof patch === "object"))
|
|
137
|
-
return patch;
|
|
138
|
-
const result = !(typeof origin === "object") ? {} : Object.assign({}, origin);
|
|
139
|
-
for (const key of Object.keys(patch)) {
|
|
140
|
-
const value = patch[key];
|
|
141
|
-
const src = result[key];
|
|
142
|
-
if (value === null)
|
|
143
|
-
delete result[key];
|
|
144
|
-
else if (Array.isArray(value) || Array.isArray(src))
|
|
145
|
-
result[key] = (src || []).concat(value || []);
|
|
146
|
-
else
|
|
147
|
-
result[key] = merge(src, value);
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
150
|
-
}
|
|
151
79
|
|
|
152
80
|
// src/guard.ts
|
|
153
81
|
var isDev = () => process.env.NODE_ENV !== "production";
|
|
@@ -174,8 +102,7 @@ function invariant(...a) {
|
|
|
174
102
|
throw new Error(m);
|
|
175
103
|
}
|
|
176
104
|
}
|
|
177
|
-
|
|
178
|
-
0 && (module.exports = {
|
|
105
|
+
export {
|
|
179
106
|
add,
|
|
180
107
|
callAll,
|
|
181
108
|
cast,
|
|
@@ -195,7 +122,6 @@ function invariant(...a) {
|
|
|
195
122
|
isObject,
|
|
196
123
|
isString,
|
|
197
124
|
last,
|
|
198
|
-
merge,
|
|
199
125
|
next,
|
|
200
126
|
nextIndex,
|
|
201
127
|
noop,
|
|
@@ -207,4 +133,4 @@ function invariant(...a) {
|
|
|
207
133
|
toArray,
|
|
208
134
|
uuid,
|
|
209
135
|
warn
|
|
210
|
-
}
|
|
136
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
+
"type": "module",
|
|
2
3
|
"name": "@zag-js/utils",
|
|
3
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.5",
|
|
4
5
|
"description": "",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"js",
|
|
@@ -11,7 +12,6 @@
|
|
|
11
12
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
12
13
|
"license": "MIT",
|
|
13
14
|
"main": "dist/index.js",
|
|
14
|
-
"module": "dist/index.mjs",
|
|
15
15
|
"types": "dist/index.d.ts",
|
|
16
16
|
"repository": "https://github.com/chakra-ui/zag/tree/main/packages/utilities/core",
|
|
17
17
|
"sideEffects": false,
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"build-fast": "tsup src/index.ts --format=esm
|
|
28
|
+
"build-fast": "tsup src/index.ts --format=esm",
|
|
29
29
|
"start": "pnpm build --watch",
|
|
30
|
-
"build": "tsup src/index.ts --format=esm
|
|
30
|
+
"build": "tsup src/index.ts --format=esm --dts",
|
|
31
31
|
"test": "jest --config ../../../jest.config.js --rootDir . --passWithNoTests",
|
|
32
32
|
"lint": "eslint src --ext .ts,.tsx",
|
|
33
33
|
"test-ci": "pnpm test --ci --runInBand",
|
package/dist/index.mjs
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
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
|
-
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 ?? 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
|
-
function merge(origin, patch) {
|
|
80
|
-
if (!(typeof patch === "object"))
|
|
81
|
-
return patch;
|
|
82
|
-
const result = !(typeof origin === "object") ? {} : Object.assign({}, origin);
|
|
83
|
-
for (const key of Object.keys(patch)) {
|
|
84
|
-
const value = patch[key];
|
|
85
|
-
const src = result[key];
|
|
86
|
-
if (value === null)
|
|
87
|
-
delete result[key];
|
|
88
|
-
else if (Array.isArray(value) || Array.isArray(src))
|
|
89
|
-
result[key] = (src || []).concat(value || []);
|
|
90
|
-
else
|
|
91
|
-
result[key] = merge(src, value);
|
|
92
|
-
}
|
|
93
|
-
return result;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// src/guard.ts
|
|
97
|
-
var isDev = () => process.env.NODE_ENV !== "production";
|
|
98
|
-
var isArray = (v) => Array.isArray(v);
|
|
99
|
-
var isBoolean = (v) => v === true || v === false;
|
|
100
|
-
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
|
|
101
|
-
var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
|
|
102
|
-
var isString = (v) => typeof v === "string";
|
|
103
|
-
var isFunction = (v) => typeof v === "function";
|
|
104
|
-
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
105
|
-
|
|
106
|
-
// src/warning.ts
|
|
107
|
-
function warn(...a) {
|
|
108
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
109
|
-
const c = a.length === 2 ? a[0] : true;
|
|
110
|
-
if (c && process.env.NODE_ENV !== "production") {
|
|
111
|
-
console.warn(m);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
function invariant(...a) {
|
|
115
|
-
const m = a.length === 1 ? a[0] : a[1];
|
|
116
|
-
const c = a.length === 2 ? a[0] : true;
|
|
117
|
-
if (c && process.env.NODE_ENV !== "production") {
|
|
118
|
-
throw new Error(m);
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
export {
|
|
122
|
-
add,
|
|
123
|
-
callAll,
|
|
124
|
-
cast,
|
|
125
|
-
chunk,
|
|
126
|
-
clear,
|
|
127
|
-
first,
|
|
128
|
-
fromLength,
|
|
129
|
-
has,
|
|
130
|
-
hasProp,
|
|
131
|
-
invariant,
|
|
132
|
-
isArray,
|
|
133
|
-
isBoolean,
|
|
134
|
-
isDev,
|
|
135
|
-
isEmpty,
|
|
136
|
-
isFunction,
|
|
137
|
-
isNumber,
|
|
138
|
-
isObject,
|
|
139
|
-
isString,
|
|
140
|
-
last,
|
|
141
|
-
merge,
|
|
142
|
-
next,
|
|
143
|
-
nextIndex,
|
|
144
|
-
noop,
|
|
145
|
-
prev,
|
|
146
|
-
prevIndex,
|
|
147
|
-
remove,
|
|
148
|
-
removeAt,
|
|
149
|
-
runIfFn,
|
|
150
|
-
toArray,
|
|
151
|
-
uuid,
|
|
152
|
-
warn
|
|
153
|
-
};
|