@zag-js/utils 1.2.0 → 1.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.mts CHANGED
@@ -30,7 +30,7 @@ declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => vo
30
30
  declare const cast: <T>(v: unknown) => T;
31
31
  declare const identity: (v: VoidFunction) => void;
32
32
  declare const noop: () => void;
33
- declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
33
+ declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
34
34
  declare const uuid: () => string;
35
35
  declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
36
36
  declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
package/dist/index.d.ts CHANGED
@@ -30,7 +30,7 @@ declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => vo
30
30
  declare const cast: <T>(v: unknown) => T;
31
31
  declare const identity: (v: VoidFunction) => void;
32
32
  declare const noop: () => void;
33
- declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
33
+ declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | null | undefined)[]) => (...a: Parameters<T>) => void;
34
34
  declare const uuid: () => string;
35
35
  declare function match<V extends string | number = string, R = unknown>(key: V, record: Record<V, R | ((...args: any[]) => R)>, ...args: any[]): R;
36
36
  declare const tryCatch: <R>(fn: () => R, fallback: () => R) => R;
package/dist/index.js CHANGED
@@ -95,6 +95,28 @@ var isEqual = (a, b) => {
95
95
  return true;
96
96
  };
97
97
 
98
+ // src/guard.ts
99
+ var isDev = () => process.env.NODE_ENV !== "production";
100
+ var isArray = (v) => Array.isArray(v);
101
+ var isBoolean = (v) => v === true || v === false;
102
+ var isObjectLike = (v) => v != null && typeof v === "object";
103
+ var isObject = (v) => isObjectLike(v) && !isArray(v);
104
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
105
+ var isString = (v) => typeof v === "string";
106
+ var isFunction = (v) => typeof v === "function";
107
+ var isNull = (v) => v == null;
108
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
109
+ var baseGetTag = (v) => Object.prototype.toString.call(v);
110
+ var fnToString = Function.prototype.toString;
111
+ var objectCtorString = fnToString.call(Object);
112
+ var isPlainObject = (v) => {
113
+ if (!isObjectLike(v) || baseGetTag(v) != "[object Object]") return false;
114
+ const proto = Object.getPrototypeOf(v);
115
+ if (proto === null) return true;
116
+ const Ctor = hasProp(proto, "constructor") && proto.constructor;
117
+ return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
118
+ };
119
+
98
120
  // src/functions.ts
99
121
  var runIfFn = (v, ...a) => {
100
122
  const res = typeof v === "function" ? v(...a) : v;
@@ -119,7 +141,7 @@ var uuid = /* @__PURE__ */ (() => {
119
141
  function match(key, record, ...args) {
120
142
  if (key in record) {
121
143
  const fn = record[key];
122
- return typeof fn === "function" ? fn(...args) : fn;
144
+ return isFunction(fn) ? fn(...args) : fn;
123
145
  }
124
146
  const error = new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
125
147
  Error.captureStackTrace?.(error, match);
@@ -158,28 +180,6 @@ function throttle(fn, wait = 0) {
158
180
  };
159
181
  }
160
182
 
161
- // src/guard.ts
162
- var isDev = () => process.env.NODE_ENV !== "production";
163
- var isArray = (v) => Array.isArray(v);
164
- var isBoolean = (v) => v === true || v === false;
165
- var isObjectLike = (v) => v != null && typeof v === "object";
166
- var isObject = (v) => isObjectLike(v) && !isArray(v);
167
- var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
168
- var isString = (v) => typeof v === "string";
169
- var isFunction = (v) => typeof v === "function";
170
- var isNull = (v) => v == null;
171
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
172
- var baseGetTag = (v) => Object.prototype.toString.call(v);
173
- var fnToString = Function.prototype.toString;
174
- var objectCtorString = fnToString.call(Object);
175
- var isPlainObject = (v) => {
176
- if (!isObjectLike(v) || baseGetTag(v) != "[object Object]") return false;
177
- const proto = Object.getPrototypeOf(v);
178
- if (proto === null) return true;
179
- const Ctor = hasProp(proto, "constructor") && proto.constructor;
180
- return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
181
- };
182
-
183
183
  // src/number.ts
184
184
  var { floor, abs, round, min, max, pow, sign } = Math;
185
185
  var isNaN = (v) => Number.isNaN(v);
package/dist/index.mjs CHANGED
@@ -93,6 +93,28 @@ var isEqual = (a, b) => {
93
93
  return true;
94
94
  };
95
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 isObjectLike = (v) => v != null && typeof v === "object";
101
+ var isObject = (v) => isObjectLike(v) && !isArray(v);
102
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
103
+ var isString = (v) => typeof v === "string";
104
+ var isFunction = (v) => typeof v === "function";
105
+ var isNull = (v) => v == null;
106
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
107
+ var baseGetTag = (v) => Object.prototype.toString.call(v);
108
+ var fnToString = Function.prototype.toString;
109
+ var objectCtorString = fnToString.call(Object);
110
+ var isPlainObject = (v) => {
111
+ if (!isObjectLike(v) || baseGetTag(v) != "[object Object]") return false;
112
+ const proto = Object.getPrototypeOf(v);
113
+ if (proto === null) return true;
114
+ const Ctor = hasProp(proto, "constructor") && proto.constructor;
115
+ return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
116
+ };
117
+
96
118
  // src/functions.ts
97
119
  var runIfFn = (v, ...a) => {
98
120
  const res = typeof v === "function" ? v(...a) : v;
@@ -117,7 +139,7 @@ var uuid = /* @__PURE__ */ (() => {
117
139
  function match(key, record, ...args) {
118
140
  if (key in record) {
119
141
  const fn = record[key];
120
- return typeof fn === "function" ? fn(...args) : fn;
142
+ return isFunction(fn) ? fn(...args) : fn;
121
143
  }
122
144
  const error = new Error(`No matching key: ${JSON.stringify(key)} in ${JSON.stringify(Object.keys(record))}`);
123
145
  Error.captureStackTrace?.(error, match);
@@ -156,28 +178,6 @@ function throttle(fn, wait = 0) {
156
178
  };
157
179
  }
158
180
 
159
- // src/guard.ts
160
- var isDev = () => process.env.NODE_ENV !== "production";
161
- var isArray = (v) => Array.isArray(v);
162
- var isBoolean = (v) => v === true || v === false;
163
- var isObjectLike = (v) => v != null && typeof v === "object";
164
- var isObject = (v) => isObjectLike(v) && !isArray(v);
165
- var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
166
- var isString = (v) => typeof v === "string";
167
- var isFunction = (v) => typeof v === "function";
168
- var isNull = (v) => v == null;
169
- var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
170
- var baseGetTag = (v) => Object.prototype.toString.call(v);
171
- var fnToString = Function.prototype.toString;
172
- var objectCtorString = fnToString.call(Object);
173
- var isPlainObject = (v) => {
174
- if (!isObjectLike(v) || baseGetTag(v) != "[object Object]") return false;
175
- const proto = Object.getPrototypeOf(v);
176
- if (proto === null) return true;
177
- const Ctor = hasProp(proto, "constructor") && proto.constructor;
178
- return typeof Ctor == "function" && Ctor instanceof Ctor && fnToString.call(Ctor) == objectCtorString;
179
- };
180
-
181
181
  // src/number.ts
182
182
  var { floor, abs, round, min, max, pow, sign } = Math;
183
183
  var isNaN = (v) => Number.isNaN(v);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",