@zag-js/utils 0.10.5 → 0.11.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.
@@ -0,0 +1,44 @@
1
+ declare function toArray<T>(v: T | T[] | undefined | null): T[];
2
+ declare const fromLength: (length: number) => number[];
3
+ declare const first: <T>(v: T[]) => T | undefined;
4
+ declare const last: <T>(v: T[]) => T | undefined;
5
+ declare const isEmpty: <T>(v: T[]) => boolean;
6
+ declare const has: <T>(v: T[], t: any) => boolean;
7
+ declare const add: <T>(v: T[], ...items: T[]) => T[];
8
+ declare const remove: <T>(v: T[], item: T) => T[];
9
+ declare const removeAt: <T>(v: T[], i: number) => T[];
10
+ declare function clear<T>(v: T[]): T[];
11
+ type IndexOptions = {
12
+ step?: number;
13
+ loop?: boolean;
14
+ };
15
+ declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
16
+ declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
17
+ declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
18
+ declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
19
+ declare const chunk: <T>(v: T[], size: number) => T[][];
20
+
21
+ declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
22
+ declare const cast: <T>(v: unknown) => T;
23
+ declare const noop: () => void;
24
+ declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
25
+ declare const uuid: () => string;
26
+
27
+ declare const isDev: () => boolean;
28
+ declare const isArray: (v: any) => v is any[];
29
+ declare const isBoolean: (v: any) => v is boolean;
30
+ declare const isObject: (v: any) => v is Record<string, any>;
31
+ declare const isNumber: (v: any) => v is number;
32
+ declare const isString: (v: any) => v is string;
33
+ declare const isFunction: (v: any) => v is Function;
34
+ declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
35
+
36
+ declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
37
+ declare function json(value: any): any;
38
+
39
+ declare function warn(m: string): void;
40
+ declare function warn(c: boolean, m: string): void;
41
+ declare function invariant(m: string): void;
42
+ declare function invariant(c: boolean, m: string): void;
43
+
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.d.ts CHANGED
@@ -1,5 +1,44 @@
1
- export * from "./array";
2
- export * from "./functions";
3
- export * from "./guard";
4
- export * from "./object";
5
- export * from "./warning";
1
+ declare function toArray<T>(v: T | T[] | undefined | null): T[];
2
+ declare const fromLength: (length: number) => number[];
3
+ declare const first: <T>(v: T[]) => T | undefined;
4
+ declare const last: <T>(v: T[]) => T | undefined;
5
+ declare const isEmpty: <T>(v: T[]) => boolean;
6
+ declare const has: <T>(v: T[], t: any) => boolean;
7
+ declare const add: <T>(v: T[], ...items: T[]) => T[];
8
+ declare const remove: <T>(v: T[], item: T) => T[];
9
+ declare const removeAt: <T>(v: T[], i: number) => T[];
10
+ declare function clear<T>(v: T[]): T[];
11
+ type IndexOptions = {
12
+ step?: number;
13
+ loop?: boolean;
14
+ };
15
+ declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
16
+ declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
17
+ declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
18
+ declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
19
+ declare const chunk: <T>(v: T[], size: number) => T[][];
20
+
21
+ declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
22
+ declare const cast: <T>(v: unknown) => T;
23
+ declare const noop: () => void;
24
+ declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
25
+ declare const uuid: () => string;
26
+
27
+ declare const isDev: () => boolean;
28
+ declare const isArray: (v: any) => v is any[];
29
+ declare const isBoolean: (v: any) => v is boolean;
30
+ declare const isObject: (v: any) => v is Record<string, any>;
31
+ declare const isNumber: (v: any) => v is number;
32
+ declare const isString: (v: any) => v is string;
33
+ declare const isFunction: (v: any) => v is Function;
34
+ declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
35
+
36
+ declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
37
+ declare function json(value: any): any;
38
+
39
+ declare function warn(m: string): void;
40
+ declare function warn(c: boolean, m: string): void;
41
+ declare function invariant(m: string): void;
42
+ declare function invariant(c: boolean, m: string): void;
43
+
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
@@ -1,44 +1,218 @@
1
- 'use strict';
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
2
19
 
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
20
+ // src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ add: () => add,
24
+ callAll: () => callAll,
25
+ cast: () => cast,
26
+ chunk: () => chunk,
27
+ clear: () => clear,
28
+ compact: () => compact,
29
+ first: () => first,
30
+ fromLength: () => fromLength,
31
+ has: () => has,
32
+ hasProp: () => hasProp,
33
+ invariant: () => invariant,
34
+ isArray: () => isArray,
35
+ isBoolean: () => isBoolean,
36
+ isDev: () => isDev,
37
+ isEmpty: () => isEmpty,
38
+ isFunction: () => isFunction,
39
+ isNumber: () => isNumber,
40
+ isObject: () => isObject,
41
+ isString: () => isString,
42
+ json: () => json,
43
+ last: () => last,
44
+ next: () => next,
45
+ nextIndex: () => nextIndex,
46
+ noop: () => noop,
47
+ prev: () => prev,
48
+ prevIndex: () => prevIndex,
49
+ remove: () => remove,
50
+ removeAt: () => removeAt,
51
+ runIfFn: () => runIfFn,
52
+ toArray: () => toArray,
53
+ uuid: () => uuid,
54
+ warn: () => warn
55
+ });
56
+ module.exports = __toCommonJS(src_exports);
4
57
 
5
- const array = require('./array.js');
6
- const functions = require('./functions.js');
7
- const guard = require('./guard.js');
8
- const object = require('./object.js');
9
- const warning = require('./warning.js');
58
+ // src/array.ts
59
+ function toArray(v) {
60
+ if (!v)
61
+ return [];
62
+ return Array.isArray(v) ? v : [v];
63
+ }
64
+ var fromLength = (length) => Array.from(Array(length).keys());
65
+ var first = (v) => v[0];
66
+ var last = (v) => v[v.length - 1];
67
+ var isEmpty = (v) => v.length === 0;
68
+ var has = (v, t) => v.indexOf(t) !== -1;
69
+ var add = (v, ...items) => v.concat(items);
70
+ var remove = (v, item) => removeAt(v, v.indexOf(item));
71
+ var removeAt = (v, i) => {
72
+ if (i > -1)
73
+ v.splice(i, 1);
74
+ return v;
75
+ };
76
+ function clear(v) {
77
+ while (v.length > 0)
78
+ v.pop();
79
+ return v;
80
+ }
81
+ function nextIndex(v, idx, opts = {}) {
82
+ const { step = 1, loop = true } = opts;
83
+ const next2 = idx + step;
84
+ const len = v.length;
85
+ const last2 = len - 1;
86
+ if (idx === -1)
87
+ return step > 0 ? 0 : last2;
88
+ if (next2 < 0)
89
+ return loop ? last2 : 0;
90
+ if (next2 >= len)
91
+ return loop ? 0 : idx > len ? len : idx;
92
+ return next2;
93
+ }
94
+ function next(v, idx, opts = {}) {
95
+ return v[nextIndex(v, idx, opts)];
96
+ }
97
+ function prevIndex(v, idx, opts = {}) {
98
+ const { step = 1, loop = true } = opts;
99
+ return nextIndex(v, idx, { step: -step, loop });
100
+ }
101
+ function prev(v, index, opts = {}) {
102
+ return v[prevIndex(v, index, opts)];
103
+ }
104
+ var chunk = (v, size) => {
105
+ const res = [];
106
+ return v.reduce((rows, value, index) => {
107
+ if (index % size === 0)
108
+ rows.push([value]);
109
+ else
110
+ last(rows)?.push(value);
111
+ return rows;
112
+ }, res);
113
+ };
10
114
 
115
+ // src/functions.ts
116
+ var runIfFn = (v, ...a) => {
117
+ const res = typeof v === "function" ? v(...a) : v;
118
+ return res ?? void 0;
119
+ };
120
+ var cast = (v) => v;
121
+ var noop = () => {
122
+ };
123
+ var callAll = (...fns) => (...a) => {
124
+ fns.forEach(function(fn) {
125
+ fn?.(...a);
126
+ });
127
+ };
128
+ var uuid = /* @__PURE__ */ (() => {
129
+ let id = 0;
130
+ return () => {
131
+ id++;
132
+ return id.toString(36);
133
+ };
134
+ })();
11
135
 
136
+ // src/guard.ts
137
+ var isDev = () => process.env.NODE_ENV !== "production";
138
+ var isArray = (v) => Array.isArray(v);
139
+ var isBoolean = (v) => v === true || v === false;
140
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
141
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
142
+ var isString = (v) => typeof v === "string";
143
+ var isFunction = (v) => typeof v === "function";
144
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
12
145
 
13
- exports.add = array.add;
14
- exports.chunk = array.chunk;
15
- exports.clear = array.clear;
16
- exports.first = array.first;
17
- exports.fromLength = array.fromLength;
18
- exports.has = array.has;
19
- exports.isEmpty = array.isEmpty;
20
- exports.last = array.last;
21
- exports.next = array.next;
22
- exports.nextIndex = array.nextIndex;
23
- exports.prev = array.prev;
24
- exports.prevIndex = array.prevIndex;
25
- exports.remove = array.remove;
26
- exports.removeAt = array.removeAt;
27
- exports.toArray = array.toArray;
28
- exports.callAll = functions.callAll;
29
- exports.cast = functions.cast;
30
- exports.noop = functions.noop;
31
- exports.runIfFn = functions.runIfFn;
32
- exports.uuid = functions.uuid;
33
- exports.hasProp = guard.hasProp;
34
- exports.isArray = guard.isArray;
35
- exports.isBoolean = guard.isBoolean;
36
- exports.isDev = guard.isDev;
37
- exports.isFunction = guard.isFunction;
38
- exports.isNumber = guard.isNumber;
39
- exports.isObject = guard.isObject;
40
- exports.isString = guard.isString;
41
- exports.compact = object.compact;
42
- exports.json = object.json;
43
- exports.invariant = warning.invariant;
44
- exports.warn = warning.warn;
146
+ // src/object.ts
147
+ function compact(obj) {
148
+ if (!isPlainObject(obj) || obj === void 0) {
149
+ return obj;
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;
160
+ }
161
+ function json(value) {
162
+ return JSON.parse(JSON.stringify(value));
163
+ }
164
+ var isPlainObject = (value) => {
165
+ return value && typeof value === "object" && value.constructor === Object;
166
+ };
167
+
168
+ // src/warning.ts
169
+ function warn(...a) {
170
+ const m = a.length === 1 ? a[0] : a[1];
171
+ const c = a.length === 2 ? a[0] : true;
172
+ if (c && process.env.NODE_ENV !== "production") {
173
+ console.warn(m);
174
+ }
175
+ }
176
+ function invariant(...a) {
177
+ const m = a.length === 1 ? a[0] : a[1];
178
+ const c = a.length === 2 ? a[0] : true;
179
+ if (c && process.env.NODE_ENV !== "production") {
180
+ throw new Error(m);
181
+ }
182
+ }
183
+ // Annotate the CommonJS export names for ESM import in node:
184
+ 0 && (module.exports = {
185
+ add,
186
+ callAll,
187
+ cast,
188
+ chunk,
189
+ clear,
190
+ compact,
191
+ first,
192
+ fromLength,
193
+ has,
194
+ hasProp,
195
+ invariant,
196
+ isArray,
197
+ isBoolean,
198
+ isDev,
199
+ isEmpty,
200
+ isFunction,
201
+ isNumber,
202
+ isObject,
203
+ isString,
204
+ json,
205
+ last,
206
+ next,
207
+ nextIndex,
208
+ noop,
209
+ prev,
210
+ prevIndex,
211
+ remove,
212
+ removeAt,
213
+ runIfFn,
214
+ toArray,
215
+ uuid,
216
+ warn
217
+ });
218
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/array.ts","../src/functions.ts","../src/guard.ts","../src/object.ts","../src/warning.ts"],"sourcesContent":["export * from \"./array\"\nexport * from \"./functions\"\nexport * from \"./guard\"\nexport * from \"./object\"\nexport * from \"./warning\"\n","export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n","export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n","export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n","export function compact<T extends Record<string, unknown> | undefined>(obj: T): T {\n if (!isPlainObject(obj) || obj === undefined) {\n return obj\n }\n\n const keys = Reflect.ownKeys(obj).filter((key) => typeof key === \"string\")\n const filtered: Partial<T> = {}\n for (const key of keys) {\n const value = (obj as any)[key]\n if (value !== undefined) {\n filtered[key as keyof T] = compact(value)\n }\n }\n return filtered as T\n}\n\nexport function json(value: any) {\n return JSON.parse(JSON.stringify(value))\n}\n\nconst isPlainObject = (value: any) => {\n return value && typeof value === \"object\" && value.constructor === Object\n}\n","export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,SAAS,QAAW,GAAoC;AAC7D,MAAI,CAAC;AAAG,WAAO,CAAC;AAChB,SAAO,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AAClC;AAEO,IAAM,aAAa,CAAC,WAAmB,MAAM,KAAK,MAAM,MAAM,EAAE,KAAK,CAAC;AAEtE,IAAM,QAAQ,CAAI,MAA0B,EAAE,CAAC;AAE/C,IAA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QAAM,OAAO,QAAQ,QAAQ,GAAG,EAAE,OAAO,CAAC,QAAQ,OAAO,QAAQ,QAAQ;AACzE,QAAM,WAAuB,CAAC;AAC9B,aAAW,OAAO,MAAM;AACtB,UAAM,QAAS,IAAY,GAAG;AAC9B,QAAI,UAAU,QAAW;AACvB,eAAS,GAAc,IAAI,QAAQ,KAAK;AAAA,IAC1C;AAAA,EACF;AACA,SAAO;AACT;AAEO,SAAS,KAAK,OAAY;AAC/B,SAAO,KAAK,MAAM,KAAK,UAAU,KAAK,CAAC;AACzC;AAEA,IAAM,gBAAgB,CAAC,UAAe;AACpC,SAAO,SAAS,OAAO,UAAU,YAAY,MAAM,gBAAgB;AACrE;;;ACpBO,SAAS,QAAQ,GAAgB;AACtC,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACrC,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI;AAClC,MAAI,KAAK,QAAQ,IAAI,aAAa,cAAc;AAC9C,YAAQ,KAAK,CAAC;AAAA,EAChB;AACF;AAIO,SAAS,aAAa,GAAgB;AAC3C,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACrC,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI;AAClC,MAAI,KAAK,QAAQ,IAAI,aAAa,cAAc;AAC9C,UAAM,IAAI,MAAM,CAAC;AAAA,EACnB;AACF;","names":["next","last"]}
package/dist/index.mjs CHANGED
@@ -1,5 +1,160 @@
1
- export { add, chunk, clear, first, fromLength, has, isEmpty, last, next, nextIndex, prev, prevIndex, remove, removeAt, toArray } from './array.mjs';
2
- export { callAll, cast, noop, runIfFn, uuid } from './functions.mjs';
3
- export { hasProp, isArray, isBoolean, isDev, isFunction, isNumber, isObject, isString } from './guard.mjs';
4
- export { compact, json } from './object.mjs';
5
- export { invariant, warn } from './warning.mjs';
1
+ // src/array.ts
2
+ function toArray(v) {
3
+ if (!v)
4
+ return [];
5
+ return Array.isArray(v) ? v : [v];
6
+ }
7
+ var fromLength = (length) => Array.from(Array(length).keys());
8
+ var first = (v) => v[0];
9
+ var last = (v) => v[v.length - 1];
10
+ var isEmpty = (v) => v.length === 0;
11
+ var has = (v, t) => v.indexOf(t) !== -1;
12
+ var add = (v, ...items) => v.concat(items);
13
+ var remove = (v, item) => removeAt(v, v.indexOf(item));
14
+ var removeAt = (v, i) => {
15
+ if (i > -1)
16
+ v.splice(i, 1);
17
+ return v;
18
+ };
19
+ function clear(v) {
20
+ while (v.length > 0)
21
+ v.pop();
22
+ return v;
23
+ }
24
+ function nextIndex(v, idx, opts = {}) {
25
+ const { step = 1, loop = true } = opts;
26
+ const next2 = idx + step;
27
+ const len = v.length;
28
+ const last2 = len - 1;
29
+ if (idx === -1)
30
+ return step > 0 ? 0 : last2;
31
+ if (next2 < 0)
32
+ return loop ? last2 : 0;
33
+ if (next2 >= len)
34
+ return loop ? 0 : idx > len ? len : idx;
35
+ return next2;
36
+ }
37
+ function next(v, idx, opts = {}) {
38
+ return v[nextIndex(v, idx, opts)];
39
+ }
40
+ function prevIndex(v, idx, opts = {}) {
41
+ const { step = 1, loop = true } = opts;
42
+ return nextIndex(v, idx, { step: -step, loop });
43
+ }
44
+ function prev(v, index, opts = {}) {
45
+ return v[prevIndex(v, index, opts)];
46
+ }
47
+ var chunk = (v, size) => {
48
+ const res = [];
49
+ return v.reduce((rows, value, index) => {
50
+ if (index % size === 0)
51
+ rows.push([value]);
52
+ else
53
+ last(rows)?.push(value);
54
+ return rows;
55
+ }, res);
56
+ };
57
+
58
+ // src/functions.ts
59
+ var runIfFn = (v, ...a) => {
60
+ const res = typeof v === "function" ? v(...a) : v;
61
+ return res ?? void 0;
62
+ };
63
+ var cast = (v) => v;
64
+ var noop = () => {
65
+ };
66
+ var callAll = (...fns) => (...a) => {
67
+ fns.forEach(function(fn) {
68
+ fn?.(...a);
69
+ });
70
+ };
71
+ var uuid = /* @__PURE__ */ (() => {
72
+ let id = 0;
73
+ return () => {
74
+ id++;
75
+ return id.toString(36);
76
+ };
77
+ })();
78
+
79
+ // src/guard.ts
80
+ var isDev = () => process.env.NODE_ENV !== "production";
81
+ var isArray = (v) => Array.isArray(v);
82
+ var isBoolean = (v) => v === true || v === false;
83
+ var isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
84
+ var isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
85
+ var isString = (v) => typeof v === "string";
86
+ var isFunction = (v) => typeof v === "function";
87
+ var hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
88
+
89
+ // src/object.ts
90
+ function compact(obj) {
91
+ if (!isPlainObject(obj) || obj === void 0) {
92
+ return obj;
93
+ }
94
+ const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
95
+ const filtered = {};
96
+ for (const key of keys) {
97
+ const value = obj[key];
98
+ if (value !== void 0) {
99
+ filtered[key] = compact(value);
100
+ }
101
+ }
102
+ return filtered;
103
+ }
104
+ function json(value) {
105
+ return JSON.parse(JSON.stringify(value));
106
+ }
107
+ var isPlainObject = (value) => {
108
+ return value && typeof value === "object" && value.constructor === Object;
109
+ };
110
+
111
+ // src/warning.ts
112
+ function warn(...a) {
113
+ const m = a.length === 1 ? a[0] : a[1];
114
+ const c = a.length === 2 ? a[0] : true;
115
+ if (c && process.env.NODE_ENV !== "production") {
116
+ console.warn(m);
117
+ }
118
+ }
119
+ function invariant(...a) {
120
+ const m = a.length === 1 ? a[0] : a[1];
121
+ const c = a.length === 2 ? a[0] : true;
122
+ if (c && process.env.NODE_ENV !== "production") {
123
+ throw new Error(m);
124
+ }
125
+ }
126
+ export {
127
+ add,
128
+ callAll,
129
+ cast,
130
+ chunk,
131
+ clear,
132
+ compact,
133
+ first,
134
+ fromLength,
135
+ has,
136
+ hasProp,
137
+ invariant,
138
+ isArray,
139
+ isBoolean,
140
+ isDev,
141
+ isEmpty,
142
+ isFunction,
143
+ isNumber,
144
+ isObject,
145
+ isString,
146
+ json,
147
+ last,
148
+ next,
149
+ nextIndex,
150
+ noop,
151
+ prev,
152
+ prevIndex,
153
+ remove,
154
+ removeAt,
155
+ runIfFn,
156
+ toArray,
157
+ uuid,
158
+ warn
159
+ };
160
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/array.ts","../src/functions.ts","../src/guard.ts","../src/object.ts","../src/warning.ts"],"sourcesContent":["export function toArray<T>(v: T | T[] | undefined | null): T[] {\n if (!v) return []\n return Array.isArray(v) ? v : [v]\n}\n\nexport const fromLength = (length: number) => Array.from(Array(length).keys())\n\nexport const first = <T>(v: T[]): T | undefined => v[0]\n\nexport const last = <T>(v: T[]): T | undefined => v[v.length - 1]\n\nexport const isEmpty = <T>(v: T[]): boolean => v.length === 0\n\nexport const has = <T>(v: T[], t: any): boolean => v.indexOf(t) !== -1\n\nexport const add = <T>(v: T[], ...items: T[]): T[] => v.concat(items)\n\nexport const remove = <T>(v: T[], item: T): T[] => removeAt(v, v.indexOf(item))\n\nexport const removeAt = <T>(v: T[], i: number): T[] => {\n if (i > -1) v.splice(i, 1)\n return v\n}\n\nexport function clear<T>(v: T[]): T[] {\n while (v.length > 0) v.pop()\n return v\n}\n\nexport type IndexOptions = {\n step?: number\n loop?: boolean\n}\n\nexport function nextIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n const next = idx + step\n const len = v.length\n const last = len - 1\n if (idx === -1) return step > 0 ? 0 : last\n if (next < 0) return loop ? last : 0\n if (next >= len) return loop ? 0 : idx > len ? len : idx\n return next\n}\n\nexport function next<T>(v: T[], idx: number, opts: IndexOptions = {}): T | undefined {\n return v[nextIndex(v, idx, opts)]\n}\n\nexport function prevIndex<T>(v: T[], idx: number, opts: IndexOptions = {}): number {\n const { step = 1, loop = true } = opts\n return nextIndex(v, idx, { step: -step, loop })\n}\n\nexport function prev<T>(v: T[], index: number, opts: IndexOptions = {}): T | undefined {\n return v[prevIndex(v, index, opts)]\n}\n\nexport const chunk = <T>(v: T[], size: number): T[][] => {\n const res: T[][] = []\n return v.reduce((rows, value, index) => {\n if (index % size === 0) rows.push([value])\n else last(rows)?.push(value)\n return rows\n }, res)\n}\n","export const runIfFn = <T>(\n v: T | undefined,\n ...a: T extends (...a: any[]) => void ? Parameters<T> : never\n): T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T> => {\n const res = typeof v === \"function\" ? v(...a) : v\n return res ?? undefined\n}\n\nexport const cast = <T>(v: unknown): T => v as T\n\nexport const noop = () => {}\n\nexport const callAll =\n <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) =>\n (...a: Parameters<T>) => {\n fns.forEach(function (fn) {\n fn?.(...a)\n })\n }\n\nexport const uuid = /*#__PURE__*/ (() => {\n let id = 0\n return () => {\n id++\n return id.toString(36)\n }\n})()\n","export const isDev = () => process.env.NODE_ENV !== \"production\"\nexport const isArray = (v: any): v is any[] => Array.isArray(v)\nexport const isBoolean = (v: any): v is boolean => v === true || v === false\nexport const isObject = (v: any): v is Record<string, any> => !(v == null || typeof v !== \"object\" || isArray(v))\nexport const isNumber = (v: any): v is number => typeof v === \"number\" && !Number.isNaN(v)\nexport const isString = (v: any): v is string => typeof v === \"string\"\nexport const isFunction = (v: any): v is Function => typeof v === \"function\"\n\nexport const hasProp = <T extends string>(obj: any, prop: T): obj is Record<T, any> =>\n Object.prototype.hasOwnProperty.call(obj, prop)\n","export function compact<T extends Record<string, unknown> | undefined>(obj: T): T {\n if (!isPlainObject(obj) || obj === undefined) {\n return obj\n }\n\n const keys = Reflect.ownKeys(obj).filter((key) => typeof key === \"string\")\n const filtered: Partial<T> = {}\n for (const key of keys) {\n const value = (obj as any)[key]\n if (value !== undefined) {\n filtered[key as keyof T] = compact(value)\n }\n }\n return filtered as T\n}\n\nexport function json(value: any) {\n return JSON.parse(JSON.stringify(value))\n}\n\nconst isPlainObject = (value: any) => {\n return value && typeof value === \"object\" && value.constructor === Object\n}\n","export function warn(m: string): void\nexport function warn(c: boolean, m: string): void\nexport function warn(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n console.warn(m)\n }\n}\n\nexport function invariant(m: string): void\nexport function invariant(c: boolean, m: string): void\nexport function invariant(...a: any[]): void {\n const m = a.length === 1 ? a[0] : a[1]\n const c = a.length === 2 ? a[0] : true\n if (c && process.env.NODE_ENV !== \"production\") {\n throw new Error(m)\n }\n}\n"],"mappings":";AAAO,SAAS,QAAW,GAAoC;AAC7D,MAAI,CAAC;AAAG,WAAO,CAAC;AAChB,SAAO,MAAM,QAAQ,CAAC,IAAI,IAAI,CAAC,CAAC;AAClC;AAEO,IAAM,aAAa,CAAC,WAAmB,MAAM,KAAK,MAAM,MAAM,EAAE,KAAK,CAAC;AAEtE,IAAM,QAAQ,CAAI,MAA0B,EAAE,CAAC;AAE/C,IAAM,OAAO,CAAI,MAA0B,EAAE,EAAE,SAAS,CAAC;AAEzD,IAAM,UAAU,CAAI,MAAoB,EAAE,WAAW;AAErD,IAAM,MAAM,CAAI,GAAQ,MAAoB,EAAE,QAAQ,CAAC,MAAM;AAE7D,IAAM,MAAM,CAAI,MAAW,UAAoB,EAAE,OAAO,KAAK;AAE7D,IAAM,SAAS,CAAI,GAAQ,SAAiB,SAAS,GAAG,EAAE,QAAQ,IAAI,CAAC;AAEvE,IAAM,WAAW,CAAI,GAAQ,MAAmB;AACrD,MAAI,IAAI;AAAI,MAAE,OAAO,GAAG,CAAC;AACzB,SAAO;AACT;AAEO,SAAS,MAAS,GAAa;AACpC,SAAO,EAAE,SAAS;AAAG,MAAE,IAAI;AAC3B,SAAO;AACT;AAOO,SAAS,UAAa,GAAQ,KAAa,OAAqB,CAAC,GAAW;AACjF,QAAM,EAAE,OAAO,GAAG,OAAO,KAAK,IAAI;AAClC,QAAMA,QAAO,MAAM;AACnB,QAAM,MAAM,EAAE;AACd,QAAMC,QAAO,MAAM;AAC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AAA,EAChB;AACF;AAIO,SAAS,aAAa,GAAgB;AAC3C,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACrC,QAAM,IAAI,EAAE,WAAW,IAAI,EAAE,CAAC,IAAI;AAClC,MAAI,KAAK,QAAQ,IAAI,aAAa,cAAc;AAC9C,UAAM,IAAI,MAAM,CAAC;AAAA,EACnB;AACF;","names":["next","last"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/utils",
3
- "version": "0.10.5",
3
+ "version": "0.11.1",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "js",
@@ -38,7 +38,7 @@
38
38
  "./package.json": "./package.json"
39
39
  },
40
40
  "scripts": {
41
- "build": "vite build -c ../../../vite.config.ts",
41
+ "build": "tsup",
42
42
  "lint": "eslint src --ext .ts,.tsx",
43
43
  "typecheck": "tsc --noEmit"
44
44
  }
package/dist/array.d.ts DELETED
@@ -1,19 +0,0 @@
1
- export declare function toArray<T>(v: T | T[] | undefined | null): T[];
2
- export declare const fromLength: (length: number) => number[];
3
- export declare const first: <T>(v: T[]) => T | undefined;
4
- export declare const last: <T>(v: T[]) => T | undefined;
5
- export declare const isEmpty: <T>(v: T[]) => boolean;
6
- export declare const has: <T>(v: T[], t: any) => boolean;
7
- export declare const add: <T>(v: T[], ...items: T[]) => T[];
8
- export declare const remove: <T>(v: T[], item: T) => T[];
9
- export declare const removeAt: <T>(v: T[], i: number) => T[];
10
- export declare function clear<T>(v: T[]): T[];
11
- export type IndexOptions = {
12
- step?: number;
13
- loop?: boolean;
14
- };
15
- export declare function nextIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
16
- export declare function next<T>(v: T[], idx: number, opts?: IndexOptions): T | undefined;
17
- export declare function prevIndex<T>(v: T[], idx: number, opts?: IndexOptions): number;
18
- export declare function prev<T>(v: T[], index: number, opts?: IndexOptions): T | undefined;
19
- export declare const chunk: <T>(v: T[], size: number) => T[][];
package/dist/array.js DELETED
@@ -1,75 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- function toArray(v) {
6
- if (!v)
7
- return [];
8
- return Array.isArray(v) ? v : [v];
9
- }
10
- const fromLength = (length) => Array.from(Array(length).keys());
11
- const first = (v) => v[0];
12
- const last = (v) => v[v.length - 1];
13
- const isEmpty = (v) => v.length === 0;
14
- const has = (v, t) => v.indexOf(t) !== -1;
15
- const add = (v, ...items) => v.concat(items);
16
- const remove = (v, item) => removeAt(v, v.indexOf(item));
17
- const removeAt = (v, i) => {
18
- if (i > -1)
19
- v.splice(i, 1);
20
- return v;
21
- };
22
- function clear(v) {
23
- while (v.length > 0)
24
- v.pop();
25
- return v;
26
- }
27
- function nextIndex(v, idx, opts = {}) {
28
- const { step = 1, loop = true } = opts;
29
- const next2 = idx + step;
30
- const len = v.length;
31
- const last2 = len - 1;
32
- if (idx === -1)
33
- return step > 0 ? 0 : last2;
34
- if (next2 < 0)
35
- return loop ? last2 : 0;
36
- if (next2 >= len)
37
- return loop ? 0 : idx > len ? len : idx;
38
- return next2;
39
- }
40
- function next(v, idx, opts = {}) {
41
- return v[nextIndex(v, idx, opts)];
42
- }
43
- function prevIndex(v, idx, opts = {}) {
44
- const { step = 1, loop = true } = opts;
45
- return nextIndex(v, idx, { step: -step, loop });
46
- }
47
- function prev(v, index, opts = {}) {
48
- return v[prevIndex(v, index, opts)];
49
- }
50
- const chunk = (v, size) => {
51
- const res = [];
52
- return v.reduce((rows, value, index) => {
53
- if (index % size === 0)
54
- rows.push([value]);
55
- else
56
- last(rows)?.push(value);
57
- return rows;
58
- }, res);
59
- };
60
-
61
- exports.add = add;
62
- exports.chunk = chunk;
63
- exports.clear = clear;
64
- exports.first = first;
65
- exports.fromLength = fromLength;
66
- exports.has = has;
67
- exports.isEmpty = isEmpty;
68
- exports.last = last;
69
- exports.next = next;
70
- exports.nextIndex = nextIndex;
71
- exports.prev = prev;
72
- exports.prevIndex = prevIndex;
73
- exports.remove = remove;
74
- exports.removeAt = removeAt;
75
- exports.toArray = toArray;
package/dist/array.mjs DELETED
@@ -1,57 +0,0 @@
1
- function toArray(v) {
2
- if (!v)
3
- return [];
4
- return Array.isArray(v) ? v : [v];
5
- }
6
- const fromLength = (length) => Array.from(Array(length).keys());
7
- const first = (v) => v[0];
8
- const last = (v) => v[v.length - 1];
9
- const isEmpty = (v) => v.length === 0;
10
- const has = (v, t) => v.indexOf(t) !== -1;
11
- const add = (v, ...items) => v.concat(items);
12
- const remove = (v, item) => removeAt(v, v.indexOf(item));
13
- const removeAt = (v, i) => {
14
- if (i > -1)
15
- v.splice(i, 1);
16
- return v;
17
- };
18
- function clear(v) {
19
- while (v.length > 0)
20
- v.pop();
21
- return v;
22
- }
23
- function nextIndex(v, idx, opts = {}) {
24
- const { step = 1, loop = true } = opts;
25
- const next2 = idx + step;
26
- const len = v.length;
27
- const last2 = len - 1;
28
- if (idx === -1)
29
- return step > 0 ? 0 : last2;
30
- if (next2 < 0)
31
- return loop ? last2 : 0;
32
- if (next2 >= len)
33
- return loop ? 0 : idx > len ? len : idx;
34
- return next2;
35
- }
36
- function next(v, idx, opts = {}) {
37
- return v[nextIndex(v, idx, opts)];
38
- }
39
- function prevIndex(v, idx, opts = {}) {
40
- const { step = 1, loop = true } = opts;
41
- return nextIndex(v, idx, { step: -step, loop });
42
- }
43
- function prev(v, index, opts = {}) {
44
- return v[prevIndex(v, index, opts)];
45
- }
46
- const chunk = (v, size) => {
47
- const res = [];
48
- return v.reduce((rows, value, index) => {
49
- if (index % size === 0)
50
- rows.push([value]);
51
- else
52
- last(rows)?.push(value);
53
- return rows;
54
- }, res);
55
- };
56
-
57
- export { add, chunk, clear, first, fromLength, has, isEmpty, last, next, nextIndex, prev, prevIndex, remove, removeAt, toArray };
@@ -1,5 +0,0 @@
1
- export declare const runIfFn: <T>(v: T | undefined, ...a: T extends (...a: any[]) => void ? Parameters<T> : never) => T extends (...a: any[]) => void ? NonNullable<ReturnType<T>> : NonNullable<T>;
2
- export declare const cast: <T>(v: unknown) => T;
3
- export declare const noop: () => void;
4
- export declare const callAll: <T extends (...a: any[]) => void>(...fns: (T | undefined)[]) => (...a: Parameters<T>) => void;
5
- export declare const uuid: () => string;
package/dist/functions.js DELETED
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const runIfFn = (v, ...a) => {
6
- const res = typeof v === "function" ? v(...a) : v;
7
- return res ?? void 0;
8
- };
9
- const cast = (v) => v;
10
- const noop = () => {
11
- };
12
- const callAll = (...fns) => (...a) => {
13
- fns.forEach(function(fn) {
14
- fn?.(...a);
15
- });
16
- };
17
- const uuid = /* @__PURE__ */ (() => {
18
- let id = 0;
19
- return () => {
20
- id++;
21
- return id.toString(36);
22
- };
23
- })();
24
-
25
- exports.callAll = callAll;
26
- exports.cast = cast;
27
- exports.noop = noop;
28
- exports.runIfFn = runIfFn;
29
- exports.uuid = uuid;
@@ -1,21 +0,0 @@
1
- const runIfFn = (v, ...a) => {
2
- const res = typeof v === "function" ? v(...a) : v;
3
- return res ?? void 0;
4
- };
5
- const cast = (v) => v;
6
- const noop = () => {
7
- };
8
- const callAll = (...fns) => (...a) => {
9
- fns.forEach(function(fn) {
10
- fn?.(...a);
11
- });
12
- };
13
- const uuid = /* @__PURE__ */ (() => {
14
- let id = 0;
15
- return () => {
16
- id++;
17
- return id.toString(36);
18
- };
19
- })();
20
-
21
- export { callAll, cast, noop, runIfFn, uuid };
package/dist/guard.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export declare const isDev: () => boolean;
2
- export declare const isArray: (v: any) => v is any[];
3
- export declare const isBoolean: (v: any) => v is boolean;
4
- export declare const isObject: (v: any) => v is Record<string, any>;
5
- export declare const isNumber: (v: any) => v is number;
6
- export declare const isString: (v: any) => v is string;
7
- export declare const isFunction: (v: any) => v is Function;
8
- export declare const hasProp: <T extends string>(obj: any, prop: T) => obj is Record<T, any>;
package/dist/guard.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const isDev = () => process.env.NODE_ENV !== "production";
6
- const isArray = (v) => Array.isArray(v);
7
- const isBoolean = (v) => v === true || v === false;
8
- const isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
9
- const isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
10
- const isString = (v) => typeof v === "string";
11
- const isFunction = (v) => typeof v === "function";
12
- const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
13
-
14
- exports.hasProp = hasProp;
15
- exports.isArray = isArray;
16
- exports.isBoolean = isBoolean;
17
- exports.isDev = isDev;
18
- exports.isFunction = isFunction;
19
- exports.isNumber = isNumber;
20
- exports.isObject = isObject;
21
- exports.isString = isString;
package/dist/guard.mjs DELETED
@@ -1,10 +0,0 @@
1
- const isDev = () => process.env.NODE_ENV !== "production";
2
- const isArray = (v) => Array.isArray(v);
3
- const isBoolean = (v) => v === true || v === false;
4
- const isObject = (v) => !(v == null || typeof v !== "object" || isArray(v));
5
- const isNumber = (v) => typeof v === "number" && !Number.isNaN(v);
6
- const isString = (v) => typeof v === "string";
7
- const isFunction = (v) => typeof v === "function";
8
- const hasProp = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop);
9
-
10
- export { hasProp, isArray, isBoolean, isDev, isFunction, isNumber, isObject, isString };
package/dist/object.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function compact<T extends Record<string, unknown> | undefined>(obj: T): T;
2
- export declare function json(value: any): any;
package/dist/object.js DELETED
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- function compact(obj) {
6
- if (!isPlainObject(obj) || obj === void 0) {
7
- return obj;
8
- }
9
- const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
10
- const filtered = {};
11
- for (const key of keys) {
12
- const value = obj[key];
13
- if (value !== void 0) {
14
- filtered[key] = compact(value);
15
- }
16
- }
17
- return filtered;
18
- }
19
- function json(value) {
20
- return JSON.parse(JSON.stringify(value));
21
- }
22
- const isPlainObject = (value) => {
23
- return value && typeof value === "object" && value.constructor === Object;
24
- };
25
-
26
- exports.compact = compact;
27
- exports.json = json;
package/dist/object.mjs DELETED
@@ -1,22 +0,0 @@
1
- function compact(obj) {
2
- if (!isPlainObject(obj) || obj === void 0) {
3
- return obj;
4
- }
5
- const keys = Reflect.ownKeys(obj).filter((key) => typeof key === "string");
6
- const filtered = {};
7
- for (const key of keys) {
8
- const value = obj[key];
9
- if (value !== void 0) {
10
- filtered[key] = compact(value);
11
- }
12
- }
13
- return filtered;
14
- }
15
- function json(value) {
16
- return JSON.parse(JSON.stringify(value));
17
- }
18
- const isPlainObject = (value) => {
19
- return value && typeof value === "object" && value.constructor === Object;
20
- };
21
-
22
- export { compact, json };
package/dist/warning.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function warn(m: string): void;
2
- export declare function warn(c: boolean, m: string): void;
3
- export declare function invariant(m: string): void;
4
- export declare function invariant(c: boolean, m: string): void;
package/dist/warning.js DELETED
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- function warn(...a) {
6
- const m = a.length === 1 ? a[0] : a[1];
7
- const c = a.length === 2 ? a[0] : true;
8
- if (c && process.env.NODE_ENV !== "production") {
9
- console.warn(m);
10
- }
11
- }
12
- function invariant(...a) {
13
- const m = a.length === 1 ? a[0] : a[1];
14
- const c = a.length === 2 ? a[0] : true;
15
- if (c && process.env.NODE_ENV !== "production") {
16
- throw new Error(m);
17
- }
18
- }
19
-
20
- exports.invariant = invariant;
21
- exports.warn = warn;
package/dist/warning.mjs DELETED
@@ -1,16 +0,0 @@
1
- function warn(...a) {
2
- const m = a.length === 1 ? a[0] : a[1];
3
- const c = a.length === 2 ? a[0] : true;
4
- if (c && process.env.NODE_ENV !== "production") {
5
- console.warn(m);
6
- }
7
- }
8
- function invariant(...a) {
9
- const m = a.length === 1 ? a[0] : a[1];
10
- const c = a.length === 2 ? a[0] : true;
11
- if (c && process.env.NODE_ENV !== "production") {
12
- throw new Error(m);
13
- }
14
- }
15
-
16
- export { invariant, warn };