@zag-js/utils
Advanced tools
Comparing version
@@ -148,7 +148,14 @@ "use strict"; | ||
function compact(obj) { | ||
if (obj === void 0) | ||
if (!isPlainObject(obj) || obj === void 0) { | ||
return obj; | ||
return Object.fromEntries( | ||
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value]) | ||
); | ||
} | ||
const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string"); | ||
const filtered = {}; | ||
for (const key of keys) { | ||
const value = obj[key]; | ||
if (value !== void 0) { | ||
filtered[key] = compact(value); | ||
} | ||
} | ||
return filtered; | ||
} | ||
@@ -158,2 +165,5 @@ function json(value) { | ||
} | ||
var isPlainObject = (value) => { | ||
return value && typeof value === "object" && value.constructor === Object; | ||
}; | ||
@@ -160,0 +170,0 @@ // src/warning.ts |
@@ -27,14 +27,15 @@ "use strict"; | ||
module.exports = __toCommonJS(object_exports); | ||
// src/guard.ts | ||
var isArray = (v) => Array.isArray(v); | ||
var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v)); | ||
// src/object.ts | ||
function compact(obj) { | ||
if (obj === void 0) | ||
if (!isPlainObject(obj) || obj === void 0) { | ||
return obj; | ||
return Object.fromEntries( | ||
Object.entries(obj).filter(([, value]) => value !== void 0).map(([key, value]) => [key, isObject(value) ? compact(value) : value]) | ||
); | ||
} | ||
const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string"); | ||
const filtered = {}; | ||
for (const key of keys) { | ||
const value = obj[key]; | ||
if (value !== void 0) { | ||
filtered[key] = compact(value); | ||
} | ||
} | ||
return filtered; | ||
} | ||
@@ -44,2 +45,5 @@ function json(value) { | ||
} | ||
var isPlainObject = (value) => { | ||
return value && typeof value === "object" && value.constructor === Object; | ||
}; | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -46,0 +50,0 @@ 0 && (module.exports = { |
{ | ||
"name": "@zag-js/utils", | ||
"version": "0.3.3", | ||
"version": "0.3.4", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25149
1.79%892
2.53%