@zag-js/utils 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +4 -1
- package/dist/index.js +16 -0
- package/dist/index.mjs +14 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,9 +33,12 @@ declare const isString: (v: any) => v is string;
|
|
|
33
33
|
declare const isFunction: (v: any) => v is Function;
|
|
34
34
|
declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
|
|
35
35
|
|
|
36
|
+
declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
|
|
37
|
+
declare function json(value: any): any;
|
|
38
|
+
|
|
36
39
|
declare function warn(m: string): void;
|
|
37
40
|
declare function warn(c: boolean, m: string): void;
|
|
38
41
|
declare function invariant(m: string): void;
|
|
39
42
|
declare function invariant(c: boolean, m: string): void;
|
|
40
43
|
|
|
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 };
|
|
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 };
|
package/dist/index.js
CHANGED
|
@@ -25,6 +25,7 @@ __export(src_exports, {
|
|
|
25
25
|
cast: () => cast,
|
|
26
26
|
chunk: () => chunk,
|
|
27
27
|
clear: () => clear,
|
|
28
|
+
compact: () => compact,
|
|
28
29
|
first: () => first,
|
|
29
30
|
fromLength: () => fromLength,
|
|
30
31
|
has: () => has,
|
|
@@ -38,6 +39,7 @@ __export(src_exports, {
|
|
|
38
39
|
isNumber: () => isNumber,
|
|
39
40
|
isObject: () => isObject,
|
|
40
41
|
isString: () => isString,
|
|
42
|
+
json: () => json,
|
|
41
43
|
last: () => last,
|
|
42
44
|
next: () => next,
|
|
43
45
|
nextIndex: () => nextIndex,
|
|
@@ -142,6 +144,18 @@ var isString = (v) => typeof v === "string";
|
|
|
142
144
|
var isFunction = (v) => typeof v === "function";
|
|
143
145
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
144
146
|
|
|
147
|
+
// src/object.ts
|
|
148
|
+
function compact(obj) {
|
|
149
|
+
if (obj === void 0)
|
|
150
|
+
return obj;
|
|
151
|
+
return Object.fromEntries(
|
|
152
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
function json(value) {
|
|
156
|
+
return JSON.parse(JSON.stringify(value));
|
|
157
|
+
}
|
|
158
|
+
|
|
145
159
|
// src/warning.ts
|
|
146
160
|
function warn(...a) {
|
|
147
161
|
const m = a.length === 1 ? a[0] : a[1];
|
|
@@ -164,6 +178,7 @@ function invariant(...a) {
|
|
|
164
178
|
cast,
|
|
165
179
|
chunk,
|
|
166
180
|
clear,
|
|
181
|
+
compact,
|
|
167
182
|
first,
|
|
168
183
|
fromLength,
|
|
169
184
|
has,
|
|
@@ -177,6 +192,7 @@ function invariant(...a) {
|
|
|
177
192
|
isNumber,
|
|
178
193
|
isObject,
|
|
179
194
|
isString,
|
|
195
|
+
json,
|
|
180
196
|
last,
|
|
181
197
|
next,
|
|
182
198
|
nextIndex,
|
package/dist/index.mjs
CHANGED
|
@@ -87,6 +87,18 @@ var isString = (v) => typeof v === "string";
|
|
|
87
87
|
var isFunction = (v) => typeof v === "function";
|
|
88
88
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
89
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
|
+
|
|
90
102
|
// src/warning.ts
|
|
91
103
|
function warn(...a) {
|
|
92
104
|
const m = a.length === 1 ? a[0] : a[1];
|
|
@@ -108,6 +120,7 @@ export {
|
|
|
108
120
|
cast,
|
|
109
121
|
chunk,
|
|
110
122
|
clear,
|
|
123
|
+
compact,
|
|
111
124
|
first,
|
|
112
125
|
fromLength,
|
|
113
126
|
has,
|
|
@@ -121,6 +134,7 @@ export {
|
|
|
121
134
|
isNumber,
|
|
122
135
|
isObject,
|
|
123
136
|
isString,
|
|
137
|
+
json,
|
|
124
138
|
last,
|
|
125
139
|
next,
|
|
126
140
|
nextIndex,
|