@h3ravel/support 0.14.3 → 0.14.5
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 +42 -31
- package/dist/index.d.ts +84 -58
- package/dist/index.js +41 -19
- package/package.json +5 -5
- package/dist/index.d.cts +0 -3198
package/dist/index.cjs
CHANGED
|
@@ -30,7 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
|
|
31
31
|
//#endregion
|
|
32
32
|
let crypto = require("crypto");
|
|
33
|
-
crypto = __toESM(crypto);
|
|
34
33
|
let process = require("process");
|
|
35
34
|
process = __toESM(process);
|
|
36
35
|
let util = require("util");
|
|
@@ -461,23 +460,6 @@ const toHumanTime = (seconds = 0, worded = false) => {
|
|
|
461
460
|
|
|
462
461
|
//#endregion
|
|
463
462
|
//#region src/Helpers/Obj.ts
|
|
464
|
-
var Obj_exports = /* @__PURE__ */ __export({
|
|
465
|
-
Obj: () => Obj,
|
|
466
|
-
data_fill: () => data_fill,
|
|
467
|
-
data_forget: () => data_forget,
|
|
468
|
-
data_get: () => data_get,
|
|
469
|
-
data_set: () => data_set,
|
|
470
|
-
dot: () => dot,
|
|
471
|
-
extractProperties: () => extractProperties,
|
|
472
|
-
getValue: () => getValue,
|
|
473
|
-
modObj: () => modObj,
|
|
474
|
-
safeDot: () => safeDot,
|
|
475
|
-
setNested: () => setNested,
|
|
476
|
-
slugifyKeys: () => slugifyKeys,
|
|
477
|
-
toCssClasses: () => toCssClasses,
|
|
478
|
-
toCssStyles: () => toCssStyles,
|
|
479
|
-
undot: () => undot
|
|
480
|
-
});
|
|
481
463
|
/**
|
|
482
464
|
* Flattens a nested object into a single-level object
|
|
483
465
|
* with dot-separated keys.
|
|
@@ -737,6 +719,15 @@ function data_forget(obj, path) {
|
|
|
737
719
|
}
|
|
738
720
|
}
|
|
739
721
|
}
|
|
722
|
+
/**
|
|
723
|
+
* Checks if a value is a plain object (not array, function, etc.)
|
|
724
|
+
*
|
|
725
|
+
* @param value
|
|
726
|
+
* @returns
|
|
727
|
+
*/
|
|
728
|
+
function isPlainObject(value) {
|
|
729
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
730
|
+
}
|
|
740
731
|
var Obj = class Obj {
|
|
741
732
|
/**
|
|
742
733
|
* Check if the value is a non-null object (associative/accessible).
|
|
@@ -757,6 +748,27 @@ var Obj = class Obj {
|
|
|
757
748
|
return obj;
|
|
758
749
|
}
|
|
759
750
|
/**
|
|
751
|
+
* Deeply merges two or more objects.
|
|
752
|
+
* - Arrays are replaced (not concatenated)
|
|
753
|
+
* - Objects are merged recursively
|
|
754
|
+
* - Non-object values overwrite previous ones
|
|
755
|
+
*
|
|
756
|
+
* @param objects
|
|
757
|
+
* @returns
|
|
758
|
+
*/
|
|
759
|
+
static deepMerge(...objects) {
|
|
760
|
+
const result = {};
|
|
761
|
+
for (const obj of objects) {
|
|
762
|
+
if (!obj || typeof obj !== "object") continue;
|
|
763
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
764
|
+
const existing = result[key];
|
|
765
|
+
if (isPlainObject(existing) && isPlainObject(value)) result[key] = Obj.deepMerge(existing, value);
|
|
766
|
+
else result[key] = value;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
760
772
|
* Split object into [keys, values]
|
|
761
773
|
*/
|
|
762
774
|
static divide(obj) {
|
|
@@ -1546,6 +1558,15 @@ var DateTime = class DateTime extends TimeClass {
|
|
|
1546
1558
|
return this.startOf(unit);
|
|
1547
1559
|
}
|
|
1548
1560
|
/**
|
|
1561
|
+
* Set the timezone for the instance
|
|
1562
|
+
*
|
|
1563
|
+
* @param timezone
|
|
1564
|
+
* @returns
|
|
1565
|
+
*/
|
|
1566
|
+
setTimezone(timezone$1, keepLocalTime) {
|
|
1567
|
+
return new DateTime(this.tz(timezone$1, keepLocalTime));
|
|
1568
|
+
}
|
|
1569
|
+
/**
|
|
1549
1570
|
* End time of a specific unit.
|
|
1550
1571
|
*
|
|
1551
1572
|
* @returns
|
|
@@ -1600,7 +1621,7 @@ var DateTime = class DateTime extends TimeClass {
|
|
|
1600
1621
|
* @return {Date} object
|
|
1601
1622
|
*/
|
|
1602
1623
|
static fromTimestamp(timestamp) {
|
|
1603
|
-
return
|
|
1624
|
+
return new DateTime(timestamp * 1e3);
|
|
1604
1625
|
}
|
|
1605
1626
|
/**
|
|
1606
1627
|
* Get current time instance.
|
|
@@ -6202,12 +6223,6 @@ Object.defineProperty(exports, 'Crypto', {
|
|
|
6202
6223
|
}
|
|
6203
6224
|
});
|
|
6204
6225
|
exports.DateTime = DateTime;
|
|
6205
|
-
Object.defineProperty(exports, 'DumpDie', {
|
|
6206
|
-
enumerable: true,
|
|
6207
|
-
get: function () {
|
|
6208
|
-
return DumpDie_exports;
|
|
6209
|
-
}
|
|
6210
|
-
});
|
|
6211
6226
|
exports.HtmlString = HtmlString;
|
|
6212
6227
|
exports.InvalidArgumentException = InvalidArgumentException;
|
|
6213
6228
|
exports.Mode = Mode;
|
|
@@ -6217,12 +6232,7 @@ Object.defineProperty(exports, 'Number', {
|
|
|
6217
6232
|
return Number_exports;
|
|
6218
6233
|
}
|
|
6219
6234
|
});
|
|
6220
|
-
|
|
6221
|
-
enumerable: true,
|
|
6222
|
-
get: function () {
|
|
6223
|
-
return Obj_exports;
|
|
6224
|
-
}
|
|
6225
|
-
});
|
|
6235
|
+
exports.Obj = Obj;
|
|
6226
6236
|
exports.RuntimeException = RuntimeException;
|
|
6227
6237
|
exports.Str = Str;
|
|
6228
6238
|
exports.Stringable = Stringable;
|
|
@@ -6245,6 +6255,7 @@ exports.getValue = getValue;
|
|
|
6245
6255
|
exports.hash = hash;
|
|
6246
6256
|
exports.hmac = hmac;
|
|
6247
6257
|
exports.humanize = humanize;
|
|
6258
|
+
exports.isPlainObject = isPlainObject;
|
|
6248
6259
|
exports.loadHelpers = loadHelpers;
|
|
6249
6260
|
exports.modObj = modObj;
|
|
6250
6261
|
exports.random = random;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
-
import
|
|
3
|
-
import dayjs, { ConfigType, Dayjs, OpUnitType } from "dayjs";
|
|
2
|
+
import "node:module";
|
|
4
3
|
import { DotFlatten, DotNestedKeys, DotNestedValue } from "@h3ravel/shared";
|
|
4
|
+
import dayjs, { ConfigType, Dayjs, OpUnitType } from "dayjs";
|
|
5
5
|
|
|
6
|
+
//#region rolldown:runtime
|
|
7
|
+
//#endregion
|
|
6
8
|
//#region src/Contracts/StrContract.d.ts
|
|
7
9
|
/**
|
|
8
10
|
* Converts CamelCased strings to snake_case
|
|
@@ -33,10 +35,10 @@ interface Function {
|
|
|
33
35
|
* Convert CamelCased Object keys to snake_case
|
|
34
36
|
*/
|
|
35
37
|
type KeysToSnakeCase<T$1> = { [K in keyof T$1 as CamelToSnakeCase<string & K>]: T$1[K] };
|
|
36
|
-
type TGeneric<V
|
|
37
|
-
type XGeneric<V
|
|
38
|
+
type TGeneric<V = any, K$1 extends string = string> = Record<K$1, V>;
|
|
39
|
+
type XGeneric<V = TGeneric, T$1 = any> = {
|
|
38
40
|
[key: string]: T$1;
|
|
39
|
-
} & V
|
|
41
|
+
} & V;
|
|
40
42
|
type DotPath<T$1> = T$1 extends object ? { [K in keyof T$1 & (string | number)]: T$1[K] extends object ? `${K}` | `${K}.${DotPath<T$1[K]>}` : `${K}` }[keyof T$1 & (string | number)] : never;
|
|
41
43
|
//#endregion
|
|
42
44
|
//#region src/Contracts/TypeCast.d.ts
|
|
@@ -238,7 +240,7 @@ declare const toBytes: (bytes?: number, decimals?: number, bits?: boolean) => st
|
|
|
238
240
|
*/
|
|
239
241
|
declare const toHumanTime: (seconds?: number, worded?: boolean) => string;
|
|
240
242
|
declare namespace Obj_d_exports {
|
|
241
|
-
export { Obj, data_fill, data_forget, data_get, data_set, dot, extractProperties, getValue, modObj, safeDot, setNested, slugifyKeys, toCssClasses, toCssStyles, undot };
|
|
243
|
+
export { Obj, data_fill, data_forget, data_get, data_set, dot, extractProperties, getValue, isPlainObject, modObj, safeDot, setNested, slugifyKeys, toCssClasses, toCssStyles, undot };
|
|
242
244
|
}
|
|
243
245
|
/**
|
|
244
246
|
* Flattens a nested object into a single-level object
|
|
@@ -261,7 +263,7 @@ declare namespace Obj_d_exports {
|
|
|
261
263
|
* @param obj - The nested object to flatten
|
|
262
264
|
* @returns A flattened object with dotted keys and inferred types
|
|
263
265
|
*/
|
|
264
|
-
declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
|
|
266
|
+
declare const dot: <T$1 extends Record<string, any>>(obj: T$1) => DotFlatten<T$1>;
|
|
265
267
|
/**
|
|
266
268
|
* Extracts a subset of properties from an object.
|
|
267
269
|
*
|
|
@@ -271,7 +273,7 @@ declare const dot: <T extends Record<string, any>>(obj: T) => DotFlatten<T>;
|
|
|
271
273
|
* @param keys - Array of keys to extract
|
|
272
274
|
* @returns A new object with only the specified keys
|
|
273
275
|
*/
|
|
274
|
-
declare const extractProperties: <T extends object, K extends keyof T>(obj: T, keys?: readonly K[]) => Pick<T, K>;
|
|
276
|
+
declare const extractProperties: <T$1 extends object, K$1 extends keyof T$1>(obj: T$1, keys?: readonly K$1[]) => Pick<T$1, K$1>;
|
|
275
277
|
/**
|
|
276
278
|
* Safely retrieves a value from an object by key or nested keys.
|
|
277
279
|
*
|
|
@@ -280,7 +282,7 @@ declare const extractProperties: <T extends object, K extends keyof T>(obj: T, k
|
|
|
280
282
|
* @param item - The source object
|
|
281
283
|
* @returns The found value as a string or the key itself if not found
|
|
282
284
|
*/
|
|
283
|
-
declare const getValue: <T extends Record<string, any>>(key: string | [keyof T, keyof T[string]], item: T) => string;
|
|
285
|
+
declare const getValue: <T$1 extends Record<string, any>>(key: string | [keyof T$1, keyof T$1[string]], item: T$1) => string;
|
|
284
286
|
/**
|
|
285
287
|
* Maps over an object's entries and returns a new object
|
|
286
288
|
* with transformed keys and/or values.
|
|
@@ -291,7 +293,7 @@ declare const getValue: <T extends Record<string, any>>(key: string | [keyof T,
|
|
|
291
293
|
* @param callback - Function that receives [key, value] and returns [newKey, newValue]
|
|
292
294
|
* @returns A new object with transformed entries
|
|
293
295
|
*/
|
|
294
|
-
declare const modObj: <T extends object, R>(obj: T, callback: (_entry: [keyof T & string, T[keyof T]]) => [string, R]) => Record<string, R>;
|
|
296
|
+
declare const modObj: <T$1 extends object, R>(obj: T$1, callback: (_entry: [keyof T$1 & string, T$1[keyof T$1]]) => [string, R]) => Record<string, R>;
|
|
295
297
|
declare function safeDot<T$1 extends Record<string, any>>(_data: T$1): T$1;
|
|
296
298
|
declare function safeDot<T$1 extends Record<string, any>, K$1 extends DotNestedKeys<T$1>>(_data: T$1, _key?: K$1): DotNestedValue<T$1, K$1>;
|
|
297
299
|
/**
|
|
@@ -317,7 +319,7 @@ declare const setNested: (obj: Record<string, any>, key: string, value: any) =>
|
|
|
317
319
|
* @param separator - Separator for slugified keys (default: "_")
|
|
318
320
|
* @returns A new object with slugified keys
|
|
319
321
|
*/
|
|
320
|
-
declare const slugifyKeys: <T extends object>(obj: T, only?: string[], separator?: string) => KeysToSnakeCase<T>;
|
|
322
|
+
declare const slugifyKeys: <T$1 extends object>(obj: T$1, only?: string[], separator?: string) => KeysToSnakeCase<T$1>;
|
|
321
323
|
/**
|
|
322
324
|
* toCssClasses
|
|
323
325
|
*
|
|
@@ -348,13 +350,13 @@ declare function undot(obj: Record<string, any>): Record<string, any>;
|
|
|
348
350
|
*
|
|
349
351
|
* Get a value from an object using dot notation.
|
|
350
352
|
*/
|
|
351
|
-
declare function data_get<T$1 extends object, P
|
|
353
|
+
declare function data_get<T$1 extends object, P extends DotPath<T$1> | DotPath<T$1>[], D = undefined>(obj: T$1, path: P, defaultValue?: D): T$1 | any;
|
|
352
354
|
/**
|
|
353
355
|
* data_set
|
|
354
356
|
*
|
|
355
357
|
* Set a value in an object using dot notation. Mutates the object.
|
|
356
358
|
*/
|
|
357
|
-
declare function data_set<T$1 extends Record<string, any>, P
|
|
359
|
+
declare function data_set<T$1 extends Record<string, any>, P extends string | string[], V>(obj: T$1, path: P, value: V): asserts obj is T$1 & Record<P extends string ? P : P[0], V>;
|
|
358
360
|
/**
|
|
359
361
|
* data_fill
|
|
360
362
|
*
|
|
@@ -367,6 +369,13 @@ declare function data_fill(obj: Record<string, any>, path: string | string[], va
|
|
|
367
369
|
* Remove a key from an object using dot notation.
|
|
368
370
|
*/
|
|
369
371
|
declare function data_forget(obj: Record<string, any>, path: string | string[]): void;
|
|
372
|
+
/**
|
|
373
|
+
* Checks if a value is a plain object (not array, function, etc.)
|
|
374
|
+
*
|
|
375
|
+
* @param value
|
|
376
|
+
* @returns
|
|
377
|
+
*/
|
|
378
|
+
declare function isPlainObject(value: any): value is Record<string, any>;
|
|
370
379
|
declare class Obj {
|
|
371
380
|
/**
|
|
372
381
|
* Check if the value is a non-null object (associative/accessible).
|
|
@@ -377,26 +386,36 @@ declare class Obj {
|
|
|
377
386
|
*
|
|
378
387
|
* Returns a new object (does not mutate original).
|
|
379
388
|
*/
|
|
380
|
-
static add<T extends Record<string, any>, K extends string, V>(obj: T, key: K, value: V): T & Record<K, V>;
|
|
389
|
+
static add<T$1 extends Record<string, any>, K$1 extends string, V>(obj: T$1, key: K$1, value: V): T$1 & Record<K$1, V>;
|
|
390
|
+
/**
|
|
391
|
+
* Deeply merges two or more objects.
|
|
392
|
+
* - Arrays are replaced (not concatenated)
|
|
393
|
+
* - Objects are merged recursively
|
|
394
|
+
* - Non-object values overwrite previous ones
|
|
395
|
+
*
|
|
396
|
+
* @param objects
|
|
397
|
+
* @returns
|
|
398
|
+
*/
|
|
399
|
+
static deepMerge<T$1 extends Record<string, any>>(...objects: (Partial<T$1> | undefined | null)[]): T$1;
|
|
381
400
|
/**
|
|
382
401
|
* Split object into [keys, values]
|
|
383
402
|
*/
|
|
384
|
-
static divide<T extends Record<string, any>>(obj: T): [string[], any[]];
|
|
403
|
+
static divide<T$1 extends Record<string, any>>(obj: T$1): [string[], any[]];
|
|
385
404
|
/**
|
|
386
405
|
* Check if a key exists in the object.
|
|
387
406
|
*/
|
|
388
|
-
static exists<T extends Record<string, any>>(obj: T, key: string | number): boolean;
|
|
407
|
+
static exists<T$1 extends Record<string, any>>(obj: T$1, key: string | number): boolean;
|
|
389
408
|
/**
|
|
390
409
|
* Get a value from an object using dot notation.
|
|
391
410
|
*
|
|
392
411
|
* Example:
|
|
393
412
|
* Obj.get({a:{b:1}}, 'a.b') -> 1
|
|
394
413
|
*/
|
|
395
|
-
static get<T extends object, P extends DotPath<T>, D = undefined>(obj: T, path: P, defaultValue?: D): any;
|
|
414
|
+
static get<T$1 extends object, P extends DotPath<T$1>, D = undefined>(obj: T$1, path: P, defaultValue?: D): any;
|
|
396
415
|
/**
|
|
397
416
|
* Check if the object has a given key or keys (dot notation supported).
|
|
398
417
|
*/
|
|
399
|
-
static has<T extends object, P extends DotPath<T>>(obj: T, keys: P | P[]): boolean;
|
|
418
|
+
static has<T$1 extends object, P extends DotPath<T$1>>(obj: T$1, keys: P | P[]): boolean;
|
|
400
419
|
/**
|
|
401
420
|
* Check if an object is associative (has at least one non-numeric key).
|
|
402
421
|
*/
|
|
@@ -404,7 +423,7 @@ declare class Obj {
|
|
|
404
423
|
/**
|
|
405
424
|
* Add a prefix to all keys of the object.
|
|
406
425
|
*/
|
|
407
|
-
static prependKeysWith<T extends Record<string, any>>(obj: T, prefix: string): Record<string, any>;
|
|
426
|
+
static prependKeysWith<T$1 extends Record<string, any>>(obj: T$1, prefix: string): Record<string, any>;
|
|
408
427
|
/**
|
|
409
428
|
* Convert an object into a URL query string.
|
|
410
429
|
*
|
|
@@ -465,7 +484,7 @@ declare class Arr {
|
|
|
465
484
|
* Arr.divide(['a','b']) -> [[0,1], ['a','b']]
|
|
466
485
|
* Arr.divide({x:1,y:2}) -> [['x','y'], [1,2]]
|
|
467
486
|
*/
|
|
468
|
-
static divide<A>(input: A[] | Record<string, A>): (A[] | number[])[] | (
|
|
487
|
+
static divide<A>(input: A[] | Record<string, A>): (A[] | number[])[] | (A[] | string[])[];
|
|
469
488
|
/**
|
|
470
489
|
* Flatten a nested array/object structure into a single-level object
|
|
471
490
|
* with dot-notated keys.
|
|
@@ -479,7 +498,7 @@ declare class Arr {
|
|
|
479
498
|
/**
|
|
480
499
|
* Checks if all elements satisfy the predicate
|
|
481
500
|
*/
|
|
482
|
-
static every<T>(array: T[], predicate: (item: T) => boolean): boolean;
|
|
501
|
+
static every<T$1>(array: T$1[], predicate: (item: T$1) => boolean): boolean;
|
|
483
502
|
/**
|
|
484
503
|
* Remove items by keys/indices from an array or properties from an object.
|
|
485
504
|
*
|
|
@@ -534,11 +553,11 @@ declare class Arr {
|
|
|
534
553
|
* Converts various input types into a plain array
|
|
535
554
|
* Supports Arrays, Objects, Iterables, Map, WeakMap, and custom toArray/toJSON/jsonSerialize methods
|
|
536
555
|
*/
|
|
537
|
-
static from<T>(value: T | Iterable<T> | Arrayable | Jsonable | JsonSerializable | null | undefined): any[];
|
|
556
|
+
static from<T$1>(value: T$1 | Iterable<T$1> | Arrayable | Jsonable | JsonSerializable | null | undefined): any[];
|
|
538
557
|
/**
|
|
539
558
|
* Checks if an object has all the specified keys
|
|
540
559
|
*/
|
|
541
|
-
static hasAll<T extends object>(obj: T, keys: (keyof T)[]): boolean;
|
|
560
|
+
static hasAll<T$1 extends object>(obj: T$1, keys: (keyof T$1)[]): boolean;
|
|
542
561
|
/**
|
|
543
562
|
* For arrays: check if the array contains any of the provided values.
|
|
544
563
|
*
|
|
@@ -575,7 +594,7 @@ declare class Arr {
|
|
|
575
594
|
* Example:
|
|
576
595
|
* Arr.keyBy([{id:1},{id:2}], 'id') -> { '1': {id:1}, '2': {id:2} }
|
|
577
596
|
*/
|
|
578
|
-
static keyBy<T>(array: T[], key: keyof T | ((item: T) => string | number)): Record<string, T>;
|
|
597
|
+
static keyBy<T$1>(array: T$1[], key: keyof T$1 | ((item: T$1) => string | number)): Record<string, T$1>;
|
|
579
598
|
/**
|
|
580
599
|
* Get the last element of an array, optionally matching a predicate,
|
|
581
600
|
* or the last element if no predicate is provided, otherwise the defaultValue.
|
|
@@ -590,15 +609,15 @@ declare class Arr {
|
|
|
590
609
|
*
|
|
591
610
|
* @returns
|
|
592
611
|
*/
|
|
593
|
-
static last<T, P extends ((item: T) => boolean) | true>(array: T[], predicate?: P | T, defaultValue?: T): P extends true ? [T, T[]] : T | undefined;
|
|
612
|
+
static last<T$1, P extends ((item: T$1) => boolean) | true>(array: T$1[], predicate?: P | T$1, defaultValue?: T$1): P extends true ? [T$1, T$1[]] : T$1 | undefined;
|
|
594
613
|
/**
|
|
595
614
|
* Transform each element in an array using a callback.
|
|
596
615
|
*/
|
|
597
|
-
static map<T, U>(array: T[], callback: (item: T, index: number) => U): U[];
|
|
616
|
+
static map<T$1, U$1>(array: T$1[], callback: (item: T$1, index: number) => U$1): U$1[];
|
|
598
617
|
/**
|
|
599
618
|
* Maps a multi-dimensional array with a spread callback
|
|
600
619
|
*/
|
|
601
|
-
static mapSpread<T extends any[], U>(array: T[], callback: (...items: T) => U): U[];
|
|
620
|
+
static mapSpread<T$1 extends any[], U$1>(array: T$1[], callback: (...items: T$1) => U$1): U$1[];
|
|
602
621
|
/**
|
|
603
622
|
* Map each element to a key-value pair.
|
|
604
623
|
*
|
|
@@ -606,25 +625,25 @@ declare class Arr {
|
|
|
606
625
|
* Arr.mapWithKeys([{id:1, name:'A'}], x => [x.id, x.name])
|
|
607
626
|
* -> { '1': 'A' }
|
|
608
627
|
*/
|
|
609
|
-
static mapWithKeys<T, K extends string | number, V>(array: T[], callback: (item: T, index: number) => [K, V]): Record<string, V>;
|
|
628
|
+
static mapWithKeys<T$1, K$1 extends string | number, V>(array: T$1[], callback: (item: T$1, index: number) => [K$1, V]): Record<string, V>;
|
|
610
629
|
/**
|
|
611
630
|
* Return only elements at the given indices.
|
|
612
631
|
*
|
|
613
632
|
* Example:
|
|
614
633
|
* Arr.only([10,20,30], [0,2]) -> [10,30]
|
|
615
634
|
*/
|
|
616
|
-
static only<T>(array: T[], keys: number | number[]): T[];
|
|
635
|
+
static only<T$1>(array: T$1[], keys: number | number[]): T$1[];
|
|
617
636
|
/**
|
|
618
637
|
* Split an array into two arrays based on a predicate
|
|
619
638
|
*/
|
|
620
|
-
static partition<T>(array: T[], predicate: (item: T) => boolean): [T[], T[]];
|
|
639
|
+
static partition<T$1>(array: T$1[], predicate: (item: T$1) => boolean): [T$1[], T$1[]];
|
|
621
640
|
/**
|
|
622
641
|
* Extract a property from each element in an array of objects.
|
|
623
642
|
*
|
|
624
643
|
* Example:
|
|
625
644
|
* Arr.pluck([{name:'A'},{name:'B'}], 'name') -> ['A','B']
|
|
626
645
|
*/
|
|
627
|
-
static pluck<T, K extends keyof T>(array: T[], key: K): T[K][];
|
|
646
|
+
static pluck<T$1, K$1 extends keyof T$1>(array: T$1[], key: K$1): T$1[K$1][];
|
|
628
647
|
/**
|
|
629
648
|
* Add elements to the beginning of an array and return a new array.
|
|
630
649
|
*
|
|
@@ -632,56 +651,56 @@ declare class Arr {
|
|
|
632
651
|
* @param value
|
|
633
652
|
* @returns
|
|
634
653
|
*/
|
|
635
|
-
static prepend<T>(array: T[], ...value: T[]): T[];
|
|
654
|
+
static prepend<T$1>(array: T$1[], ...value: T$1[]): T$1[];
|
|
636
655
|
/**
|
|
637
656
|
* Remove a value from an array by index and return it.
|
|
638
657
|
* Returns a tuple: [newArray, removedValue]
|
|
639
658
|
*/
|
|
640
|
-
static pull<T>(array: T[], key: number): [T[], T | undefined];
|
|
659
|
+
static pull<T$1>(array: T$1[], key: number): [T$1[], T$1 | undefined];
|
|
641
660
|
/**
|
|
642
661
|
* Append values to an array (mutable)
|
|
643
662
|
*/
|
|
644
|
-
static push<T>(array: T[], ...values: T[]): T[];
|
|
663
|
+
static push<T$1>(array: T$1[], ...values: T$1[]): T$1[];
|
|
645
664
|
/**
|
|
646
665
|
* Pick one or more random elements from an array.
|
|
647
666
|
*/
|
|
648
|
-
static random<T>(array: T[], count?: number): T | T[] | undefined;
|
|
667
|
+
static random<T$1>(array: T$1[], count?: number): T$1 | T$1[] | undefined;
|
|
649
668
|
/**
|
|
650
669
|
* Returns array elements that do NOT satisfy the predicate
|
|
651
670
|
*/
|
|
652
|
-
static reject<T>(array: T[], predicate: (item: T) => boolean): T[];
|
|
671
|
+
static reject<T$1>(array: T$1[], predicate: (item: T$1) => boolean): T$1[];
|
|
653
672
|
/**
|
|
654
673
|
* Pick keys from an array of objects or an object
|
|
655
674
|
*/
|
|
656
|
-
static select<T extends object, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>;
|
|
675
|
+
static select<T$1 extends object, K$1 extends keyof T$1>(obj: T$1, keys: K$1[]): Pick<T$1, K$1>;
|
|
657
676
|
/**
|
|
658
677
|
* Returns the only element that passes a callback, throws if none or multiple
|
|
659
678
|
*/
|
|
660
|
-
static sole<T>(array: T[], predicate: (item: T) => boolean): T;
|
|
679
|
+
static sole<T$1>(array: T$1[], predicate: (item: T$1) => boolean): T$1;
|
|
661
680
|
/**
|
|
662
681
|
* Checks if at least one element satisfies the predicate
|
|
663
682
|
*/
|
|
664
|
-
static some<T>(array: T[], predicate: (item: T) => boolean): boolean;
|
|
683
|
+
static some<T$1>(array: T$1[], predicate: (item: T$1) => boolean): boolean;
|
|
665
684
|
/**
|
|
666
685
|
* Randomly shuffle an array and return a new array.
|
|
667
686
|
*/
|
|
668
|
-
static shuffle<T>(array: T[]): T[];
|
|
687
|
+
static shuffle<T$1>(array: T$1[]): T$1[];
|
|
669
688
|
/**
|
|
670
689
|
* Sort an array ascending using optional comparator.
|
|
671
690
|
*/
|
|
672
|
-
static sort<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
691
|
+
static sort<T$1>(array: T$1[], comparator?: (a: T$1, b: T$1) => number): T$1[];
|
|
673
692
|
/**
|
|
674
693
|
* Sort an array descending using optional comparator.
|
|
675
694
|
*/
|
|
676
|
-
static sortDesc<T>(array: T[], comparator?: (a: T, b: T) => number): T[];
|
|
695
|
+
static sortDesc<T$1>(array: T$1[], comparator?: (a: T$1, b: T$1) => number): T$1[];
|
|
677
696
|
/**
|
|
678
697
|
* Recursively sort arrays inside an array.
|
|
679
698
|
*/
|
|
680
|
-
static sortRecursive<T>(array: T[]): T[];
|
|
699
|
+
static sortRecursive<T$1>(array: T$1[]): T$1[];
|
|
681
700
|
/**
|
|
682
701
|
* Recursively sort arrays inside an array descending.
|
|
683
702
|
*/
|
|
684
|
-
static sortRecursiveDesc<T>(array: T[]): T[];
|
|
703
|
+
static sortRecursiveDesc<T$1>(array: T$1[]): T$1[];
|
|
685
704
|
/**
|
|
686
705
|
* Retrieve a value using dot notation
|
|
687
706
|
* Throws if value is not a string
|
|
@@ -694,15 +713,15 @@ declare class Arr {
|
|
|
694
713
|
* @param count
|
|
695
714
|
* @returns
|
|
696
715
|
*/
|
|
697
|
-
static take<T>(array: T[], count: number): T[];
|
|
716
|
+
static take<T$1>(array: T$1[], count: number): T$1[];
|
|
698
717
|
/**
|
|
699
718
|
* Filter an array based on a predicate function or key-value match.
|
|
700
719
|
*/
|
|
701
|
-
static where<T>(array: T[], predicate: ((item: T) => boolean) | Partial<T>): T[];
|
|
720
|
+
static where<T$1>(array: T$1[], predicate: ((item: T$1) => boolean) | Partial<T$1>): T$1[];
|
|
702
721
|
/**
|
|
703
722
|
* Filter an array of objects, keeping elements where the given key is not null/undefined.
|
|
704
723
|
*/
|
|
705
|
-
static whereNotNull<T>(array: T[], key: keyof T): T[];
|
|
724
|
+
static whereNotNull<T$1>(array: T$1[], key: keyof T$1): T$1[];
|
|
706
725
|
/**
|
|
707
726
|
* If the given value is not an array and not null, wrap it in one.
|
|
708
727
|
*
|
|
@@ -711,11 +730,11 @@ declare class Arr {
|
|
|
711
730
|
* @param value
|
|
712
731
|
* @returns
|
|
713
732
|
*/
|
|
714
|
-
static wrap<T>(value: T | T[] | null | undefined): T[];
|
|
733
|
+
static wrap<T$1>(value: T$1 | T$1[] | null | undefined): T$1[];
|
|
715
734
|
/**
|
|
716
735
|
* Return the first element of an array, undefined if empty.
|
|
717
736
|
*/
|
|
718
|
-
static head<T>(array: T[]): T | undefined;
|
|
737
|
+
static head<T$1>(array: T$1[]): T$1 | undefined;
|
|
719
738
|
/**
|
|
720
739
|
* Splits an array into chunks of a specified size.
|
|
721
740
|
*
|
|
@@ -724,7 +743,7 @@ declare class Arr {
|
|
|
724
743
|
* @param size - Size of each chunk (default: 2)
|
|
725
744
|
* @returns An array of chunks (arrays)
|
|
726
745
|
*/
|
|
727
|
-
static chunk: <T>(arr: T[], size?: number) => T[][];
|
|
746
|
+
static chunk: <T$1>(arr: T$1[], size?: number) => T$1[][];
|
|
728
747
|
/**
|
|
729
748
|
* Alternates between two arrays, creating a zipped result.
|
|
730
749
|
*
|
|
@@ -732,7 +751,7 @@ declare class Arr {
|
|
|
732
751
|
* @param b
|
|
733
752
|
* @returns
|
|
734
753
|
*/
|
|
735
|
-
static alternate<T>(a: T[], b: T[]): T[];
|
|
754
|
+
static alternate<T$1>(a: T$1[], b: T$1[]): T$1[];
|
|
736
755
|
/**
|
|
737
756
|
* Combine arrays and sum their values element by element.
|
|
738
757
|
*
|
|
@@ -747,35 +766,35 @@ declare class Arr {
|
|
|
747
766
|
* @param arr
|
|
748
767
|
* @returns
|
|
749
768
|
*/
|
|
750
|
-
static find<T>(key: T, arr: T[]): T | null;
|
|
769
|
+
static find<T$1>(key: T$1, arr: T$1[]): T$1 | null;
|
|
751
770
|
/**
|
|
752
771
|
* Check if array is empty.
|
|
753
772
|
*
|
|
754
773
|
* @param arr
|
|
755
774
|
* @returns
|
|
756
775
|
*/
|
|
757
|
-
static isEmpty<T>(arr: T[]): boolean;
|
|
776
|
+
static isEmpty<T$1>(arr: T$1[]): boolean;
|
|
758
777
|
/**
|
|
759
778
|
* Check if array is empty.
|
|
760
779
|
*
|
|
761
780
|
* @param arr
|
|
762
781
|
* @returns
|
|
763
782
|
*/
|
|
764
|
-
static isNotEmpty<T>(arr: T[]): boolean;
|
|
783
|
+
static isNotEmpty<T$1>(arr: T$1[]): boolean;
|
|
765
784
|
/**
|
|
766
785
|
* Pop the element off the end of array.
|
|
767
786
|
*
|
|
768
787
|
* @param arr
|
|
769
788
|
* @returns
|
|
770
789
|
*/
|
|
771
|
-
static pop<T>(arr: T[]): T[];
|
|
790
|
+
static pop<T$1>(arr: T$1[]): T$1[];
|
|
772
791
|
/**
|
|
773
792
|
* Create a new array in reverse order.
|
|
774
793
|
*
|
|
775
794
|
* @param arr
|
|
776
795
|
* @returns
|
|
777
796
|
*/
|
|
778
|
-
static reverse<T>(arr: T[]): T[];
|
|
797
|
+
static reverse<T$1>(arr: T$1[]): T$1[];
|
|
779
798
|
/**
|
|
780
799
|
* Return the first element of an array that satisfies the predicate,
|
|
781
800
|
* or the first element if no predicate is provided, otherwise the defaultValue.
|
|
@@ -816,6 +835,13 @@ declare class DateTime extends TimeClass {
|
|
|
816
835
|
* @returns
|
|
817
836
|
*/
|
|
818
837
|
start(unit?: OpUnitType): dayjs.Dayjs;
|
|
838
|
+
/**
|
|
839
|
+
* Set the timezone for the instance
|
|
840
|
+
*
|
|
841
|
+
* @param timezone
|
|
842
|
+
* @returns
|
|
843
|
+
*/
|
|
844
|
+
setTimezone(timezone?: string | undefined, keepLocalTime?: boolean | undefined): DateTime;
|
|
819
845
|
/**
|
|
820
846
|
* End time of a specific unit.
|
|
821
847
|
*
|
|
@@ -852,7 +878,7 @@ declare class DateTime extends TimeClass {
|
|
|
852
878
|
*
|
|
853
879
|
* @return {Date} object
|
|
854
880
|
*/
|
|
855
|
-
static fromTimestamp(timestamp: number):
|
|
881
|
+
static fromTimestamp(timestamp: number): DateTime;
|
|
856
882
|
/**
|
|
857
883
|
* Get current time instance.
|
|
858
884
|
*
|
|
@@ -3193,4 +3219,4 @@ declare function loadHelpers(target?: any): void;
|
|
|
3193
3219
|
*/
|
|
3194
3220
|
declare function cleanHelpers(target?: any): void;
|
|
3195
3221
|
//#endregion
|
|
3196
|
-
export { Arr, Arrayable, Callback, CamelToSnakeCase, Crypto_d_exports as Crypto, DateTime, DotPath,
|
|
3222
|
+
export { Arr, Arrayable, Callback, CamelToSnakeCase, Crypto_d_exports as Crypto, DateTime, DotPath, ExcerptOptions, Fallback, Function, GlobalHelpers, HtmlString, HtmlStringType, InvalidArgumentException, JsonSerializable, Jsonable, KeysToSnakeCase, Mode, Number_d_exports as Number, 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, isPlainObject, loadHelpers, modObj, random, randomColor, randomPassword, randomSecure, safeDot, secureToken, setNested, slugifyKeys, str, toBytes, toCssClasses, toCssStyles, toHumanTime, undot, uuid, verifyChecksum, xor };
|
package/dist/index.js
CHANGED
|
@@ -419,23 +419,6 @@ const toHumanTime = (seconds = 0, worded = false) => {
|
|
|
419
419
|
|
|
420
420
|
//#endregion
|
|
421
421
|
//#region src/Helpers/Obj.ts
|
|
422
|
-
var Obj_exports = /* @__PURE__ */ __export({
|
|
423
|
-
Obj: () => Obj,
|
|
424
|
-
data_fill: () => data_fill,
|
|
425
|
-
data_forget: () => data_forget,
|
|
426
|
-
data_get: () => data_get,
|
|
427
|
-
data_set: () => data_set,
|
|
428
|
-
dot: () => dot,
|
|
429
|
-
extractProperties: () => extractProperties,
|
|
430
|
-
getValue: () => getValue,
|
|
431
|
-
modObj: () => modObj,
|
|
432
|
-
safeDot: () => safeDot,
|
|
433
|
-
setNested: () => setNested,
|
|
434
|
-
slugifyKeys: () => slugifyKeys,
|
|
435
|
-
toCssClasses: () => toCssClasses,
|
|
436
|
-
toCssStyles: () => toCssStyles,
|
|
437
|
-
undot: () => undot
|
|
438
|
-
});
|
|
439
422
|
/**
|
|
440
423
|
* Flattens a nested object into a single-level object
|
|
441
424
|
* with dot-separated keys.
|
|
@@ -695,6 +678,15 @@ function data_forget(obj, path) {
|
|
|
695
678
|
}
|
|
696
679
|
}
|
|
697
680
|
}
|
|
681
|
+
/**
|
|
682
|
+
* Checks if a value is a plain object (not array, function, etc.)
|
|
683
|
+
*
|
|
684
|
+
* @param value
|
|
685
|
+
* @returns
|
|
686
|
+
*/
|
|
687
|
+
function isPlainObject(value) {
|
|
688
|
+
return value !== null && typeof value === "object" && !Array.isArray(value) && Object.prototype.toString.call(value) === "[object Object]";
|
|
689
|
+
}
|
|
698
690
|
var Obj = class Obj {
|
|
699
691
|
/**
|
|
700
692
|
* Check if the value is a non-null object (associative/accessible).
|
|
@@ -715,6 +707,27 @@ var Obj = class Obj {
|
|
|
715
707
|
return obj;
|
|
716
708
|
}
|
|
717
709
|
/**
|
|
710
|
+
* Deeply merges two or more objects.
|
|
711
|
+
* - Arrays are replaced (not concatenated)
|
|
712
|
+
* - Objects are merged recursively
|
|
713
|
+
* - Non-object values overwrite previous ones
|
|
714
|
+
*
|
|
715
|
+
* @param objects
|
|
716
|
+
* @returns
|
|
717
|
+
*/
|
|
718
|
+
static deepMerge(...objects) {
|
|
719
|
+
const result = {};
|
|
720
|
+
for (const obj of objects) {
|
|
721
|
+
if (!obj || typeof obj !== "object") continue;
|
|
722
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
723
|
+
const existing = result[key];
|
|
724
|
+
if (isPlainObject(existing) && isPlainObject(value)) result[key] = Obj.deepMerge(existing, value);
|
|
725
|
+
else result[key] = value;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
return result;
|
|
729
|
+
}
|
|
730
|
+
/**
|
|
718
731
|
* Split object into [keys, values]
|
|
719
732
|
*/
|
|
720
733
|
static divide(obj) {
|
|
@@ -1504,6 +1517,15 @@ var DateTime = class DateTime extends TimeClass {
|
|
|
1504
1517
|
return this.startOf(unit);
|
|
1505
1518
|
}
|
|
1506
1519
|
/**
|
|
1520
|
+
* Set the timezone for the instance
|
|
1521
|
+
*
|
|
1522
|
+
* @param timezone
|
|
1523
|
+
* @returns
|
|
1524
|
+
*/
|
|
1525
|
+
setTimezone(timezone$1, keepLocalTime) {
|
|
1526
|
+
return new DateTime(this.tz(timezone$1, keepLocalTime));
|
|
1527
|
+
}
|
|
1528
|
+
/**
|
|
1507
1529
|
* End time of a specific unit.
|
|
1508
1530
|
*
|
|
1509
1531
|
* @returns
|
|
@@ -1558,7 +1580,7 @@ var DateTime = class DateTime extends TimeClass {
|
|
|
1558
1580
|
* @return {Date} object
|
|
1559
1581
|
*/
|
|
1560
1582
|
static fromTimestamp(timestamp) {
|
|
1561
|
-
return
|
|
1583
|
+
return new DateTime(timestamp * 1e3);
|
|
1562
1584
|
}
|
|
1563
1585
|
/**
|
|
1564
1586
|
* Get current time instance.
|
|
@@ -6152,4 +6174,4 @@ function cleanHelpers(target = globalThis) {
|
|
|
6152
6174
|
}
|
|
6153
6175
|
|
|
6154
6176
|
//#endregion
|
|
6155
|
-
export { Arr, Crypto_exports as Crypto, DateTime,
|
|
6177
|
+
export { Arr, Crypto_exports as Crypto, DateTime, HtmlString, InvalidArgumentException, Mode, Number_exports as Number, Obj, RuntimeException, Str, Stringable, abbreviate, base64Decode, base64Encode, caesarCipher, checksum, cleanHelpers, data_fill, data_forget, data_get, data_set, dd, dot, dump, extractProperties, format, getValue, hash, hmac, humanize, isPlainObject, loadHelpers, modObj, random, randomColor, randomPassword, randomSecure, safeDot, secureToken, setNested, slugifyKeys, str, toBytes, toCssClasses, toCssStyles, toHumanTime, undot, uuid, verifyChecksum, xor };
|