@zag-js/utils 0.1.6 → 0.3.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/index.d.ts +3 -1
- package/dist/index.js +12 -1
- package/dist/index.mjs +11 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -33,9 +33,11 @@ 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
|
+
|
|
36
38
|
declare function warn(m: string): void;
|
|
37
39
|
declare function warn(c: boolean, m: string): void;
|
|
38
40
|
declare function invariant(m: string): void;
|
|
39
41
|
declare function invariant(c: boolean, m: string): void;
|
|
40
42
|
|
|
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 };
|
|
43
|
+
export { IndexOptions, add, callAll, cast, chunk, clear, compact, 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
|
@@ -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,
|
|
@@ -114,7 +115,7 @@ var chunk = (v, size) => {
|
|
|
114
115
|
// src/functions.ts
|
|
115
116
|
var runIfFn = (v, ...a) => {
|
|
116
117
|
const res = typeof v === "function" ? v(...a) : v;
|
|
117
|
-
return res
|
|
118
|
+
return res != null ? res : void 0;
|
|
118
119
|
};
|
|
119
120
|
var cast = (v) => v;
|
|
120
121
|
var noop = () => {
|
|
@@ -142,6 +143,15 @@ var isString = (v) => typeof v === "string";
|
|
|
142
143
|
var isFunction = (v) => typeof v === "function";
|
|
143
144
|
var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
|
|
144
145
|
|
|
146
|
+
// src/object.ts
|
|
147
|
+
function compact(obj) {
|
|
148
|
+
if (obj === void 0)
|
|
149
|
+
return obj;
|
|
150
|
+
return Object.fromEntries(
|
|
151
|
+
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value])
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
|
|
145
155
|
// src/warning.ts
|
|
146
156
|
function warn(...a) {
|
|
147
157
|
const m = a.length === 1 ? a[0] : a[1];
|
|
@@ -164,6 +174,7 @@ function invariant(...a) {
|
|
|
164
174
|
cast,
|
|
165
175
|
chunk,
|
|
166
176
|
clear,
|
|
177
|
+
compact,
|
|
167
178
|
first,
|
|
168
179
|
fromLength,
|
|
169
180
|
has,
|
package/dist/index.mjs
CHANGED
|
@@ -59,7 +59,7 @@ var chunk = (v, size) => {
|
|
|
59
59
|
// src/functions.ts
|
|
60
60
|
var runIfFn = (v, ...a) => {
|
|
61
61
|
const res = typeof v === "function" ? v(...a) : v;
|
|
62
|
-
return res
|
|
62
|
+
return res != null ? res : void 0;
|
|
63
63
|
};
|
|
64
64
|
var cast = (v) => v;
|
|
65
65
|
var noop = () => {
|
|
@@ -87,6 +87,15 @@ 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
|
+
|
|
90
99
|
// src/warning.ts
|
|
91
100
|
function warn(...a) {
|
|
92
101
|
const m = a.length === 1 ? a[0] : a[1];
|
|
@@ -108,6 +117,7 @@ export {
|
|
|
108
117
|
cast,
|
|
109
118
|
chunk,
|
|
110
119
|
clear,
|
|
120
|
+
compact,
|
|
111
121
|
first,
|
|
112
122
|
fromLength,
|
|
113
123
|
has,
|