@zinaid/utils 0.0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Abraham Arango
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ export * from './utils';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,46 @@
1
+ import { castableToArray as s, compareValues as t, entriesKeyValue as r, getAccessibleValues as a, isAccessibleData as o, isArray as l, isBoolean as b, isFalsy as n, isFiniteNumber as u, isFloat as c, isFunction as y, isInteger as m, isMap as p, isNegativeNumber as A, isNonPrimitive as N, isNull as S, isNumber as g, isObject as F, isObjectAny as v, isPositiveNumber as T, isPrimitive as f, isSet as j, isString as O, isStringable as P, isSymbol as V, isTruthy as d, isTruthyObject as h, isUndefined as k, isWeakMap as q, isWeakSet as w, looseEqual as z, lowerFirst as D, normalizeToArray as E, objectToString as J, resolveDefault as M, strictEqual as U, toArrayable as W, toJsonSerializable as x, toJsonable as B, toLower as I, toUpper as K, typeOf as L, upperFirst as C } from "./utils.js";
2
+ export {
3
+ s as castableToArray,
4
+ t as compareValues,
5
+ r as entriesKeyValue,
6
+ a as getAccessibleValues,
7
+ o as isAccessibleData,
8
+ l as isArray,
9
+ b as isBoolean,
10
+ n as isFalsy,
11
+ u as isFiniteNumber,
12
+ c as isFloat,
13
+ y as isFunction,
14
+ m as isInteger,
15
+ p as isMap,
16
+ A as isNegativeNumber,
17
+ N as isNonPrimitive,
18
+ S as isNull,
19
+ g as isNumber,
20
+ F as isObject,
21
+ v as isObjectAny,
22
+ T as isPositiveNumber,
23
+ f as isPrimitive,
24
+ j as isSet,
25
+ O as isString,
26
+ P as isStringable,
27
+ V as isSymbol,
28
+ d as isTruthy,
29
+ h as isTruthyObject,
30
+ k as isUndefined,
31
+ q as isWeakMap,
32
+ w as isWeakSet,
33
+ z as looseEqual,
34
+ D as lowerFirst,
35
+ E as normalizeToArray,
36
+ J as objectToString,
37
+ M as resolveDefault,
38
+ U as strictEqual,
39
+ W as toArrayable,
40
+ x as toJsonSerializable,
41
+ B as toJsonable,
42
+ I as toLower,
43
+ K as toUpper,
44
+ L as typeOf,
45
+ C as upperFirst
46
+ };
@@ -0,0 +1,514 @@
1
+ import { DataItems } from '../../types/src/index.ts';
2
+ /**
3
+ * Check if a value is an array.
4
+ *
5
+ * @param value - The value to check
6
+ * @returns True if the value is an array
7
+ */
8
+ export declare function isArray<T>(value: DataItems<T> | T[] | unknown): value is T[];
9
+ /**
10
+ * Check if a value is an object (not null, not array).
11
+ *
12
+ * @param value - The value to check
13
+ * @returns True if the value is an object
14
+ *
15
+ * @example
16
+ *
17
+ * isObject({a: 1, b: 2}); -> true
18
+ * isObject([1, 2, 3]); -> false
19
+ * isObject(null); -> false
20
+ */
21
+ export declare function isObject<T, K extends PropertyKey = PropertyKey>(value: DataItems<T, K> | unknown): value is Record<K, T>;
22
+ /**
23
+ * Check if a value is any object (including arrays, null).
24
+ *
25
+ * @param value - The value to check
26
+ * @returns True if the value is any object
27
+ *
28
+ * @example
29
+ *
30
+ * isObjectAny({a: 1, b: 2}); -> true
31
+ * isObjectAny([1, 2, 3]); -> true
32
+ * isObjectAny(null); -> true
33
+ */
34
+ export declare function isObjectAny(value: unknown): value is object;
35
+ /**
36
+ * Check if a value is a truthy object (not null, not undefined, and an object).
37
+ *
38
+ * @param value - The value to check
39
+ * @returns True if the value is a truthy object
40
+ *
41
+ * @example
42
+ *
43
+ * isTruthyObject({a: 1, b: 2}); -> true
44
+ * isTruthyObject([1, 2, 3]); -> true
45
+ * isTruthyObject(null); -> false
46
+ * isTruthyObject(undefined); -> false
47
+ */
48
+ export declare function isTruthyObject(value: unknown): value is object;
49
+ /**
50
+ * Check if a value is a string.
51
+ *
52
+ * @param value - The value to check
53
+ * @returns True if the value is a string
54
+ *
55
+ * @example
56
+ *
57
+ * isString("hello"); -> true
58
+ * isString(123); -> false
59
+ * isString(null); -> false
60
+ */
61
+ export declare function isString(value: unknown): value is string;
62
+ /**
63
+ * Convert a string to lower-case.
64
+ */
65
+ export declare function toLower(value: string): string;
66
+ /**
67
+ * Convert a string to upper-case.
68
+ */
69
+ export declare function toUpper(value: string): string;
70
+ /**
71
+ * Convert the first character of a string to lower-case.
72
+ */
73
+ export declare function lowerFirst(value: string): string;
74
+ /**
75
+ * Convert the first character of a string to upper-case.
76
+ */
77
+ export declare function upperFirst(value: string): string;
78
+ /**
79
+ * Check if a value is stringable (can be converted to a string).
80
+ *
81
+ * @param value - The value to check
82
+ * @returns True if the value is stringable
83
+ *
84
+ * @example
85
+ *
86
+ * isStringable("hello"); -> true
87
+ * isStringable(new Stringable('test')); -> true
88
+ * isStringable({ toString: () => "world" }); -> true
89
+ * isStringable(123); -> false
90
+ * isStringable(null); -> false
91
+ */
92
+ export declare function isStringable(value: unknown): value is string | {
93
+ toString(): string;
94
+ };
95
+ /**
96
+ * Check if a value is an object with a toString method.
97
+ *
98
+ * @param value - The value to check
99
+ * @returns True if the value is an object with a toString method
100
+ */
101
+ export declare function objectToString(value: unknown): value is {
102
+ toString(): string;
103
+ };
104
+ /**
105
+ * Check if a value is a number (and not NaN).
106
+ *
107
+ * @param value - The value to check
108
+ * @returns True if the value is a valid number
109
+ *
110
+ * @example
111
+ *
112
+ * isNumber(123); -> true
113
+ * isNumber(3.14); -> true
114
+ * isNumber(NaN); -> false
115
+ * isNumber("123"); -> false
116
+ */
117
+ export declare function isNumber(value: unknown): value is number;
118
+ /**
119
+ * Check if a value is an integer.
120
+ *
121
+ * @param value - The value to check
122
+ * @returns True if the value is an integer
123
+ */
124
+ export declare function isInteger(value: unknown): value is number;
125
+ /**
126
+ * Check if a value is a float.
127
+ *
128
+ * @param value - The value to check
129
+ * @returns True if the value is a float
130
+ */
131
+ export declare function isFloat(value: unknown): value is number;
132
+ /**
133
+ * Check if a value is a positive number.
134
+ *
135
+ * @param value - The value to check
136
+ * @returns True if the value is a positive number
137
+ */
138
+ export declare function isPositiveNumber(value: unknown): value is number;
139
+ /**
140
+ * Check if a value is a negative number.
141
+ *
142
+ * @param value - The value to check
143
+ * @returns True if the value is a negative number
144
+ */
145
+ export declare function isNegativeNumber(value: unknown): value is number;
146
+ /**
147
+ * Check if a value is a boolean.
148
+ *
149
+ * @param value - The value to check
150
+ * @returns True if the value is a boolean
151
+ *
152
+ * @example
153
+ *
154
+ * isBoolean(true); -> true
155
+ * isBoolean(false); -> true
156
+ * isBoolean(0); -> false
157
+ * isBoolean("true"); -> false
158
+ */
159
+ export declare function isBoolean(value: unknown): value is boolean;
160
+ /**
161
+ * Check if a value is a function.
162
+ *
163
+ * @param value - The value to check
164
+ * @returns True if the value is a function
165
+ *
166
+ * @example
167
+ *
168
+ * isFunction(() => {}); -> true
169
+ * isFunction(Math.max); -> true
170
+ * isFunction("function"); -> false
171
+ * isFunction({}); -> false
172
+ */
173
+ export declare function isFunction<T extends (...args: unknown[]) => unknown>(value: unknown): value is T;
174
+ /**
175
+ * Check if a value is undefined.
176
+ *
177
+ * @param value - The value to check
178
+ * @returns True if the value is undefined
179
+ *
180
+ * @example
181
+ *
182
+ * isUndefined(undefined); -> true
183
+ * isUndefined(null); -> false
184
+ * isUndefined(""); -> false
185
+ * isUndefined(0); -> false
186
+ */
187
+ export declare function isUndefined(value: unknown): value is undefined;
188
+ /**
189
+ * Check if a value is a symbol.
190
+ *
191
+ * @param value - The value to check
192
+ * @returns True if the value is a symbol
193
+ *
194
+ * @example
195
+ *
196
+ * isSymbol(Symbol('test')); -> true
197
+ * isSymbol(Symbol.iterator); -> true
198
+ * isSymbol("symbol"); -> false
199
+ * isSymbol({}); -> false
200
+ */
201
+ export declare function isSymbol(value: unknown): value is symbol;
202
+ /**
203
+ * Check if a value is null.
204
+ *
205
+ * @param value - The value to check
206
+ * @returns True if the value is null
207
+ *
208
+ * @example
209
+ *
210
+ * isNull(null); -> true
211
+ * isNull(undefined); -> false
212
+ * isNull(""); -> false
213
+ * isNull(0); -> false
214
+ */
215
+ export declare function isNull(value: unknown): value is null;
216
+ /**
217
+ * Check if a value is a Map.
218
+ *
219
+ * @param value - The value to check
220
+ * @returns True if the value is a Map
221
+ *
222
+ * @example
223
+ *
224
+ * isMap(new Map()); -> true
225
+ * isMap({}); -> false
226
+ * isMap([]); -> false
227
+ */
228
+ export declare function isMap<K, V>(value: unknown): value is Map<K, V>;
229
+ /**
230
+ * Check if a value is a Set.
231
+ *
232
+ * @param value - The value to check
233
+ * @returns True if the value is a Set
234
+ *
235
+ * @example
236
+ *
237
+ * isSet(new Set()); -> true
238
+ * isSet({}); -> false
239
+ * isSet([]); -> false
240
+ */
241
+ export declare function isSet<T>(value: unknown): value is Set<T>;
242
+ /**
243
+ * Check if a value is a WeakMap.
244
+ *
245
+ * @param value - The value to check
246
+ * @returns True if the value is a WeakMap
247
+ */
248
+ export declare function isWeakMap<K extends object, V>(value: unknown): value is WeakMap<K, V>;
249
+ /**
250
+ * Check if a value is a WeakSet.
251
+ *
252
+ * @param value - The value to check
253
+ * @returns True if the value is a WeakSet
254
+ */
255
+ export declare function isWeakSet<T extends object>(value: unknown): value is WeakSet<T>;
256
+ /**
257
+ * Check if a value is arrayable (has a toArray method).
258
+ *
259
+ * @param value - The value to check
260
+ * @returns True if the value is arrayable
261
+ *
262
+ * @example
263
+ *
264
+ * isArrayable({ toArray: () => [1, 2, 3] }); -> true
265
+ * isArrayable([1, 2, 3]); -> false
266
+ * isArrayable("hello"); -> false
267
+ */
268
+ export declare function toArrayable<T>(value: unknown): value is {
269
+ toArray(): T[];
270
+ };
271
+ /**
272
+ * Check if a value is jsonable (has a toJSON method).
273
+ *
274
+ * @param value - The value to check
275
+ * @returns True if the value is jsonable
276
+ *
277
+ * @example
278
+ *
279
+ * isJsonable({ toJSON: () => ({ a: 1 }) }); -> true
280
+ * isJsonable("hello"); -> false
281
+ */
282
+ export declare function toJsonable<T>(value: unknown): value is {
283
+ toJson(): T;
284
+ } | {
285
+ toJSON(): T;
286
+ };
287
+ /**
288
+ * Check if a value is json serializable (has a jsonSerialize method).
289
+ *
290
+ * @param value - The value to check
291
+ * @returns True if the value is json serializable
292
+ *
293
+ * @example
294
+ *
295
+ * isJsonSerializable({ jsonSerialize: () => ({ a: 1 }) }); -> true
296
+ * isJsonSerializable("hello"); -> false
297
+ */
298
+ export declare function toJsonSerializable<T>(value: unknown): value is {
299
+ jsonSerialize(): T;
300
+ };
301
+ /**
302
+ * Check if a value is falsy (undefined, null, false, 0, "", empty array/object).
303
+ *
304
+ * @param value - The value to check
305
+ * @returns True if the value is falsy
306
+ *
307
+ * @example
308
+ *
309
+ * isFalsy(undefined); -> true
310
+ * isFalsy(null); -> true
311
+ * isFalsy(false); -> true
312
+ * isFalsy(0); -> true
313
+ * isFalsy(""); -> true
314
+ * isFalsy([]); -> true
315
+ * isFalsy({}); -> true
316
+ * isFalsy("hello"); -> false
317
+ * isFalsy([1, 2, 3]); -> false
318
+ * isFalsy({ a: 1 }); -> false
319
+ */
320
+ export declare function isFalsy<TValue = unknown>(value: TValue): boolean;
321
+ /**
322
+ * Check if a value is truthy (not falsy).
323
+ *
324
+ * @param value - The value to check
325
+ * @returns True if the value is truthy
326
+ *
327
+ * @example
328
+ *
329
+ * isTruthy(1); -> true
330
+ * isTruthy("hello"); -> true
331
+ * isTruthy([1, 2, 3]); -> true
332
+ * isTruthy({ a: 1 }); -> true
333
+ * isTruthy(0); -> false
334
+ * isTruthy(""); -> false
335
+ * isTruthy([]); -> false
336
+ * isTruthy({}); -> false
337
+ */
338
+ export declare function isTruthy(value: unknown): boolean;
339
+ /**
340
+ * Get a more specific type description for debugging purposes.
341
+ * Differentiates between null, arrays, and other types.
342
+ *
343
+ * @param {unknown} v - The value to get the type of.
344
+ * @returns {string} A string describing the type.
345
+ * @example
346
+ * Get specific types
347
+ * typeOf(null); -> "null"
348
+ * typeOf([]); -> "array"
349
+ * typeOf({}); -> "object"
350
+ */
351
+ export declare function typeOf(v: unknown): string;
352
+ /**
353
+ * Check if a value is a primitive type (null, boolean, number, string, symbol, undefined).
354
+ *
355
+ * @param value - The value to check
356
+ * @returns True if the value is a primitive
357
+ *
358
+ * @example
359
+ *
360
+ * isPrimitive(123); -> true
361
+ * isPrimitive("hello"); -> true
362
+ * isPrimitive(null); -> true
363
+ * isPrimitive({}); -> false
364
+ * isPrimitive([]); -> false
365
+ */
366
+ export declare function isPrimitive(value: unknown): boolean;
367
+ /**
368
+ * Check if a value is a non-primitive type (object, array, function, etc.).
369
+ *
370
+ * @param value - The value to check
371
+ * @returns True if the value is a non-primitive
372
+ *
373
+ * @example
374
+ *
375
+ * isNonPrimitive({}); -> true
376
+ * isNonPrimitive([]); -> true
377
+ * isNonPrimitive(() => {}); -> true
378
+ * isNonPrimitive(123); -> false
379
+ * isNonPrimitive("hello"); -> false
380
+ */
381
+ export declare function isNonPrimitive(value: unknown): boolean;
382
+ /**
383
+ * Check if a value is a finite number.
384
+ *
385
+ * @param value - The value to check
386
+ * @returns True if the value is a finite number
387
+ *
388
+ * @example
389
+ *
390
+ * isFiniteNumber(123); -> true
391
+ * isFiniteNumber(3.14); -> true
392
+ * isFiniteNumber(Infinity); -> false
393
+ * isFiniteNumber(NaN); -> false
394
+ * isFiniteNumber("123"); -> false
395
+ */
396
+ export declare function isFiniteNumber(value: unknown): value is number;
397
+ /**
398
+ * Convert a value to an array if it's already an array, otherwise return null.
399
+ * Used internally for safe array conversion without coercion.
400
+ *
401
+ * @param {unknown} value - The value to convert.
402
+ * @returns {unknown[] | null} The array if value is an array, null otherwise.
403
+ * @example
404
+ * Convert to array
405
+ * toArray([1, 2, 3]); -> [1, 2, 3]
406
+ * toArray("hello"); -> null
407
+ * toArray({}); -> null
408
+ */
409
+ export declare function castableToArray<T>(value: unknown): T[] | null;
410
+ /**
411
+ * Helper function to safely compare two unknown values for sorting.
412
+ * Provides stable comparison for objects using JSON serialization.
413
+ *
414
+ * @param a - First value to compare
415
+ * @param b - Second value to compare
416
+ * @returns -1 if a < b, 1 if a > b, 0 if equal
417
+ *
418
+ * @example
419
+ * compareValues(1, 2); -> -1
420
+ * compareValues('b', 'a'); -> 1
421
+ * compareValues({x: 1}, {x: 1}); -> 0
422
+ */
423
+ export declare function compareValues(a: unknown, b: unknown): number;
424
+ /**
425
+ * Helper function to resolve a default value (either direct value or lazy function).
426
+ *
427
+ * @param defaultValue - The default value or lazy function
428
+ * @returns The resolved default value
429
+ *
430
+ * @example
431
+ * resolveDefault('hello'); -> 'hello'
432
+ * resolveDefault(() => 'world'); -> 'world'
433
+ * resolveDefault(undefined); -> null
434
+ */
435
+ export declare function resolveDefault<D>(defaultValue?: D | (() => D)): D | null;
436
+ /**
437
+ * Helper function to normalize data to an array format.
438
+ * Handles arrays only now.
439
+ *
440
+ * @param data - The data to normalize (array or other)
441
+ * @returns An array representation of the data, or null if not accessible
442
+ *
443
+ * @example
444
+ * normalizeToArray([1, 2, 3]); -> [1, 2, 3]
445
+ * normalizeToArray('hello'); -> null
446
+ */
447
+ export declare function normalizeToArray<T>(data: ReadonlyArray<T> | unknown): T[] | null;
448
+ /**
449
+ * Helper function to check if data is accessible (array only).
450
+ *
451
+ * @param data - The data to check
452
+ * @returns True if data is an array
453
+ *
454
+ * @example
455
+ * isAccessibleData([1, 2, 3]); -> true
456
+ * isAccessibleData('hello'); -> false
457
+ */
458
+ export declare function isAccessibleData(data: unknown): boolean;
459
+ /**
460
+ * Helper function to get normalized values from data.
461
+ * Returns array values or empty array if data is not accessible.
462
+ *
463
+ * @param data - The data to get values from
464
+ * @returns Array of values or empty array
465
+ *
466
+ * @example
467
+ * getAccessibleValues([1, 2, 3]); -> [1, 2, 3]
468
+ * getAccessibleValues('hello'); -> []
469
+ */
470
+ export declare function getAccessibleValues<T>(data: ReadonlyArray<T> | unknown): T[];
471
+ /**
472
+ * PHP-like loose equality comparison.
473
+ * Mimics PHP's == operator behavior where null, false, 0, '', and [] are considered loosely equal.
474
+ * Also handles deep comparison for arrays and objects.
475
+ *
476
+ * @param a - First value to compare
477
+ * @param b - Second value to compare
478
+ * @returns True if values are loosely equal in PHP-like manner
479
+ *
480
+ * @example
481
+ *
482
+ * looseEqual(null, false); -> true
483
+ * looseEqual(null, 0); -> true
484
+ * looseEqual(null, ''); -> true
485
+ * looseEqual(0, false); -> true
486
+ * looseEqual(1, '1'); -> true
487
+ * looseEqual(['a'], ['a']); -> true
488
+ */
489
+ export declare function looseEqual(a: unknown, b: unknown): boolean;
490
+ /**
491
+ * PHP-like strict equality comparison (=== operator).
492
+ * Performs strict type checking for primitives but value-based comparison for arrays and objects.
493
+ * NOTE: For class instances (objects with constructors other than Object), uses reference equality.
494
+ *
495
+ * @param a - First value to compare
496
+ * @param b - Second value to compare
497
+ * @returns True if values are strictly equal in PHP-like manner
498
+ *
499
+ * @example
500
+ *
501
+ * strictEqual(1, 1); -> true
502
+ * strictEqual(1, '1'); -> false (different types)
503
+ * strictEqual(['a'], ['a']); -> true (same array content)
504
+ * strictEqual({a: 1}, {a: 1}); -> true (same object content)
505
+ */
506
+ export declare function strictEqual(a: unknown, b: unknown): boolean;
507
+ /**
508
+ * Figures out if the entry key should be a number or a string.
509
+ *
510
+ * @param value - The entry key value (number, string, or symbol)
511
+ * @returns The entry key as a number if it can be converted, otherwise returns the original value
512
+ */
513
+ export declare function entriesKeyValue<T extends PropertyKey>(value: T): T extends `${number}` ? number : T;
514
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,EAAE,GAAG,OAAO,GAAG,KAAK,IAAI,CAAC,EAAE,CAE5E;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,SAAS,WAAW,GAAG,WAAW,EAC3D,KAAK,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,GACjC,KAAK,IAAI,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAEvB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE3D;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE9D;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEx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,CAKZ;AAED;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,CAEvD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,CAAC,EAAE,CAG5E;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAoG1D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,OAAO,GAAG,OAAO,CAqE3D;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,WAAW,EACjD,KAAK,EAAE,CAAC,GACT,CAAC,SAAS,GAAG,MAAM,EAAE,GAAG,MAAM,GAAG,CAAC,CAMpC"}
package/dist/utils.js ADDED
@@ -0,0 +1,240 @@
1
+ function l(r) {
2
+ return Array.isArray(r);
3
+ }
4
+ function y(r) {
5
+ return !f(r) && typeof r == "object" && !l(r);
6
+ }
7
+ function h(r) {
8
+ return typeof r == "object";
9
+ }
10
+ function J(r) {
11
+ return !f(r) && !p(r) && h(r);
12
+ }
13
+ function A(r) {
14
+ return typeof r == "string";
15
+ }
16
+ function d(r) {
17
+ return r.toLowerCase();
18
+ }
19
+ function z(r) {
20
+ return r.toUpperCase();
21
+ }
22
+ function T(r) {
23
+ const t = [...r];
24
+ return t.length === 0 ? r : (t[0] = t[0].toLowerCase(), t.join(""));
25
+ }
26
+ function B(r) {
27
+ const t = [...r];
28
+ return t.length === 0 ? r : (t[0] = t[0].toUpperCase(), t.join(""));
29
+ }
30
+ function P(r) {
31
+ return !!(A(r) || o(r) || j(r));
32
+ }
33
+ function j(r) {
34
+ return !!(y(r) && c(r.toString));
35
+ }
36
+ function o(r) {
37
+ return typeof r == "number" && !isNaN(r);
38
+ }
39
+ function w(r) {
40
+ return o(r) && Number.isInteger(r);
41
+ }
42
+ function C(r) {
43
+ return o(r) && !Number.isInteger(r);
44
+ }
45
+ function M(r) {
46
+ return o(r) && r >= 0;
47
+ }
48
+ function U(r) {
49
+ return o(r) && r < 0;
50
+ }
51
+ function N(r) {
52
+ return typeof r == "boolean";
53
+ }
54
+ function c(r) {
55
+ return typeof r == "function";
56
+ }
57
+ function p(r) {
58
+ return typeof r > "u";
59
+ }
60
+ function m(r) {
61
+ return typeof r == "symbol";
62
+ }
63
+ function f(r) {
64
+ return r === null;
65
+ }
66
+ function S(r) {
67
+ return r instanceof Map;
68
+ }
69
+ function b(r) {
70
+ return r instanceof Set;
71
+ }
72
+ function W(r) {
73
+ return r instanceof WeakMap;
74
+ }
75
+ function I(r) {
76
+ return r instanceof WeakSet;
77
+ }
78
+ function L(r) {
79
+ return y(r) && !f(r) && c(r.toArray);
80
+ }
81
+ function q(r) {
82
+ if (!y(r) || f(r))
83
+ return !1;
84
+ const t = c(r.toJson), e = c(r.toJSON);
85
+ return t || e;
86
+ }
87
+ function D(r) {
88
+ return y(r) && !f(r) && c(r.jsonSerialize);
89
+ }
90
+ function k(r) {
91
+ return Number.isNaN(r) ? !0 : o(r) ? r === 0 : p(r) || f(r) ? !0 : N(r) ? r === !1 : A(r) ? r.trim() === "" : S(r) || b(r) ? r.size === 0 : l(r) ? r.length === 0 : y(r) ? Object.keys(r).length === 0 : !1;
92
+ }
93
+ function E(r) {
94
+ return !k(r);
95
+ }
96
+ function V(r) {
97
+ return f(r) ? "object" : l(r) ? "array" : typeof r;
98
+ }
99
+ function O(r) {
100
+ return f(r) || N(r) || o(r) || A(r) || m(r) || p(r);
101
+ }
102
+ function x(r) {
103
+ return !O(r);
104
+ }
105
+ function K(r) {
106
+ return o(r) && Number.isFinite(r);
107
+ }
108
+ function G(r) {
109
+ return l(r) ? r : null;
110
+ }
111
+ function H(r, t) {
112
+ if (r == null && t == null) return 0;
113
+ if (r == null) return -1;
114
+ if (t == null) return 1;
115
+ if (typeof r == "object" && typeof t == "object") {
116
+ const e = JSON.stringify(r), u = JSON.stringify(t);
117
+ return e < u ? -1 : e > u ? 1 : 0;
118
+ }
119
+ return r < t ? -1 : r > t ? 1 : 0;
120
+ }
121
+ function Q(r) {
122
+ return r === void 0 ? null : typeof r == "function" ? r() : r;
123
+ }
124
+ function F(r) {
125
+ return Array.isArray(r) ? r.slice() : null;
126
+ }
127
+ function R(r) {
128
+ return Array.isArray(r);
129
+ }
130
+ function X(r) {
131
+ return F(r) || [];
132
+ }
133
+ function g(r, t) {
134
+ if (r == t)
135
+ return !0;
136
+ if (typeof r == "boolean" || typeof t == "boolean") {
137
+ const i = typeof r == "boolean" ? r : t, n = typeof r == "boolean" ? t : r;
138
+ return i === !0 ? !(n === null || n === !1 || n === 0 || n === "" || Array.isArray(n) && n.length === 0) : n === null || n === 0 || n === "";
139
+ }
140
+ const e = r === null || r === !1 || r === 0 || r === "" || Array.isArray(r) && r.length === 0, u = t === null || t === !1 || t === 0 || t === "" || Array.isArray(t) && t.length === 0;
141
+ if (e && u)
142
+ return !0;
143
+ if (Array.isArray(r) && Array.isArray(t)) {
144
+ if (r.length !== t.length)
145
+ return !1;
146
+ for (let i = 0; i < r.length; i++)
147
+ if (!g(r[i], t[i]))
148
+ return !1;
149
+ return !0;
150
+ }
151
+ if (r !== null && t !== null && typeof r == "object" && typeof t == "object" && !Array.isArray(r) && !Array.isArray(t)) {
152
+ const i = Object.keys(r), n = Object.keys(t);
153
+ if (i.length !== n.length)
154
+ return !1;
155
+ for (const s of i)
156
+ if (!n.includes(s) || !g(
157
+ r[s],
158
+ t[s]
159
+ ))
160
+ return !1;
161
+ return !0;
162
+ }
163
+ return !1;
164
+ }
165
+ function a(r, t) {
166
+ if (r === t)
167
+ return !0;
168
+ if (Array.isArray(r) && Array.isArray(t)) {
169
+ if (r.length !== t.length)
170
+ return !1;
171
+ for (let e = 0; e < r.length; e++)
172
+ if (!a(r[e], t[e]))
173
+ return !1;
174
+ return !0;
175
+ }
176
+ if (r !== null && t !== null && typeof r == "object" && typeof t == "object" && !Array.isArray(r) && !Array.isArray(t)) {
177
+ const e = r.constructor === Object || r.constructor === void 0, u = t.constructor === Object || t.constructor === void 0;
178
+ if (!e || !u)
179
+ return !1;
180
+ const i = Object.keys(r), n = Object.keys(t);
181
+ if (i.length !== n.length)
182
+ return !1;
183
+ for (const s of i)
184
+ if (!n.includes(s) || !a(
185
+ r[s],
186
+ t[s]
187
+ ))
188
+ return !1;
189
+ return !0;
190
+ }
191
+ return !1;
192
+ }
193
+ function Y(r) {
194
+ return !isNaN(Number(r)) && !isNaN(parseFloat(String(r))) ? Number(r) : r;
195
+ }
196
+ export {
197
+ G as castableToArray,
198
+ H as compareValues,
199
+ Y as entriesKeyValue,
200
+ X as getAccessibleValues,
201
+ R as isAccessibleData,
202
+ l as isArray,
203
+ N as isBoolean,
204
+ k as isFalsy,
205
+ K as isFiniteNumber,
206
+ C as isFloat,
207
+ c as isFunction,
208
+ w as isInteger,
209
+ S as isMap,
210
+ U as isNegativeNumber,
211
+ x as isNonPrimitive,
212
+ f as isNull,
213
+ o as isNumber,
214
+ y as isObject,
215
+ h as isObjectAny,
216
+ M as isPositiveNumber,
217
+ O as isPrimitive,
218
+ b as isSet,
219
+ A as isString,
220
+ P as isStringable,
221
+ m as isSymbol,
222
+ E as isTruthy,
223
+ J as isTruthyObject,
224
+ p as isUndefined,
225
+ W as isWeakMap,
226
+ I as isWeakSet,
227
+ g as looseEqual,
228
+ T as lowerFirst,
229
+ F as normalizeToArray,
230
+ j as objectToString,
231
+ Q as resolveDefault,
232
+ a as strictEqual,
233
+ L as toArrayable,
234
+ D as toJsonSerializable,
235
+ q as toJsonable,
236
+ d as toLower,
237
+ z as toUpper,
238
+ V as typeOf,
239
+ B as upperFirst
240
+ };
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@zinaid/utils",
3
+ "version": "0.0.1",
4
+ "description": "A set of utility functions for the @zinaid packages.",
5
+ "type": "module",
6
+ "main": "dist/index.js",
7
+ "keywords": [],
8
+ "author": "",
9
+ "license": "MIT",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "build": "vite build"
15
+ },
16
+ "types": "dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "require": "./dist/index.js",
21
+ "types": "./dist/index.d.ts"
22
+ },
23
+ "./*": {
24
+ "import": "./dist/*.js",
25
+ "require": "./dist/*.js",
26
+ "types": "./dist/*.d.ts"
27
+ }
28
+ }
29
+ }