@zag-js/utils 0.3.2 → 0.3.4

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.js CHANGED
@@ -85,11 +85,10 @@ function prev(v, index, opts = {}) {
85
85
  var chunk = (v, size) => {
86
86
  const res = [];
87
87
  return v.reduce((rows, value, index) => {
88
- var _a;
89
88
  if (index % size === 0)
90
89
  rows.push([value]);
91
90
  else
92
- (_a = last(rows)) == null ? void 0 : _a.push(value);
91
+ last(rows)?.push(value);
93
92
  return rows;
94
93
  }, res);
95
94
  };
package/dist/array.mjs CHANGED
@@ -14,7 +14,7 @@ import {
14
14
  remove,
15
15
  removeAt,
16
16
  toArray
17
- } from "./chunk-CVED4DVS.mjs";
17
+ } from "./chunk-27EXK2DH.mjs";
18
18
  export {
19
19
  add,
20
20
  chunk,
@@ -47,11 +47,10 @@ function prev(v, index, opts = {}) {
47
47
  var chunk = (v, size) => {
48
48
  const res = [];
49
49
  return v.reduce((rows, value, index) => {
50
- var _a;
51
50
  if (index % size === 0)
52
51
  rows.push([value]);
53
52
  else
54
- (_a = last(rows)) == null ? void 0 : _a.push(value);
53
+ last(rows)?.push(value);
55
54
  return rows;
56
55
  }, res);
57
56
  };
@@ -0,0 +1,26 @@
1
+ // src/object.ts
2
+ function compact(obj) {
3
+ if (!isPlainObject(obj) || obj === void 0) {
4
+ return obj;
5
+ }
6
+ const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
7
+ const filtered = {};
8
+ for (const key of keys) {
9
+ const value = obj[key];
10
+ if (value !== void 0) {
11
+ filtered[key] = compact(value);
12
+ }
13
+ }
14
+ return filtered;
15
+ }
16
+ function json(value) {
17
+ return JSON.parse(JSON.stringify(value));
18
+ }
19
+ var isPlainObject = (value) => {
20
+ return value && typeof value === "object" && value.constructor === Object;
21
+ };
22
+
23
+ export {
24
+ compact,
25
+ json
26
+ };
@@ -1,14 +1,14 @@
1
1
  // src/functions.ts
2
2
  var runIfFn = (v, ...a) => {
3
3
  const res = typeof v === "function" ? v(...a) : v;
4
- return res != null ? res : void 0;
4
+ return res ?? void 0;
5
5
  };
6
6
  var cast = (v) => v;
7
7
  var noop = () => {
8
8
  };
9
9
  var callAll = (...fns) => (...a) => {
10
10
  fns.forEach(function(fn) {
11
- fn == null ? void 0 : fn(...a);
11
+ fn?.(...a);
12
12
  });
13
13
  };
14
14
  var uuid = /* @__PURE__ */ (() => {
package/dist/functions.js CHANGED
@@ -29,14 +29,14 @@ __export(functions_exports, {
29
29
  module.exports = __toCommonJS(functions_exports);
30
30
  var runIfFn = (v, ...a) => {
31
31
  const res = typeof v === "function" ? v(...a) : v;
32
- return res != null ? res : void 0;
32
+ return res ?? void 0;
33
33
  };
34
34
  var cast = (v) => v;
35
35
  var noop = () => {
36
36
  };
37
37
  var callAll = (...fns) => (...a) => {
38
38
  fns.forEach(function(fn) {
39
- fn == null ? void 0 : fn(...a);
39
+ fn?.(...a);
40
40
  });
41
41
  };
42
42
  var uuid = /* @__PURE__ */ (() => {
@@ -4,7 +4,7 @@ import {
4
4
  noop,
5
5
  runIfFn,
6
6
  uuid
7
- } from "./chunk-74GHTI6P.mjs";
7
+ } from "./chunk-YKQM3BDH.mjs";
8
8
  export {
9
9
  callAll,
10
10
  cast,
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
- (_a = last(rows)) == null ? void 0 : _a.push(value);
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 != null ? res : void 0;
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 == null ? void 0 : fn(...a);
125
+ fn?.(...a);
127
126
  });
128
127
  };
129
128
  var uuid = /* @__PURE__ */ (() => {
@@ -146,15 +145,25 @@ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
146
145
 
147
146
  // src/object.ts
148
147
  function compact(obj) {
149
- if (obj === void 0)
148
+ if (!isPlainObject(obj) || obj === void 0) {
150
149
  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
- );
150
+ }
151
+ const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
152
+ const filtered = {};
153
+ for (const key of keys) {
154
+ const value = obj[key];
155
+ if (value !== void 0) {
156
+ filtered[key] = compact(value);
157
+ }
158
+ }
159
+ return filtered;
154
160
  }
155
161
  function json(value) {
156
162
  return JSON.parse(JSON.stringify(value));
157
163
  }
164
+ var isPlainObject = (value) => {
165
+ return value && typeof value === "object" && value.constructor === Object;
166
+ };
158
167
 
159
168
  // src/warning.ts
160
169
  function warn(...a) {
package/dist/index.mjs CHANGED
@@ -14,18 +14,14 @@ import {
14
14
  remove,
15
15
  removeAt,
16
16
  toArray
17
- } from "./chunk-CVED4DVS.mjs";
17
+ } from "./chunk-27EXK2DH.mjs";
18
18
  import {
19
19
  callAll,
20
20
  cast,
21
21
  noop,
22
22
  runIfFn,
23
23
  uuid
24
- } from "./chunk-74GHTI6P.mjs";
25
- import {
26
- compact,
27
- json
28
- } from "./chunk-7DKPTIZF.mjs";
24
+ } from "./chunk-YKQM3BDH.mjs";
29
25
  import {
30
26
  hasProp,
31
27
  isArray,
@@ -36,6 +32,10 @@ import {
36
32
  isObject,
37
33
  isString
38
34
  } from "./chunk-FZD3QLPB.mjs";
35
+ import {
36
+ compact,
37
+ json
38
+ } from "./chunk-Q55U6R3S.mjs";
39
39
  import {
40
40
  invariant,
41
41
  warn
package/dist/object.js CHANGED
@@ -24,22 +24,26 @@ __export(object_exports, {
24
24
  json: () => json
25
25
  });
26
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
27
  function compact(obj) {
34
- if (obj === void 0)
28
+ if (!isPlainObject(obj) || obj === void 0) {
35
29
  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
- );
30
+ }
31
+ const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
32
+ const filtered = {};
33
+ for (const key of keys) {
34
+ const value = obj[key];
35
+ if (value !== void 0) {
36
+ filtered[key] = compact(value);
37
+ }
38
+ }
39
+ return filtered;
39
40
  }
40
41
  function json(value) {
41
42
  return JSON.parse(JSON.stringify(value));
42
43
  }
44
+ var isPlainObject = (value) => {
45
+ return value && typeof value === "object" && value.constructor === Object;
46
+ };
43
47
  // Annotate the CommonJS export names for ESM import in node:
44
48
  0 && (module.exports = {
45
49
  compact,
package/dist/object.mjs CHANGED
@@ -1,8 +1,7 @@
1
1
  import {
2
2
  compact,
3
3
  json
4
- } from "./chunk-7DKPTIZF.mjs";
5
- import "./chunk-FZD3QLPB.mjs";
4
+ } from "./chunk-Q55U6R3S.mjs";
6
5
  export {
7
6
  compact,
8
7
  json
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "0.3.2",
3
+ "version": "0.3.4",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",
@@ -1,20 +0,0 @@
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
- };