@h3ravel/support 0.13.0 → 0.14.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.cjs +946 -164
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +516 -65
- package/dist/index.d.ts +516 -65
- package/dist/index.js +937 -141
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -36,69 +36,37 @@ type TGeneric<V = any, K extends string = string> = Record<K, V>;
|
|
|
36
36
|
type XGeneric<V = TGeneric, T = any> = {
|
|
37
37
|
[key: string]: T;
|
|
38
38
|
} & V;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
* Alternates between two arrays, creating a zipped result.
|
|
57
|
-
*/
|
|
58
|
-
declare const alternate: <T>(a: T[], b: T[]) => T[];
|
|
59
|
-
/**
|
|
60
|
-
* Combine arrays and sum their values element by element.
|
|
61
|
-
*/
|
|
62
|
-
declare const combine: (...arr: number[][]) => number[];
|
|
63
|
-
/** Find the value associated with a given key. */
|
|
64
|
-
declare const find: <T>(key: T, arr: T[]) => T | null;
|
|
65
|
-
/** Returns a new array without the given indices. */
|
|
66
|
-
declare const forget: <T>(arr: T[], keys: number[]) => T[];
|
|
67
|
-
/** Remove the first element and return tuple [el, rest]. */
|
|
68
|
-
declare const first: <T>(arr: T[]) => [T, T[]];
|
|
69
|
-
/** Remove the last element and return tuple [el, rest]. */
|
|
70
|
-
declare const last: <T>(arr: T[]) => [T, T[]];
|
|
71
|
-
/** Check if array is empty. */
|
|
72
|
-
declare const isEmpty: <T>(arr: T[]) => boolean;
|
|
73
|
-
/** Check if array is empty. */
|
|
74
|
-
declare const isNotEmpty: <T>(arr: T[]) => boolean;
|
|
75
|
-
/** Pop the element off the end of array. */
|
|
76
|
-
declare const pop: <T>(arr: T[]) => T[];
|
|
77
|
-
/** Add elements to the beginning of array. */
|
|
78
|
-
declare const prepend: <T>(arr: T[], ...elements: T[]) => T[];
|
|
79
|
-
/** Take first n elements of array. */
|
|
80
|
-
declare const take: <T>(amount: number, arr: T[]) => T[];
|
|
81
|
-
/** Create a new array in reverse order. */
|
|
82
|
-
declare const reverse: <T>(arr: T[]) => T[];
|
|
83
|
-
/** Alias for first element removal. */
|
|
84
|
-
declare const shift: <T>(arr: T[]) => [T, T[]];
|
|
39
|
+
type DotPath<T> = T extends object ? { [K in keyof T & (string | number)]: T[K] extends object ? `${K}` | `${K}.${DotPath<T[K]>}` : `${K}` }[keyof T & (string | number)] : never;
|
|
40
|
+
//#endregion
|
|
41
|
+
//#region src/Contracts/TypeCast.d.ts
|
|
42
|
+
type Arrayable = {
|
|
43
|
+
[key: string]: any;
|
|
44
|
+
toArray(): any[];
|
|
45
|
+
};
|
|
46
|
+
type Jsonable = {
|
|
47
|
+
[key: string]: any;
|
|
48
|
+
toJSON(): any;
|
|
49
|
+
};
|
|
50
|
+
type JsonSerializable = {
|
|
51
|
+
[key: string]: any;
|
|
52
|
+
jsonSerialize(): any;
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
//#region src/Exceptions/InvalidArgumentException.d.ts
|
|
85
56
|
/**
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* @param size - Number of elements in the range
|
|
89
|
-
* @param startAt - Starting number (default: 0)
|
|
90
|
-
* @returns An array of numbers from startAt to startAt + size - 1
|
|
57
|
+
* Custom error for invalid type coercion
|
|
91
58
|
*/
|
|
92
|
-
declare
|
|
93
|
-
|
|
94
|
-
|
|
59
|
+
declare class InvalidArgumentException extends Error {
|
|
60
|
+
constructor(message: string);
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/Exceptions/RuntimeException.d.ts
|
|
95
64
|
/**
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* @param {Array} value
|
|
99
|
-
* @return array
|
|
65
|
+
* Custom error for invalid type coercion
|
|
100
66
|
*/
|
|
101
|
-
declare
|
|
67
|
+
declare class RuntimeException extends Error {
|
|
68
|
+
constructor(message: string);
|
|
69
|
+
}
|
|
102
70
|
declare namespace Crypto_d_exports {
|
|
103
71
|
export { base64Decode, base64Encode, caesarCipher, checksum, hash, hmac, random, randomColor, randomPassword, randomSecure, secureToken, uuid, verifyChecksum, xor };
|
|
104
72
|
}
|
|
@@ -269,7 +237,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
|
|
|
269
237
|
*/
|
|
270
238
|
declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
|
|
271
239
|
declare namespace Obj_d_exports {
|
|
272
|
-
export { dot, extractProperties, getValue, modObj, safeDot, setNested, slugifyKeys };
|
|
240
|
+
export { Obj, data_fill, data_forget, data_get, data_set, dot, extractProperties, getValue, modObj, safeDot, setNested, slugifyKeys, toCssClasses, toCssStyles, undot };
|
|
273
241
|
}
|
|
274
242
|
/**
|
|
275
243
|
* Flattens a nested object into a single-level object
|
|
@@ -349,6 +317,489 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
|
|
|
349
317
|
* @returns A new object with slugified keys
|
|
350
318
|
*/
|
|
351
319
|
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
|
|
320
|
+
/**
|
|
321
|
+
* toCssClasses
|
|
322
|
+
*
|
|
323
|
+
* Convert array/object/string input into a CSS class string.
|
|
324
|
+
* - Arrays: included if truthy
|
|
325
|
+
* - Objects: keys included if value is truthy
|
|
326
|
+
* - Strings: included as-is
|
|
327
|
+
*/
|
|
328
|
+
declare function toCssClasses<T extends string | Record<string, boolean> | Array<string | false | null | undefined>>(input: T): string;
|
|
329
|
+
/**
|
|
330
|
+
* toCssStyles
|
|
331
|
+
*
|
|
332
|
+
* Convert object input into CSS style string.
|
|
333
|
+
* - Only includes truthy values (ignores null/undefined/false)
|
|
334
|
+
*/
|
|
335
|
+
declare function toCssStyles<T extends Record<string, string | number | boolean | null | undefined>>(styles: T): string;
|
|
336
|
+
/**
|
|
337
|
+
* undot
|
|
338
|
+
*
|
|
339
|
+
* Convert a dot-notated object back into nested structure.
|
|
340
|
+
*
|
|
341
|
+
* Example:
|
|
342
|
+
* undot({ 'a.b': 1, 'c.0': 2 }) -> { a: { b: 1 }, c: [2] }
|
|
343
|
+
*/
|
|
344
|
+
declare function undot(obj: Record<string, any>): Record<string, any>;
|
|
345
|
+
/**
|
|
346
|
+
* data_get
|
|
347
|
+
*
|
|
348
|
+
* Get a value from an object using dot notation.
|
|
349
|
+
*/
|
|
350
|
+
declare function data_get<T extends object, P extends DotPath<T> | DotPath<T>[], D = undefined>(obj: T, path: P, defaultValue?: D): T | any;
|
|
351
|
+
/**
|
|
352
|
+
* data_set
|
|
353
|
+
*
|
|
354
|
+
* Set a value in an object using dot notation. Mutates the object.
|
|
355
|
+
*/
|
|
356
|
+
declare function data_set<T extends Record<string, any>, P extends string | string[], V>(obj: T, path: P, value: V): asserts obj is T & Record<P extends string ? P : P[0], V>;
|
|
357
|
+
/**
|
|
358
|
+
* data_fill
|
|
359
|
+
*
|
|
360
|
+
* Like data_set, but only sets the value if the key does NOT exist.
|
|
361
|
+
*/
|
|
362
|
+
declare function data_fill(obj: Record<string, any>, path: string | string[], value: any): void;
|
|
363
|
+
/**
|
|
364
|
+
* data_forget
|
|
365
|
+
*
|
|
366
|
+
* Remove a key from an object using dot notation.
|
|
367
|
+
*/
|
|
368
|
+
declare function data_forget(obj: Record<string, any>, path: string | string[]): void;
|
|
369
|
+
declare class Obj {
|
|
370
|
+
/**
|
|
371
|
+
* Check if the value is a non-null object (associative/accessible).
|
|
372
|
+
*/
|
|
373
|
+
static accessible(value: unknown): value is Record<string, any>;
|
|
374
|
+
/**
|
|
375
|
+
* Add a key-value pair to an object only if the key does not already exist.
|
|
376
|
+
*
|
|
377
|
+
* Returns a new object (does not mutate original).
|
|
378
|
+
*/
|
|
379
|
+
static add<T extends Record<string, any>, K extends string, V>(obj: T, key: K, value: V): T & Record<K, V>;
|
|
380
|
+
/**
|
|
381
|
+
* Split object into [keys, values]
|
|
382
|
+
*/
|
|
383
|
+
static divide<T extends Record<string, any>>(obj: T): [string[], any[]];
|
|
384
|
+
/**
|
|
385
|
+
* Check if a key exists in the object.
|
|
386
|
+
*/
|
|
387
|
+
static exists<T extends Record<string, any>>(obj: T, key: string | number): boolean;
|
|
388
|
+
/**
|
|
389
|
+
* Get a value from an object using dot notation.
|
|
390
|
+
*
|
|
391
|
+
* Example:
|
|
392
|
+
* Obj.get({a:{b:1}}, 'a.b') -> 1
|
|
393
|
+
*/
|
|
394
|
+
static get<T extends object, P extends DotPath<T>, D = undefined>(obj: T, path: P, defaultValue?: D): any;
|
|
395
|
+
/**
|
|
396
|
+
* Check if the object has a given key or keys (dot notation supported).
|
|
397
|
+
*/
|
|
398
|
+
static has<T extends object, P extends DotPath<T>>(obj: T, keys: P | P[]): boolean;
|
|
399
|
+
/**
|
|
400
|
+
* Check if an object is associative (has at least one non-numeric key).
|
|
401
|
+
*/
|
|
402
|
+
static isAssoc(obj: unknown): obj is Record<string, any>;
|
|
403
|
+
/**
|
|
404
|
+
* Add a prefix to all keys of the object.
|
|
405
|
+
*/
|
|
406
|
+
static prependKeysWith<T extends Record<string, any>>(obj: T, prefix: string): Record<string, any>;
|
|
407
|
+
/**
|
|
408
|
+
* Convert an object into a URL query string.
|
|
409
|
+
*
|
|
410
|
+
* Nested objects/arrays are flattened using bracket notation.
|
|
411
|
+
*/
|
|
412
|
+
static query(obj: Record<string, any>): string;
|
|
413
|
+
}
|
|
414
|
+
//#endregion
|
|
415
|
+
//#region src/Helpers/Arr.d.ts
|
|
416
|
+
/**
|
|
417
|
+
* Arr — Laravel-like array helpers for JavaScript.
|
|
418
|
+
*
|
|
419
|
+
* - Methods aim for clear, predictable JS behavior.
|
|
420
|
+
* - Inputs are validated where useful; functions try not to mutate arguments.
|
|
421
|
+
*/
|
|
422
|
+
declare class Arr {
|
|
423
|
+
/**
|
|
424
|
+
* Helper: is a value an object (but not null).
|
|
425
|
+
*/
|
|
426
|
+
static _isObject(value: any): boolean;
|
|
427
|
+
/**
|
|
428
|
+
* Helper: deep clone for safety (simple).
|
|
429
|
+
* Uses JSON methods — good for typical data shapes (no functions, Dates, Maps).
|
|
430
|
+
*/
|
|
431
|
+
static _clone<A = any>(value: A): A;
|
|
432
|
+
/**
|
|
433
|
+
* Retrieve a value using dot notation
|
|
434
|
+
* Throws if value is not an array
|
|
435
|
+
*/
|
|
436
|
+
static array(obj: any, path: string, defaultValue?: number): any[];
|
|
437
|
+
/**
|
|
438
|
+
* Retrieve a value using dot notation
|
|
439
|
+
* Throws if value is not a boolean
|
|
440
|
+
*/
|
|
441
|
+
static boolean(obj: any, path: string, defaultValue?: boolean): boolean;
|
|
442
|
+
/**
|
|
443
|
+
* Flatten an array of arrays by one level.
|
|
444
|
+
*
|
|
445
|
+
* Example:
|
|
446
|
+
* Arr.collapse([[1,2], [3], 4]) -> [1,2,3,4]
|
|
447
|
+
*/
|
|
448
|
+
static collapse<X>(array: X[][] | X[]): X[];
|
|
449
|
+
/**
|
|
450
|
+
* Cartesian product of arrays.
|
|
451
|
+
*
|
|
452
|
+
* Example:
|
|
453
|
+
* Arr.crossJoin([1,2], ['a','b']) -> [[1,'a'], [1,'b'], [2,'a'], [2,'b']]
|
|
454
|
+
*
|
|
455
|
+
* Accepts any number of array arguments (or single array-of-arrays).
|
|
456
|
+
*/
|
|
457
|
+
static crossJoin<A>(...arrays: A[][]): A[][];
|
|
458
|
+
/**
|
|
459
|
+
* Split an array (or object) into two arrays: [keys, values].
|
|
460
|
+
*
|
|
461
|
+
* For arrays, keys are numeric indices. For objects, keys are property names.
|
|
462
|
+
*
|
|
463
|
+
* Example:
|
|
464
|
+
* Arr.divide(['a','b']) -> [[0,1], ['a','b']]
|
|
465
|
+
* Arr.divide({x:1,y:2}) -> [['x','y'], [1,2]]
|
|
466
|
+
*/
|
|
467
|
+
static divide<A>(input: A[] | Record<string, A>): (A[] | number[])[] | (A[] | string[])[];
|
|
468
|
+
/**
|
|
469
|
+
* Flatten a nested array/object structure into a single-level object
|
|
470
|
+
* with dot-notated keys.
|
|
471
|
+
*
|
|
472
|
+
* Example:
|
|
473
|
+
* Arr.dot({ a: { b: 1 }, c: [2,3] }) -> { 'a.b': 1, 'c.0': 2, 'c.1': 3 }
|
|
474
|
+
*
|
|
475
|
+
* Works for arrays and plain objects.
|
|
476
|
+
*/
|
|
477
|
+
static dot<A>(input: A[] | Record<string, A>, prefix?: string): Record<string, A>;
|
|
478
|
+
/**
|
|
479
|
+
* Checks if all elements satisfy the predicate
|
|
480
|
+
*/
|
|
481
|
+
static every<T>(array: T[], predicate: (item: T) => boolean): boolean;
|
|
482
|
+
/**
|
|
483
|
+
* Remove items by keys/indices from an array or properties from an object.
|
|
484
|
+
*
|
|
485
|
+
* For arrays: keys are numeric indices (single number or array of numbers).
|
|
486
|
+
*
|
|
487
|
+
* Returns a shallow-copied result (does not mutate input).
|
|
488
|
+
*
|
|
489
|
+
* Example:
|
|
490
|
+
* Arr.except([10,20,30], [1]) -> [10,30]
|
|
491
|
+
*/
|
|
492
|
+
static except<A extends any[] | Record<string, any>, X>(input: A, keys: X[]): A;
|
|
493
|
+
/**
|
|
494
|
+
* Return the first element of an array that satisfies the predicate,
|
|
495
|
+
* or the first element if no predicate is provided, otherwise the defaultValue.
|
|
496
|
+
*
|
|
497
|
+
* Predicate can be true (boolean), a function or a value to match (strict equality).
|
|
498
|
+
*
|
|
499
|
+
* When predicate is true (boolean), the first element will be removed and a tuple will be returned [el, rest].
|
|
500
|
+
*
|
|
501
|
+
* @param array
|
|
502
|
+
* @param predicate
|
|
503
|
+
* @param defaultValue
|
|
504
|
+
*
|
|
505
|
+
* @returns
|
|
506
|
+
*/
|
|
507
|
+
static first<A, P extends (((arg: A) => true) | true)>(array: A[], predicate?: P | undefined, defaultValue?: A | undefined): P extends true ? [A, A[]] : A | undefined;
|
|
508
|
+
/**
|
|
509
|
+
* Recursively flatten an array up to `depth` levels (default: Infinity).
|
|
510
|
+
*
|
|
511
|
+
* Example:
|
|
512
|
+
* Arr.flatten([1, [2, [3]]], 1) -> [1,2,[3]]
|
|
513
|
+
*/
|
|
514
|
+
static flatten<A>(array: A[], depth?: number): A[];
|
|
515
|
+
/**
|
|
516
|
+
* Retrieve a value from an array/object using dot notation
|
|
517
|
+
* Throws if value is not a float
|
|
518
|
+
*/
|
|
519
|
+
static float(obj: any, path: string, defaultValue?: number): number;
|
|
520
|
+
/**
|
|
521
|
+
* Remove element(s) by index or dot-notated path from an array/object.
|
|
522
|
+
*
|
|
523
|
+
* For arrays: accepts numeric index or array of indices. Returns a new array.
|
|
524
|
+
*
|
|
525
|
+
* For objects: supports dot notation to remove nested keys.
|
|
526
|
+
*
|
|
527
|
+
* Example:
|
|
528
|
+
* Arr.forget([1,2,3], 1) -> [1,3]
|
|
529
|
+
* Arr.forget({a:{b:1}}, 'a.b') -> { a: {} }
|
|
530
|
+
*/
|
|
531
|
+
static forget<A extends any[] | Record<string, any>>(input: A, keys: any): A;
|
|
532
|
+
/**
|
|
533
|
+
* Converts various input types into a plain array
|
|
534
|
+
* Supports Arrays, Objects, Iterables, Map, WeakMap, and custom toArray/toJSON/jsonSerialize methods
|
|
535
|
+
*/
|
|
536
|
+
static from<T>(value: T | Iterable<T> | Arrayable | Jsonable | JsonSerializable | null | undefined): any[];
|
|
537
|
+
/**
|
|
538
|
+
* Checks if an object has all the specified keys
|
|
539
|
+
*/
|
|
540
|
+
static hasAll<T extends object>(obj: T, keys: (keyof T)[]): boolean;
|
|
541
|
+
/**
|
|
542
|
+
* For arrays: check if the array contains any of the provided values.
|
|
543
|
+
*
|
|
544
|
+
* values can be single value or array of values.
|
|
545
|
+
*
|
|
546
|
+
* Example:
|
|
547
|
+
* Arr.hasAny([1,2,3], [4,2]) -> true
|
|
548
|
+
*/
|
|
549
|
+
static hasAny<A>(array: A[], values: A[] | A): boolean;
|
|
550
|
+
/**
|
|
551
|
+
* Retrieve a value using dot notation
|
|
552
|
+
* Throws if value is not an integer
|
|
553
|
+
*/
|
|
554
|
+
static integer(obj: any, path: string, defaultValue?: number): number;
|
|
555
|
+
/**
|
|
556
|
+
* Determine if the input is a "list-like" array: an Array with
|
|
557
|
+
* contiguous numeric indices starting at 0 (no gaps).
|
|
558
|
+
*
|
|
559
|
+
* Example:
|
|
560
|
+
* Arr.isList([1,2,3]) -> true
|
|
561
|
+
* const a = []; a[2] = 5; Arr.isList(a) -> false
|
|
562
|
+
*/
|
|
563
|
+
static isList<A>(value: A[]): boolean;
|
|
564
|
+
/**
|
|
565
|
+
* Join array elements into a string using the given separator.
|
|
566
|
+
*
|
|
567
|
+
* Example:
|
|
568
|
+
* Arr.join([1,2,3], '-') -> '1-2-3'
|
|
569
|
+
*/
|
|
570
|
+
static join(array: any[], separator?: string): string;
|
|
571
|
+
/**
|
|
572
|
+
* Create an object indexed by a key or callback function.
|
|
573
|
+
*
|
|
574
|
+
* Example:
|
|
575
|
+
* Arr.keyBy([{id:1},{id:2}], 'id') -> { '1': {id:1}, '2': {id:2} }
|
|
576
|
+
*/
|
|
577
|
+
static keyBy<T>(array: T[], key: keyof T | ((item: T) => string | number)): Record<string, T>;
|
|
578
|
+
/**
|
|
579
|
+
* Get the last element of an array, optionally matching a predicate,
|
|
580
|
+
* or the last element if no predicate is provided, otherwise the defaultValue.
|
|
581
|
+
*
|
|
582
|
+
* Predicate can be a true (boolean), a function or a value to match (strict equality).
|
|
583
|
+
*
|
|
584
|
+
* When predicate is true (boolean), the last element will be removed and a tuple will be returned [el, rest].
|
|
585
|
+
*
|
|
586
|
+
* @param array
|
|
587
|
+
* @param predicate
|
|
588
|
+
* @param defaultValue
|
|
589
|
+
*
|
|
590
|
+
* @returns
|
|
591
|
+
*/
|
|
592
|
+
static last<T, P extends ((item: T) => boolean) | true>(array: T[], predicate?: P | T, defaultValue?: T): P extends true ? [T, T[]] : T | undefined;
|
|
593
|
+
/**
|
|
594
|
+
* Transform each element in an array using a callback.
|
|
595
|
+
*/
|
|
596
|
+
static map<T, U>(array: T[], callback: (item: T, index: number) => U): U[];
|
|
597
|
+
/**
|
|
598
|
+
* Maps a multi-dimensional array with a spread callback
|
|
599
|
+
*/
|
|
600
|
+
static mapSpread<T extends any[], U>(array: T[], callback: (...items: T) => U): U[];
|
|
601
|
+
/**
|
|
602
|
+
* Map each element to a key-value pair.
|
|
603
|
+
*
|
|
604
|
+
* Example:
|
|
605
|
+
* Arr.mapWithKeys([{id:1, name:'A'}], x => [x.id, x.name])
|
|
606
|
+
* -> { '1': 'A' }
|
|
607
|
+
*/
|
|
608
|
+
static mapWithKeys<T, K extends string | number, V>(array: T[], callback: (item: T, index: number) => [K, V]): Record<string, V>;
|
|
609
|
+
/**
|
|
610
|
+
* Return only elements at the given indices.
|
|
611
|
+
*
|
|
612
|
+
* Example:
|
|
613
|
+
* Arr.only([10,20,30], [0,2]) -> [10,30]
|
|
614
|
+
*/
|
|
615
|
+
static only<T>(array: T[], keys: number | number[]): T[];
|
|
616
|
+
/**
|
|
617
|
+
* Split an array into two arrays based on a predicate
|
|
618
|
+
*/
|
|
619
|
+
static partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]];
|
|
620
|
+
/**
|
|
621
|
+
* Extract a property from each element in an array of objects.
|
|
622
|
+
*
|
|
623
|
+
* Example:
|
|
624
|
+
* Arr.pluck([{name:'A'},{name:'B'}], 'name') -> ['A','B']
|
|
625
|
+
*/
|
|
626
|
+
static pluck<T, K extends keyof T>(array: T[], key: K): T[K][];
|
|
627
|
+
/**
|
|
628
|
+
* Add elements to the beginning of an array and return a new array.
|
|
629
|
+
*
|
|
630
|
+
* @param array
|
|
631
|
+
* @param value
|
|
632
|
+
* @returns
|
|
633
|
+
*/
|
|
634
|
+
static prepend<T>(array: T[], ...value: T[]): T[];
|
|
635
|
+
/**
|
|
636
|
+
* Remove a value from an array by index and return it.
|
|
637
|
+
* Returns a tuple: [newArray, removedValue]
|
|
638
|
+
*/
|
|
639
|
+
static pull<T>(array: T[], key: number): [T[], T | undefined];
|
|
640
|
+
/**
|
|
641
|
+
* Append values to an array (mutable)
|
|
642
|
+
*/
|
|
643
|
+
static push<T>(array: T[], ...values: T[]): T[];
|
|
644
|
+
/**
|
|
645
|
+
* Pick one or more random elements from an array.
|
|
646
|
+
*/
|
|
647
|
+
static random<T>(array: T[], count?: number): T | T[] | undefined;
|
|
648
|
+
/**
|
|
649
|
+
* Returns array elements that do NOT satisfy the predicate
|
|
650
|
+
*/
|
|
651
|
+
static reject<T>(array: T[], predicate: (item: T) => boolean): T[];
|
|
652
|
+
/**
|
|
653
|
+
* Pick keys from an array of objects or an object
|
|
654
|
+
*/
|
|
655
|
+
static select<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
656
|
+
/**
|
|
657
|
+
* Returns the only element that passes a callback, throws if none or multiple
|
|
658
|
+
*/
|
|
659
|
+
static sole<T>(array: T[], predicate: (item: T) => boolean): T;
|
|
660
|
+
/**
|
|
661
|
+
* Checks if at least one element satisfies the predicate
|
|
662
|
+
*/
|
|
663
|
+
static some<T>(array: T[], predicate: (item: T) => boolean): boolean;
|
|
664
|
+
/**
|
|
665
|
+
* Randomly shuffle an array and return a new array.
|
|
666
|
+
*/
|
|
667
|
+
static shuffle<T>(array: T[]): T[];
|
|
668
|
+
/**
|
|
669
|
+
* Sort an array ascending using optional comparator.
|
|
670
|
+
*/
|
|
671
|
+
static sort<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
672
|
+
/**
|
|
673
|
+
* Sort an array descending using optional comparator.
|
|
674
|
+
*/
|
|
675
|
+
static sortDesc<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
676
|
+
/**
|
|
677
|
+
* Recursively sort arrays inside an array.
|
|
678
|
+
*/
|
|
679
|
+
static sortRecursive<T>(array: T[]): T[];
|
|
680
|
+
/**
|
|
681
|
+
* Recursively sort arrays inside an array descending.
|
|
682
|
+
*/
|
|
683
|
+
static sortRecursiveDesc<T>(array: T[]): T[];
|
|
684
|
+
/**
|
|
685
|
+
* Retrieve a value using dot notation
|
|
686
|
+
* Throws if value is not a string
|
|
687
|
+
*/
|
|
688
|
+
static string(obj: any, path: string, defaultValue?: string): string;
|
|
689
|
+
/**
|
|
690
|
+
* Return the first N elements of an array.
|
|
691
|
+
*
|
|
692
|
+
* @param array
|
|
693
|
+
* @param count
|
|
694
|
+
* @returns
|
|
695
|
+
*/
|
|
696
|
+
static take<T>(array: T[], count: number): T[];
|
|
697
|
+
/**
|
|
698
|
+
* Filter an array based on a predicate function or key-value match.
|
|
699
|
+
*/
|
|
700
|
+
static where<T>(array: T[], predicate: ((item: T) => boolean) | Partial<T>): T[];
|
|
701
|
+
/**
|
|
702
|
+
* Filter an array of objects, keeping elements where the given key is not null/undefined.
|
|
703
|
+
*/
|
|
704
|
+
static whereNotNull<T>(array: T[], key: keyof T): T[];
|
|
705
|
+
/**
|
|
706
|
+
* If the given value is not an array and not null, wrap it in one.
|
|
707
|
+
*
|
|
708
|
+
* Non-array values become [value]; null/undefined becomes [].
|
|
709
|
+
*
|
|
710
|
+
* @param value
|
|
711
|
+
* @returns
|
|
712
|
+
*/
|
|
713
|
+
static wrap<T>(value: T | T[] | null | undefined): T[];
|
|
714
|
+
/**
|
|
715
|
+
* Return the first element of an array, undefined if empty.
|
|
716
|
+
*/
|
|
717
|
+
static head<T>(array: T[]): T | undefined;
|
|
718
|
+
/**
|
|
719
|
+
* Splits an array into chunks of a specified size.
|
|
720
|
+
*
|
|
721
|
+
* @template T - Type of elements in the array
|
|
722
|
+
* @param arr - The input array
|
|
723
|
+
* @param size - Size of each chunk (default: 2)
|
|
724
|
+
* @returns An array of chunks (arrays)
|
|
725
|
+
*/
|
|
726
|
+
static chunk: <T>(arr: T[], size?: number) => T[][];
|
|
727
|
+
/**
|
|
728
|
+
* Alternates between two arrays, creating a zipped result.
|
|
729
|
+
*
|
|
730
|
+
* @param a
|
|
731
|
+
* @param b
|
|
732
|
+
* @returns
|
|
733
|
+
*/
|
|
734
|
+
static alternate<T>(a: T[], b: T[]): T[];
|
|
735
|
+
/**
|
|
736
|
+
* Combine arrays and sum their values element by element.
|
|
737
|
+
*
|
|
738
|
+
* @param arr
|
|
739
|
+
* @returns
|
|
740
|
+
*/
|
|
741
|
+
static combine(...arr: number[][]): number[];
|
|
742
|
+
/**
|
|
743
|
+
* Find the value associated with a given key.
|
|
744
|
+
*
|
|
745
|
+
* @param key
|
|
746
|
+
* @param arr
|
|
747
|
+
* @returns
|
|
748
|
+
*/
|
|
749
|
+
static find<T>(key: T, arr: T[]): T | null;
|
|
750
|
+
/**
|
|
751
|
+
* Check if array is empty.
|
|
752
|
+
*
|
|
753
|
+
* @param arr
|
|
754
|
+
* @returns
|
|
755
|
+
*/
|
|
756
|
+
static isEmpty<T>(arr: T[]): boolean;
|
|
757
|
+
/**
|
|
758
|
+
* Check if array is empty.
|
|
759
|
+
*
|
|
760
|
+
* @param arr
|
|
761
|
+
* @returns
|
|
762
|
+
*/
|
|
763
|
+
static isNotEmpty<T>(arr: T[]): boolean;
|
|
764
|
+
/**
|
|
765
|
+
* Pop the element off the end of array.
|
|
766
|
+
*
|
|
767
|
+
* @param arr
|
|
768
|
+
* @returns
|
|
769
|
+
*/
|
|
770
|
+
static pop<T>(arr: T[]): T[];
|
|
771
|
+
/**
|
|
772
|
+
* Create a new array in reverse order.
|
|
773
|
+
*
|
|
774
|
+
* @param arr
|
|
775
|
+
* @returns
|
|
776
|
+
*/
|
|
777
|
+
static reverse<T>(arr: T[]): T[];
|
|
778
|
+
/**
|
|
779
|
+
* Return the first element of an array that satisfies the predicate,
|
|
780
|
+
* or the first element if no predicate is provided, otherwise the defaultValue.
|
|
781
|
+
*
|
|
782
|
+
* Predicate can be true (boolean), a function or a value to match (strict equality).
|
|
783
|
+
*
|
|
784
|
+
* When predicate is true (boolean), the first element will be removed and a tuple will be returned [el, rest].
|
|
785
|
+
*
|
|
786
|
+
* @param array
|
|
787
|
+
* @param predicate
|
|
788
|
+
* @param defaultValue
|
|
789
|
+
*
|
|
790
|
+
* @alias Arr.first()
|
|
791
|
+
* @returns
|
|
792
|
+
*/
|
|
793
|
+
static shift<A, P extends (((arg: A) => true) | true)>(array: A[], predicate?: P | undefined, defaultValue?: A | undefined): P extends true ? [A, A[]] : A | undefined;
|
|
794
|
+
/**
|
|
795
|
+
* Generates an array of sequential numbers.
|
|
796
|
+
*
|
|
797
|
+
* @param size - Number of elements in the range
|
|
798
|
+
* @param startAt - Starting number (default: 0)
|
|
799
|
+
* @returns An array of numbers from startAt to startAt + size - 1
|
|
800
|
+
*/
|
|
801
|
+
static range(size: number, startAt?: number): number[];
|
|
802
|
+
}
|
|
352
803
|
//#endregion
|
|
353
804
|
//#region src/Helpers/Time.d.ts
|
|
354
805
|
declare function format(date: ConfigType, fmt: string): string;
|
|
@@ -2694,17 +3145,17 @@ declare function str(string?: string): Stringable;
|
|
|
2694
3145
|
//#endregion
|
|
2695
3146
|
//#region src/GlobalBootstrap.d.ts
|
|
2696
3147
|
type CollapseStatics<T extends Record<string, any>> = { [K in keyof T]: T[K] };
|
|
2697
|
-
type Omitables = 'start' | 'take' | 'reverse' | 'chunk' | 'find' | 'pop' | 'end' | 'shift' | 'push' | 'at' | 'prototype' | 'concat' | 'join' | 'slice' | 'sort' | 'splice' | 'includes' | 'indexOf' | 'lastIndexOf' | 'findIndex' | 'every' | 'some' | 'forEach' | 'map' | 'filter' | 'reduce' | 'unshift' | 'flat' | 'flatMap' | 'keys' | 'fill' | 'copyWithin' | 'entries' | 'values' | 'reduceRight' | 'length' | 'of' | typeof Symbol.unscopables | typeof Symbol.iterator;
|
|
3148
|
+
type Omitables = 'start' | 'take' | 'reverse' | 'chunk' | 'find' | 'pop' | 'end' | 'shift' | 'push' | 'at' | 'prototype' | 'concat' | 'join' | 'slice' | 'sort' | 'splice' | 'includes' | 'indexOf' | 'lastIndexOf' | 'findIndex' | 'every' | 'some' | 'forEach' | 'map' | 'filter' | 'reduce' | 'unshift' | 'flat' | 'flatMap' | 'keys' | 'fill' | 'copyWithin' | 'entries' | 'values' | 'reduceRight' | 'length' | 'of' | '_isObject' | '_clone' | 'crossJoin' | 'divide' | 'wrap' | 'except' | 'hasAny' | 'isList' | 'keyBy' | 'mapWithKeys' | 'only' | 'pluck' | 'pull' | 'shuffle' | 'sortDesc' | 'sortRecursive' | 'sortRecursiveDesc' | 'where' | 'whereNotNull' | 'head' | 'string' | 'boolean' | 'array' | 'float' | 'from' | 'hasAll' | 'integer' | 'mapSpread' | 'partition' | 'reject' | 'select' | 'sole' | 'alternate' | 'combine' | 'isEmpty' | 'isNotEmpty' | 'range' | typeof Symbol.unscopables | typeof Symbol.iterator;
|
|
2698
3149
|
type TakeTime = Pick<typeof DateTime, 'now' | 'format' | 'fromTimestamp' | 'randomTime' | 'firstDayOfMonth' | 'lastDayOfMonth' | 'parse'>;
|
|
2699
3150
|
type TakeString = Pick<typeof Str, 'after' | 'afterLast' | 'apa' | 'ascii' | 'before' | 'beforeLast' | 'between' | 'betweenFirst' | 'capitalize' | 'plural' | 'singular' | 'title'>;
|
|
2700
3151
|
/**
|
|
2701
3152
|
* Global helpers interface that mirrors Laravel's helpers
|
|
2702
3153
|
* and provides convenient access to all utility functions
|
|
2703
3154
|
*/
|
|
2704
|
-
interface GlobalHelpers extends Omit<CollapseStatics<typeof
|
|
2705
|
-
Arr: typeof
|
|
3155
|
+
interface GlobalHelpers extends Omit<CollapseStatics<typeof Arr>, Omitables | 'random' | 'dot'>, Omit<CollapseStatics<TakeString>, Omitables | 'random' | 'uuid'>, Omit<CollapseStatics<TakeTime>, Omitables>, Omit<CollapseStatics<typeof Obj_d_exports>, Omitables | 'Obj'>, Omit<CollapseStatics<typeof Crypto_d_exports>, Omitables>, Omit<CollapseStatics<typeof Number_d_exports>, Omitables>, Omit<CollapseStatics<typeof DumpDie_d_exports>, Omitables> {
|
|
3156
|
+
Arr: typeof Arr;
|
|
2706
3157
|
Str: typeof Str;
|
|
2707
|
-
Obj: typeof
|
|
3158
|
+
Obj: typeof Obj;
|
|
2708
3159
|
Crypto: typeof Crypto_d_exports;
|
|
2709
3160
|
Number: typeof Number_d_exports;
|
|
2710
3161
|
DumpDie: typeof DumpDie_d_exports;
|
|
@@ -2741,5 +3192,5 @@ declare function loadHelpers(target?: any): void;
|
|
|
2741
3192
|
*/
|
|
2742
3193
|
declare function cleanHelpers(target?: any): void;
|
|
2743
3194
|
//#endregion
|
|
2744
|
-
export {
|
|
3195
|
+
export { Arr, Arrayable, Callback, CamelToSnakeCase, Crypto_d_exports as Crypto, DateTime, DotPath, DumpDie_d_exports as DumpDie, ExcerptOptions, Fallback, Function, GlobalHelpers, HtmlString, HtmlStringType, InvalidArgumentException, JsonSerializable, Jsonable, KeysToSnakeCase, Mode, Number_d_exports as Number, Obj_d_exports as Obj, RuntimeException, SnakeToCamelCase, SnakeToTitleCase, Str, Stringable, TGeneric, Value, XGeneric, abbreviate, base64Decode, base64Encode, caesarCipher, checksum, cleanHelpers, data_fill, data_forget, data_get, data_set, dd, dot, dump, extractProperties, format, getValue, hash, hmac, humanize, loadHelpers, modObj, random, randomColor, randomPassword, randomSecure, safeDot, secureToken, setNested, slugifyKeys, str, toBytes, toCssClasses, toCssStyles, toHumanTime, undot, uuid, verifyChecksum, xor };
|
|
2745
3196
|
//# sourceMappingURL=index.d.ts.map
|