toolbox-x 1.2.0 → 2.0.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/{Color-Dsut0Bex.d.cts → Color-B8MR8Vp0.d.cts} +1 -1
- package/dist/{Color-DCfoQk_-.d.mts → Color-D2MfZx7L.d.mts} +1 -1
- package/dist/{Stylog-DXZtHAbp.d.mts → Stylog-CSbLtqrZ.d.mts} +5 -5
- package/dist/{Stylog-TyLCTRtT.d.cts → Stylog-DF0CWtZb.d.cts} +5 -5
- package/dist/{area-CvSC96va.d.mts → area-C4tDXnGC.d.mts} +3 -3
- package/dist/{area-CcRQ6TfR.d.cts → area-CMJZ0gVm.d.cts} +3 -3
- package/dist/{array-B6jWzJ4F.d.mts → array-26Vs2HCs.d.mts} +1 -1
- package/dist/{array-CqDu610k.d.cts → array-DJAq9Qj8.d.cts} +1 -1
- package/dist/{basics-K8BDSYD6.cjs → basics-CJmdhXoo.cjs} +567 -14
- package/dist/{basics-1_M7UvCn.mjs → basics-CebgkY-n.mjs} +449 -16
- package/dist/{basics-KobRNhV-.d.cts → basics-Cis9Ej6c.d.mts} +5 -5
- package/dist/{basics-V5M2oltn.d.mts → basics-D4yU0NQ_.d.cts} +5 -5
- package/dist/{case-uKFzt5TY.cjs → case-Bd7QLHYw.cjs} +3 -3
- package/dist/{case-KdrBKjjK.d.mts → case-ChRzRBnY.d.mts} +12 -12
- package/dist/{case-BQwn5N-k.mjs → case-DBC4Rj0h.mjs} +3 -3
- package/dist/{case--Vjea9DS.d.cts → case-DkYSKSeV.d.cts} +12 -12
- package/dist/change-case.cjs +1 -1
- package/dist/change-case.d.cts +1 -1
- package/dist/change-case.d.mts +1 -1
- package/dist/change-case.mjs +1 -1
- package/dist/colors.d.cts +2 -2
- package/dist/colors.d.mts +2 -2
- package/dist/constants.d.cts +1 -1
- package/dist/constants.d.mts +1 -1
- package/dist/converter.cjs +2 -2
- package/dist/converter.d.cts +2 -2
- package/dist/converter.d.mts +2 -2
- package/dist/converter.mjs +2 -2
- package/dist/date.cjs +10 -10
- package/dist/date.d.cts +4 -4
- package/dist/date.d.mts +4 -4
- package/dist/date.mjs +10 -10
- package/dist/dom.cjs +5 -6
- package/dist/dom.d.cts +3 -3
- package/dist/dom.d.mts +3 -3
- package/dist/dom.mjs +4 -5
- package/dist/{form-DoQGMTOc.d.mts → form-Cp1OyCRI.d.cts} +2 -2
- package/dist/{form-mP-nl8EC.d.cts → form-DPdS2AhM.d.mts} +2 -2
- package/dist/guards-B2s2wlVN.mjs +425 -0
- package/dist/{guards-Cp6KAkVI.mjs → guards-BK1QuvFZ.mjs} +3 -3
- package/dist/{guards-DP5k4_Mm.cjs → guards-Bsh6Bfdq.cjs} +3 -3
- package/dist/{guards-0VjySrPM.cjs → guards-DMJcjPDt.cjs} +279 -3
- package/dist/guards.cjs +9 -9
- package/dist/guards.d.cts +6 -5
- package/dist/guards.d.mts +6 -5
- package/dist/guards.mjs +5 -5
- package/dist/{hash-BcoFHSu1.d.cts → hash-DfhOK0Fi.d.mts} +1 -1
- package/dist/{hash-GYRx2ee_.d.mts → hash-IdZN0mIe.d.cts} +1 -1
- package/dist/hash.cjs +8 -8
- package/dist/hash.d.cts +8 -8
- package/dist/hash.d.mts +8 -8
- package/dist/hash.mjs +4 -5
- package/dist/{http-status-xrlR-LlB.d.mts → http-status-B-yBZr-J.d.mts} +1 -1
- package/dist/{http-status-C0DOpCDf.d.cts → http-status-Dq_hoSG6.d.cts} +1 -1
- package/dist/http-status.cjs +4 -4
- package/dist/http-status.d.cts +6 -6
- package/dist/http-status.d.mts +6 -6
- package/dist/http-status.mjs +4 -4
- package/dist/index-C5FoCCbF.d.cts +292 -0
- package/dist/index-CIJWxnDS.d.mts +292 -0
- package/dist/index.cjs +67 -248
- package/dist/index.d.cts +25 -280
- package/dist/index.d.mts +25 -280
- package/dist/index.mjs +11 -194
- package/dist/{object-ChFVh95z.d.cts → object-X5fSMx-I.d.cts} +13 -1
- package/dist/{object-ChFVh95z.d.mts → object-X5fSMx-I.d.mts} +13 -1
- package/dist/{objectify-CfXtS_E0.mjs → objectify-CQa8gQib.mjs} +3 -4
- package/dist/{objectify-CZJr9hwg.cjs → objectify-xQvZS3UI.cjs} +5 -6
- package/dist/paginator.d.cts +1 -1
- package/dist/paginator.d.mts +1 -1
- package/dist/{parse-BpUlILVi.cjs → parse-DT7jbWx7.cjs} +5 -5
- package/dist/{parse-rcJRAOJl.mjs → parse-erxBG2hd.mjs} +5 -5
- package/dist/{pluralizer-CdG-VJ6t.d.cts → pluralizer-B8vuljyy.d.cts} +1 -1
- package/dist/{pluralizer-D2Lh8CdU.d.mts → pluralizer-DOdDskzF.d.mts} +1 -1
- package/dist/pluralizer.cjs +6 -6
- package/dist/pluralizer.d.cts +6 -6
- package/dist/pluralizer.d.mts +6 -6
- package/dist/pluralizer.mjs +6 -6
- package/dist/{specials-Cye93-uo.mjs → specials-Hq5Ncd6y.mjs} +2 -2
- package/dist/{specials-BM6cx43o.cjs → specials-dkYP1Nh2.cjs} +2 -2
- package/dist/{string-CkwTVFeL.d.mts → string-C51m7T6d.d.mts} +4 -2
- package/dist/{string-Dq2b8rcN.d.cts → string-CO7HP50i.d.cts} +4 -2
- package/dist/stylog.cjs +5 -5
- package/dist/stylog.d.cts +2 -2
- package/dist/stylog.d.mts +2 -2
- package/dist/stylog.mjs +5 -5
- package/dist/types/array.d.cts +1 -1
- package/dist/types/array.d.mts +1 -1
- package/dist/types/colors.d.cts +1 -1
- package/dist/types/colors.d.mts +1 -1
- package/dist/types/converter.d.cts +1 -1
- package/dist/types/converter.d.mts +1 -1
- package/dist/types/date.d.cts +1 -1
- package/dist/types/date.d.mts +1 -1
- package/dist/types/form.d.cts +1 -1
- package/dist/types/form.d.mts +1 -1
- package/dist/types/hash.d.cts +1 -1
- package/dist/types/hash.d.mts +1 -1
- package/dist/types/http-status.d.cts +1 -1
- package/dist/types/http-status.d.mts +1 -1
- package/dist/types/index.d.cts +2 -2
- package/dist/types/index.d.mts +2 -2
- package/dist/types/number.d.cts +1 -1
- package/dist/types/number.d.mts +1 -1
- package/dist/types/object.d.cts +2 -2
- package/dist/types/object.d.mts +2 -2
- package/dist/types/pluralizer.d.cts +1 -1
- package/dist/types/pluralizer.d.mts +1 -1
- package/dist/types/string.d.cts +2 -2
- package/dist/types/string.d.mts +2 -2
- package/dist/types/stylog.d.cts +1 -1
- package/dist/types/stylog.d.mts +1 -1
- package/dist/types/utils.d.cts +1 -1
- package/dist/types/utils.d.mts +1 -1
- package/dist/{utilities-CzyXCRHM.cjs → utilities-CWV1GPGY.cjs} +1 -1
- package/dist/{utilities-B9axOvOX.mjs → utilities-DPscNbS1.mjs} +1 -1
- package/dist/{uuid-DgTBxcVu.d.cts → uuid-BUI3Jt8n.d.cts} +3 -3
- package/dist/{uuid-Yc3Uu8qr.d.mts → uuid-mEiy14sf.d.mts} +3 -3
- package/dist/verbalizer.cjs +3 -3
- package/dist/verbalizer.d.cts +3 -3
- package/dist/verbalizer.d.mts +3 -3
- package/dist/verbalizer.mjs +3 -3
- package/package.json +7 -6
- package/dist/guards-DeO4ukiK.mjs +0 -221
- package/dist/utils-CFyEFj2Y.cjs +0 -568
- package/dist/utils-CN3ocK98.mjs +0 -449
package/dist/index.cjs
CHANGED
|
@@ -16,15 +16,14 @@
|
|
|
16
16
|
|
|
17
17
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
18
18
|
const require_primitives = require('./primitives-CBGICrDR.cjs');
|
|
19
|
-
const require_case = require('./case-
|
|
19
|
+
const require_case = require('./case-Bd7QLHYw.cjs');
|
|
20
20
|
const require_constants = require('./constants-B3nc8psr.cjs');
|
|
21
21
|
const require_countries = require('./countries-C0x58zVg.cjs');
|
|
22
|
-
const require_specials = require('./specials-
|
|
23
|
-
const require_utilities = require('./utilities-
|
|
24
|
-
const require_basics = require('./basics-
|
|
25
|
-
const require_guards = require('./guards-
|
|
26
|
-
const require_objectify = require('./objectify-
|
|
27
|
-
const require_utils = require('./utils-CFyEFj2Y.cjs');
|
|
22
|
+
const require_specials = require('./specials-dkYP1Nh2.cjs');
|
|
23
|
+
const require_utilities = require('./utilities-CWV1GPGY.cjs');
|
|
24
|
+
const require_basics = require('./basics-CJmdhXoo.cjs');
|
|
25
|
+
const require_guards = require('./guards-DMJcjPDt.cjs');
|
|
26
|
+
const require_objectify = require('./objectify-xQvZS3UI.cjs');
|
|
28
27
|
|
|
29
28
|
//#region src/string/anagram.ts
|
|
30
29
|
/** `WeakMap` to cache user provided dictionary array */
|
|
@@ -1239,10 +1238,12 @@ function getNthFibonacci(index) {
|
|
|
1239
1238
|
//#region src/number/convert.ts
|
|
1240
1239
|
/**
|
|
1241
1240
|
* * Converts a numeric value into its corresponding English word representation.
|
|
1242
|
-
* @warning ***Supports numeric values up to `10e19` or `10^20` (one hundred quintillion).***
|
|
1243
|
-
* @warning ***Decimal values are ignored; only the integer part is converted.***
|
|
1244
1241
|
* @param number - The number to convert into words.
|
|
1245
1242
|
* @returns The number converted in words.
|
|
1243
|
+
*
|
|
1244
|
+
* @warning
|
|
1245
|
+
* - Supports numeric values up to `10e19` (`10^20`) (one hundred quintillion).
|
|
1246
|
+
* - Decimal values are ignored; only the integer part is converted.
|
|
1246
1247
|
*/
|
|
1247
1248
|
function numberToWords(num) {
|
|
1248
1249
|
let number = Math.trunc(Number(num));
|
|
@@ -1506,101 +1507,6 @@ function digitToBangla(digit, preserveNonDigit = true) {
|
|
|
1506
1507
|
return "";
|
|
1507
1508
|
}
|
|
1508
1509
|
|
|
1509
|
-
//#endregion
|
|
1510
|
-
//#region src/number/prime.ts
|
|
1511
|
-
/**
|
|
1512
|
-
* * Checks if a number is prime.
|
|
1513
|
-
*
|
|
1514
|
-
* @param number The number to check.
|
|
1515
|
-
* @returns Boolean: `true` if the number is prime, otherwise `false`.
|
|
1516
|
-
*/
|
|
1517
|
-
const isPrime = (number) => {
|
|
1518
|
-
if (number < 2) return false;
|
|
1519
|
-
if (number === 2 || number === 3) return true;
|
|
1520
|
-
if (number % 2 === 0 || number % 3 === 0) return false;
|
|
1521
|
-
for (let i = 5; i * i <= number; i += 6) if (number % i === 0 || number % (i + 2) === 0) return false;
|
|
1522
|
-
return true;
|
|
1523
|
-
};
|
|
1524
|
-
/**
|
|
1525
|
-
* * Find prime numbers in a given range.
|
|
1526
|
-
*
|
|
1527
|
-
* @param start The starting number of the range. Default is `1`.
|
|
1528
|
-
* @param end The ending number of the range. Default is `1000`.
|
|
1529
|
-
* @returns An array of prime numbers within the range (inclusive).
|
|
1530
|
-
*/
|
|
1531
|
-
const findPrimeNumbers = (start = 1, end = 1e3) => {
|
|
1532
|
-
let startNumber = start, endNumber = end;
|
|
1533
|
-
if (start > end) [startNumber, endNumber] = [end, start];
|
|
1534
|
-
return Array.from({ length: endNumber - startNumber + 1 }, (_, i) => startNumber + i).filter(isPrime);
|
|
1535
|
-
};
|
|
1536
|
-
|
|
1537
|
-
//#endregion
|
|
1538
|
-
//#region src/array/basics.ts
|
|
1539
|
-
/**
|
|
1540
|
-
* * Flattens a nested array recursively or wraps any non-array data type in an array.
|
|
1541
|
-
*
|
|
1542
|
-
* @param input - The input value, which can be a nested array or a non-array value.
|
|
1543
|
-
* @returns A fully flattened array of type `Flatten<T>`. If the input is not an array, it wraps it in a single-element array.
|
|
1544
|
-
*/
|
|
1545
|
-
const flattenArray = (input) => {
|
|
1546
|
-
if (!Array.isArray(input)) return [input];
|
|
1547
|
-
return input.reduce((acc, item) => {
|
|
1548
|
-
return acc.concat(Array.isArray(item) ? flattenArray(item) : [item]);
|
|
1549
|
-
}, []);
|
|
1550
|
-
};
|
|
1551
|
-
/**
|
|
1552
|
-
* @deprecated _Please, use `findAll` instance method from `Finder` class for **more advanced filtering and searching.**_
|
|
1553
|
-
*
|
|
1554
|
-
* * Filters an array of objects based on multiple conditions for specified keys.
|
|
1555
|
-
* @param array - The array of objects to filter.
|
|
1556
|
-
* @param conditions - An object where keys represent the property names and values represent filter conditions.
|
|
1557
|
-
* The conditions can be a function `(value: T[K]) => boolean`.
|
|
1558
|
-
* @returns The filtered array of objects.
|
|
1559
|
-
* @throws `Error` If the input is not a valid array.
|
|
1560
|
-
*/
|
|
1561
|
-
const filterArrayOfObjects = (array, conditions) => {
|
|
1562
|
-
if (!Array.isArray(array)) throw new Error("The provided input is not a valid array!");
|
|
1563
|
-
return array?.filter((item) => Object.entries(conditions)?.every(([key, conditionFn]) => {
|
|
1564
|
-
if (typeof conditionFn === "function") return conditionFn(item[key]);
|
|
1565
|
-
return true;
|
|
1566
|
-
}));
|
|
1567
|
-
};
|
|
1568
|
-
/**
|
|
1569
|
-
* * Checks if a value is an empty array or an array with only empty values.
|
|
1570
|
-
*
|
|
1571
|
-
* @param value - The value to check.
|
|
1572
|
-
* @returns `true` if the value is not an array, an empty array, or an array containing only `null`, `undefined`, empty objects, or empty arrays.
|
|
1573
|
-
*/
|
|
1574
|
-
const isInvalidOrEmptyArray = (value) => {
|
|
1575
|
-
if (!Array.isArray(value)) return true;
|
|
1576
|
-
if (value?.length === 0) return true;
|
|
1577
|
-
return value?.every((item) => item == null || Array.isArray(item) && item?.length === 0 || typeof item === "object" && Object.keys(item || {})?.length === 0);
|
|
1578
|
-
};
|
|
1579
|
-
/**
|
|
1580
|
-
* * Shuffle the elements of an array.
|
|
1581
|
-
*
|
|
1582
|
-
* @param array Array to shuffle.
|
|
1583
|
-
* @returns Shuffled array.
|
|
1584
|
-
*/
|
|
1585
|
-
const shuffleArray = (array) => {
|
|
1586
|
-
if (isInvalidOrEmptyArray(array)) return array;
|
|
1587
|
-
const shuffled = [...array];
|
|
1588
|
-
for (let i = shuffled?.length - 1; i > 0; i--) {
|
|
1589
|
-
const j = Math.floor(Math.random() * (i + 1));
|
|
1590
|
-
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
|
1591
|
-
}
|
|
1592
|
-
return shuffled;
|
|
1593
|
-
};
|
|
1594
|
-
/**
|
|
1595
|
-
* * Get the last element of an array.
|
|
1596
|
-
*
|
|
1597
|
-
* @param array Array to get the last element from.
|
|
1598
|
-
* @returns The last element or `undefined` if the array is empty.
|
|
1599
|
-
*/
|
|
1600
|
-
const getLastArrayElement = (array) => {
|
|
1601
|
-
return array?.length > 0 ? array[array?.length - 1] : void 0;
|
|
1602
|
-
};
|
|
1603
|
-
|
|
1604
1510
|
//#endregion
|
|
1605
1511
|
//#region src/number/range.ts
|
|
1606
1512
|
/**
|
|
@@ -1633,7 +1539,7 @@ function getNumbersInRange(type = "any", options) {
|
|
|
1633
1539
|
if (type === "prime" && !require_primitives.isUndefined(multiplesOf)) console.warn("Warning: The \"multiplesOf\" option is ignored when the type is \"prime\"!");
|
|
1634
1540
|
switch (type) {
|
|
1635
1541
|
case "random":
|
|
1636
|
-
output = shuffleArray(_applyRangeOptions(min, max).map((n) => getRandomNumber({
|
|
1542
|
+
output = require_guards.shuffleArray(_applyRangeOptions(min, max).map((n) => getRandomNumber({
|
|
1637
1543
|
min: n,
|
|
1638
1544
|
max: n,
|
|
1639
1545
|
includeMin,
|
|
@@ -1641,7 +1547,7 @@ function getNumbersInRange(type = "any", options) {
|
|
|
1641
1547
|
})));
|
|
1642
1548
|
break;
|
|
1643
1549
|
case "prime":
|
|
1644
|
-
output = _applyRangeOptions(min, max).filter(isPrime);
|
|
1550
|
+
output = _applyRangeOptions(min, max).filter(require_guards.isPrime);
|
|
1645
1551
|
break;
|
|
1646
1552
|
case "odd":
|
|
1647
1553
|
output = _applyRangeOptions(min, max).filter(require_guards.isOdd);
|
|
@@ -1657,7 +1563,7 @@ function getNumbersInRange(type = "any", options) {
|
|
|
1657
1563
|
break;
|
|
1658
1564
|
}
|
|
1659
1565
|
if (type !== "prime") output = _applyMultiples(output, multiplesOf);
|
|
1660
|
-
return getAsString ?
|
|
1566
|
+
return getAsString ? require_basics.convertArrayToString(output, { separator }) : output;
|
|
1661
1567
|
}
|
|
1662
1568
|
|
|
1663
1569
|
//#endregion
|
|
@@ -1687,7 +1593,7 @@ function createOptionsArray(data, config) {
|
|
|
1687
1593
|
* @returns A new array with duplicates removed.
|
|
1688
1594
|
*/
|
|
1689
1595
|
function removeDuplicatesFromArray(array) {
|
|
1690
|
-
return array?.filter((item, index, self) => index === self?.findIndex((el) =>
|
|
1596
|
+
return array?.filter((item, index, self) => index === self?.findIndex((el) => require_basics.isDeepEqual(el, item)));
|
|
1691
1597
|
}
|
|
1692
1598
|
/**
|
|
1693
1599
|
* * Finds duplicate values in an array, runs deep comparison for objects and arrays.
|
|
@@ -1699,8 +1605,8 @@ function getDuplicates(array) {
|
|
|
1699
1605
|
const seen = [];
|
|
1700
1606
|
const duplicates = [];
|
|
1701
1607
|
for (const item of array) {
|
|
1702
|
-
const hasSeen = seen?.find((el) =>
|
|
1703
|
-
const hasDuplicate = duplicates?.find((el) =>
|
|
1608
|
+
const hasSeen = seen?.find((el) => require_basics.isDeepEqual(el, item));
|
|
1609
|
+
const hasDuplicate = duplicates?.find((el) => require_basics.isDeepEqual(el, item));
|
|
1704
1610
|
if (hasSeen && !hasDuplicate) duplicates?.push(item);
|
|
1705
1611
|
else if (!hasSeen) seen?.push(item);
|
|
1706
1612
|
}
|
|
@@ -1725,7 +1631,7 @@ function getDuplicates(array) {
|
|
|
1725
1631
|
function findMissingElements(array1, array2, missingFrom) {
|
|
1726
1632
|
const source = (missingFrom === "from-first" ? array1 : array2) ?? [];
|
|
1727
1633
|
const target = (missingFrom === "from-first" ? array2 : array1) ?? [];
|
|
1728
|
-
return source.filter((s) => !target?.some((t) =>
|
|
1634
|
+
return source.filter((s) => !target?.some((t) => require_basics.isDeepEqual(t, s)));
|
|
1729
1635
|
}
|
|
1730
1636
|
/**
|
|
1731
1637
|
* * Splits an array into chunks of a given size.
|
|
@@ -1759,7 +1665,7 @@ function splitArrayByProperty(source, property) {
|
|
|
1759
1665
|
if (!require_specials.isValidArray(source)) return [];
|
|
1760
1666
|
const grouped = {};
|
|
1761
1667
|
source.forEach((item) => {
|
|
1762
|
-
const rawKey =
|
|
1668
|
+
const rawKey = require_basics._resolveNestedKey(item, property);
|
|
1763
1669
|
const key = rawKey != null ? String(rawKey) : "__undefined__";
|
|
1764
1670
|
if (!grouped[key]) grouped[key] = [];
|
|
1765
1671
|
grouped[key].push(item);
|
|
@@ -1812,7 +1718,7 @@ function moveArrayElement(arr, fromIndex, toIndex) {
|
|
|
1812
1718
|
function sumFieldDifference(data, first, second, roundTo = 2) {
|
|
1813
1719
|
if (!require_specials.isValidArray(data)) return 0;
|
|
1814
1720
|
const total = data?.reduce((acc, item) => {
|
|
1815
|
-
return acc + (
|
|
1721
|
+
return acc + (require_basics._getNumericProp(item, first) - require_basics._getNumericProp(item, second));
|
|
1816
1722
|
}, 0);
|
|
1817
1723
|
return roundNumber(total, roundTo);
|
|
1818
1724
|
}
|
|
@@ -1830,7 +1736,7 @@ function sumFieldDifference(data, first, second, roundTo = 2) {
|
|
|
1830
1736
|
*/
|
|
1831
1737
|
function sumByField(data, field, roundTo = 2) {
|
|
1832
1738
|
if (!require_specials.isValidArray(data)) return 0;
|
|
1833
|
-
const total = data?.reduce((acc, item) => acc +
|
|
1739
|
+
const total = data?.reduce((acc, item) => acc + require_basics._getNumericProp(item, field), 0);
|
|
1834
1740
|
return roundNumber(total, roundTo);
|
|
1835
1741
|
}
|
|
1836
1742
|
/**
|
|
@@ -1847,7 +1753,7 @@ function sumByField(data, field, roundTo = 2) {
|
|
|
1847
1753
|
*/
|
|
1848
1754
|
function averageByField(data, field, roundTo = 2) {
|
|
1849
1755
|
if (!require_specials.isValidArray(data)) return 0;
|
|
1850
|
-
const total = data?.reduce((acc, item) => acc +
|
|
1756
|
+
const total = data?.reduce((acc, item) => acc + require_basics._getNumericProp(item, field), 0);
|
|
1851
1757
|
return roundNumber(total / data.length, roundTo);
|
|
1852
1758
|
}
|
|
1853
1759
|
/**
|
|
@@ -1865,7 +1771,7 @@ function averageByField(data, field, roundTo = 2) {
|
|
|
1865
1771
|
*/
|
|
1866
1772
|
function groupAndSumByField(data, groupBy, sumBy, roundTo = 2) {
|
|
1867
1773
|
if (!require_specials.isValidArray(data)) return [];
|
|
1868
|
-
return splitArrayByProperty(data, groupBy).map((group) => ({ [`${
|
|
1774
|
+
return splitArrayByProperty(data, groupBy).map((group) => ({ [`${require_basics._resolveNestedKey(group[0], groupBy)}`]: sumByField(group, sumBy, roundTo) }));
|
|
1869
1775
|
}
|
|
1870
1776
|
/**
|
|
1871
1777
|
* * Groups an array of objects by a primitive field and averages another numeric field per group.
|
|
@@ -1882,7 +1788,7 @@ function groupAndSumByField(data, groupBy, sumBy, roundTo = 2) {
|
|
|
1882
1788
|
*/
|
|
1883
1789
|
function groupAndAverageByField(data, groupBy, averageBy, roundTo = 2) {
|
|
1884
1790
|
if (!require_specials.isValidArray(data)) return [];
|
|
1885
|
-
return splitArrayByProperty(data, groupBy).map((group) => ({ [`${
|
|
1791
|
+
return splitArrayByProperty(data, groupBy).map((group) => ({ [`${require_basics._resolveNestedKey(group[0], groupBy)}`]: averageByField(group, averageBy, roundTo) }));
|
|
1886
1792
|
}
|
|
1887
1793
|
|
|
1888
1794
|
//#endregion
|
|
@@ -2110,95 +2016,6 @@ var Finder = class Finder {
|
|
|
2110
2016
|
}
|
|
2111
2017
|
};
|
|
2112
2018
|
|
|
2113
|
-
//#endregion
|
|
2114
|
-
//#region src/object/basics.ts
|
|
2115
|
-
/**
|
|
2116
|
-
* * Deep clone an object using `structuredClone` or deterministic *JSON serialization*.
|
|
2117
|
-
*
|
|
2118
|
-
* @param obj Object to clone.
|
|
2119
|
-
* @param serialize Whether to force deterministic JSON serialization instead of using `structuredClone`. Defaults to `false`.
|
|
2120
|
-
* @returns Deep cloned object.
|
|
2121
|
-
*
|
|
2122
|
-
* @remarks
|
|
2123
|
-
* **Primary behavior**
|
|
2124
|
-
* - By default (`serialize = false`), the function uses {@link https://developer.mozilla.org/docs/Web/API/Window/structuredClone structuredClone} when available. This supports:
|
|
2125
|
-
* - Circular references
|
|
2126
|
-
* - `Date` objects
|
|
2127
|
-
* - `Map` / `Set`
|
|
2128
|
-
* - `RegExp`
|
|
2129
|
-
* - Typed arrays
|
|
2130
|
-
* - Most built-in JavaScript types
|
|
2131
|
-
* - Preserves `undefined` values
|
|
2132
|
-
*
|
|
2133
|
-
* - **Note:** `structuredClone` **does not preserve class prototypes**, even though it preserves data types like `Date`, `Map`, and `Set`.
|
|
2134
|
-
*
|
|
2135
|
-
* **Deterministic serialization mode**
|
|
2136
|
-
* - When `serialize = true`, or when `structuredClone` is unavailable, the function falls back to **stable JSON serialization** via `stableStringify`. This guarantees:
|
|
2137
|
-
* - All object keys are sorted alphabetically.
|
|
2138
|
-
* - Consistent output across environments (deterministic).
|
|
2139
|
-
* - All `undefined` values are converted to `null`.
|
|
2140
|
-
* - Converting date-like objects (`Date`, `Chronos`, `Moment.js`, `Day.js`, `Luxon`, `JS-Joda`, `Temporal`) **in the same way that {@link JSON.stringify} would serialize them**, ensuring predictable and JSON-compliant output.
|
|
2141
|
-
*
|
|
2142
|
-
* - This mode is ideal for:
|
|
2143
|
-
* - Hashing
|
|
2144
|
-
* - Signature generation
|
|
2145
|
-
* - Deep equality checks
|
|
2146
|
-
* - Anything requiring deterministic, environment-neutral output
|
|
2147
|
-
*
|
|
2148
|
-
* **Deterministic mode limitations**
|
|
2149
|
-
* - JSON serialization will:
|
|
2150
|
-
* - Drop functions and `Symbol` values.
|
|
2151
|
-
* - Lose prototype and class instance information.
|
|
2152
|
-
* - Convert all date-like objects into strings.
|
|
2153
|
-
* - Fail on circular references.
|
|
2154
|
-
*
|
|
2155
|
-
* **Final safety fallback**
|
|
2156
|
-
* - If JSON serialization fails (e.g., due to circular references), the function returns a **shallow clone** (`{ ...obj }`) to ensure the cloning never throws.
|
|
2157
|
-
*/
|
|
2158
|
-
function cloneObject(obj, serialize = false) {
|
|
2159
|
-
try {
|
|
2160
|
-
if (!serialize && typeof structuredClone === "function") return structuredClone(obj);
|
|
2161
|
-
return JSON.parse(require_utils.stableStringify(obj));
|
|
2162
|
-
} catch {
|
|
2163
|
-
return { ...obj };
|
|
2164
|
-
}
|
|
2165
|
-
}
|
|
2166
|
-
/**
|
|
2167
|
-
* * Count the number of fields in an object.
|
|
2168
|
-
*
|
|
2169
|
-
* @param obj Object to check.
|
|
2170
|
-
* @returns Number of fields in the object.
|
|
2171
|
-
*/
|
|
2172
|
-
function countObjectFields(obj) {
|
|
2173
|
-
if (obj != null) return Object.keys(obj)?.length;
|
|
2174
|
-
return 0;
|
|
2175
|
-
}
|
|
2176
|
-
function extractObjectKeys(obj, tuple) {
|
|
2177
|
-
const keys = require_specials.isNotEmptyObject(obj) ? Object.keys(obj) : [];
|
|
2178
|
-
return tuple ? keys : keys;
|
|
2179
|
-
}
|
|
2180
|
-
/**
|
|
2181
|
-
* * Recursively extracts all nested keys from an object as an array.
|
|
2182
|
-
*
|
|
2183
|
-
* @remarks
|
|
2184
|
-
* - Returns an empty array (`[]`) for an empty object or a non-object value.
|
|
2185
|
-
* - For only top-level keys, use {@link extractObjectKeys}.
|
|
2186
|
-
*
|
|
2187
|
-
* @param obj The object from which to extract the keys.
|
|
2188
|
-
* @returns An array of all the nested keys (string literals) from the specified object.
|
|
2189
|
-
*/
|
|
2190
|
-
function extractObjectKeysDeep(obj) {
|
|
2191
|
-
function _getDeepKeys(candidate) {
|
|
2192
|
-
let result = [];
|
|
2193
|
-
for (const key in candidate) {
|
|
2194
|
-
result.push(key);
|
|
2195
|
-
if (require_specials.isNotEmptyObject(candidate[key])) result = [...result, ..._getDeepKeys(candidate[key])];
|
|
2196
|
-
}
|
|
2197
|
-
return result;
|
|
2198
|
-
}
|
|
2199
|
-
return require_specials.isNotEmptyObject(obj) ? _getDeepKeys(obj) : [];
|
|
2200
|
-
}
|
|
2201
|
-
|
|
2202
2019
|
//#endregion
|
|
2203
2020
|
//#region src/object/convert.ts
|
|
2204
2021
|
/**
|
|
@@ -2374,11 +2191,11 @@ exports.capitalizeString = require_case.capitalizeString;
|
|
|
2374
2191
|
exports.cardinalToOrdinal = require_utilities.getOrdinal;
|
|
2375
2192
|
exports.cardinalWordsToOrdinal = numberToWordsOrdinal;
|
|
2376
2193
|
exports.clampNumber = require_utilities.clampNumber;
|
|
2377
|
-
exports.cloneObject = cloneObject;
|
|
2378
|
-
exports.compareNaturally =
|
|
2379
|
-
exports.compareSorter =
|
|
2194
|
+
exports.cloneObject = require_guards.cloneObject;
|
|
2195
|
+
exports.compareNaturally = require_basics.naturalSort;
|
|
2196
|
+
exports.compareSorter = require_basics.naturalSort;
|
|
2380
2197
|
exports.computeTextDiff = computeTextDiff;
|
|
2381
|
-
exports.convertArrayToString =
|
|
2198
|
+
exports.convertArrayToString = require_basics.convertArrayToString;
|
|
2382
2199
|
exports.convertNumberToCurrency = require_utilities.formatCurrency;
|
|
2383
2200
|
exports.convertNumberToOrdinal = require_utilities.getOrdinal;
|
|
2384
2201
|
exports.convertNumberToWords = numberToWords;
|
|
@@ -2394,39 +2211,41 @@ exports.convertToOrdinal = require_utilities.getOrdinal;
|
|
|
2394
2211
|
exports.convertToRomanNumerals = convertToRomanNumerals;
|
|
2395
2212
|
exports.convertWordToNumber = wordsToNumber;
|
|
2396
2213
|
exports.convertWordsToNumber = wordsToNumber;
|
|
2397
|
-
exports.countInstanceMethods =
|
|
2398
|
-
exports.countObjectFields = countObjectFields;
|
|
2399
|
-
exports.countStaticMethods =
|
|
2214
|
+
exports.countInstanceMethods = require_basics.countInstanceMethods;
|
|
2215
|
+
exports.countObjectFields = require_guards.countObjectFields;
|
|
2216
|
+
exports.countStaticMethods = require_basics.countStaticMethods;
|
|
2400
2217
|
exports.countWords = countWords;
|
|
2401
2218
|
exports.countWordsInString = countWords;
|
|
2402
2219
|
exports.createOptionsArray = createOptionsArray;
|
|
2403
|
-
exports.debounceAction =
|
|
2404
|
-
exports.deepParsePrimitives =
|
|
2405
|
-
exports.definePrototypeMethod =
|
|
2220
|
+
exports.debounceAction = require_basics.debounceAction;
|
|
2221
|
+
exports.deepParsePrimitives = require_basics.deepParsePrimitives;
|
|
2222
|
+
exports.definePrototypeMethod = require_basics.definePrototypeMethod;
|
|
2406
2223
|
exports.deleteFields = deleteFields;
|
|
2407
2224
|
exports.deleteObjectFields = deleteFields;
|
|
2408
2225
|
exports.digitToBangla = digitToBangla;
|
|
2409
2226
|
exports.extractDuplicates = getDuplicates;
|
|
2410
2227
|
exports.extractDuplicatesFromArray = getDuplicates;
|
|
2411
2228
|
exports.extractEmails = require_guards.extractEmails;
|
|
2412
|
-
exports.
|
|
2413
|
-
exports.
|
|
2229
|
+
exports.extractEntries = require_guards.extractObjectEntries;
|
|
2230
|
+
exports.extractKeys = require_guards.extractObjectKeys;
|
|
2231
|
+
exports.extractKeysDeep = require_guards.extractObjectKeysDeep;
|
|
2414
2232
|
exports.extractMissingElements = findMissingElements;
|
|
2415
2233
|
exports.extractNewFields = require_objectify.extractNewFields;
|
|
2416
2234
|
exports.extractNumbers = extractNumbersFromString;
|
|
2417
2235
|
exports.extractNumbersFromString = extractNumbersFromString;
|
|
2418
|
-
exports.
|
|
2419
|
-
exports.
|
|
2236
|
+
exports.extractObjectEntries = require_guards.extractObjectEntries;
|
|
2237
|
+
exports.extractObjectKeys = require_guards.extractObjectKeys;
|
|
2238
|
+
exports.extractObjectKeysDeep = require_guards.extractObjectKeysDeep;
|
|
2420
2239
|
exports.extractURLs = require_guards.extractURLs;
|
|
2421
2240
|
exports.extractUpdatedAndNewFields = require_objectify.extractUpdatedAndNewFields;
|
|
2422
2241
|
exports.extractUpdatedFields = require_objectify.extractUpdatedFields;
|
|
2423
2242
|
exports.factorial = factorial;
|
|
2424
2243
|
exports.factorsOf = getFactors;
|
|
2425
2244
|
exports.fibonacciGenerator = fibonacciGenerator;
|
|
2426
|
-
exports.filterArrayOfObjects = filterArrayOfObjects;
|
|
2245
|
+
exports.filterArrayOfObjects = require_guards.filterArrayOfObjects;
|
|
2427
2246
|
exports.findMissingElements = findMissingElements;
|
|
2428
|
-
exports.findPrimeNumbers = findPrimeNumbers;
|
|
2429
|
-
exports.flattenArray = flattenArray;
|
|
2247
|
+
exports.findPrimeNumbers = require_guards.findPrimeNumbers;
|
|
2248
|
+
exports.flattenArray = require_guards.flattenArray;
|
|
2430
2249
|
exports.flattenObjectDotNotation = require_objectify.flattenObjectDotNotation;
|
|
2431
2250
|
exports.flattenObjectKeyValue = require_objectify.flattenObjectKeyValue;
|
|
2432
2251
|
exports.formatCurrency = require_utilities.formatCurrency;
|
|
@@ -2439,7 +2258,7 @@ exports.generateRandomID = require_basics.generateRandomID;
|
|
|
2439
2258
|
exports.getAverage = getAverage;
|
|
2440
2259
|
exports.getAverageOfNumbers = getAverage;
|
|
2441
2260
|
exports.getCharacterDifferences = getCharacterDifferences;
|
|
2442
|
-
exports.getClassDetails =
|
|
2261
|
+
exports.getClassDetails = require_basics.getClassDetails;
|
|
2443
2262
|
exports.getCountryByPhone = getCountryByPhone;
|
|
2444
2263
|
exports.getDivisors = getFactors;
|
|
2445
2264
|
exports.getDuplicates = getDuplicates;
|
|
@@ -2450,10 +2269,10 @@ exports.getFibonacci = getFibonacciSeries;
|
|
|
2450
2269
|
exports.getFibonacciNumbers = getFibonacciSeries;
|
|
2451
2270
|
exports.getFibonacciSeries = getFibonacciSeries;
|
|
2452
2271
|
exports.getFibonacciSeriesMemo = getFibonacciSeriesMemo;
|
|
2453
|
-
exports.getInstanceGetterNames =
|
|
2454
|
-
exports.getInstanceMethodNames =
|
|
2455
|
-
exports.getInstanceMethodsCount =
|
|
2456
|
-
exports.getLastArrayElement = getLastArrayElement;
|
|
2272
|
+
exports.getInstanceGetterNames = require_basics.getInstanceGetterNames;
|
|
2273
|
+
exports.getInstanceMethodNames = require_basics.getInstanceMethodNames;
|
|
2274
|
+
exports.getInstanceMethodsCount = require_basics.countInstanceMethods;
|
|
2275
|
+
exports.getLastArrayElement = require_guards.getLastArrayElement;
|
|
2457
2276
|
exports.getLevenshteinDistance = getLevenshteinDistance;
|
|
2458
2277
|
exports.getMemoizedFibonacci = getFibonacciSeriesMemo;
|
|
2459
2278
|
exports.getMemoizedFibonacciSeries = getFibonacciSeriesMemo;
|
|
@@ -2462,33 +2281,32 @@ exports.getNthFibonacci = getNthFibonacci;
|
|
|
2462
2281
|
exports.getNumbersInRange = getNumbersInRange;
|
|
2463
2282
|
exports.getOrdinal = require_utilities.getOrdinal;
|
|
2464
2283
|
exports.getOrdinalNumber = require_utilities.getOrdinal;
|
|
2465
|
-
exports.getPrimeNumbers = findPrimeNumbers;
|
|
2284
|
+
exports.getPrimeNumbers = require_guards.findPrimeNumbers;
|
|
2466
2285
|
exports.getRandomDecimal = require_utilities.getRandomFloat;
|
|
2467
2286
|
exports.getRandomFloat = require_utilities.getRandomFloat;
|
|
2468
2287
|
exports.getRandomInt = getRandomNumber;
|
|
2469
2288
|
exports.getRandomNumber = getRandomNumber;
|
|
2470
|
-
exports.getStaticGetterNames =
|
|
2471
|
-
exports.getStaticMethodNames =
|
|
2472
|
-
exports.getStaticMethodsCount =
|
|
2289
|
+
exports.getStaticGetterNames = require_basics.getStaticGetterNames;
|
|
2290
|
+
exports.getStaticMethodNames = require_basics.getStaticMethodNames;
|
|
2291
|
+
exports.getStaticMethodsCount = require_basics.countStaticMethods;
|
|
2473
2292
|
exports.getSumOfNumbers = sumNumbers;
|
|
2474
2293
|
exports.groupAndAverageByField = groupAndAverageByField;
|
|
2475
2294
|
exports.groupAndAvgByField = groupAndAverageByField;
|
|
2476
2295
|
exports.groupAndSumByField = groupAndSumByField;
|
|
2477
2296
|
exports.groupArrayByProperty = splitArrayByProperty;
|
|
2478
2297
|
exports.integerToRoman = convertToRomanNumerals;
|
|
2479
|
-
exports.isDeepEqual =
|
|
2480
|
-
exports.isInvalidOrEmptyArray = isInvalidOrEmptyArray;
|
|
2481
|
-
exports.isPrime = isPrime;
|
|
2482
|
-
exports.isPrimeNumber = isPrime;
|
|
2483
|
-
exports.
|
|
2484
|
-
exports.joinArrayElements = require_utils.convertArrayToString;
|
|
2298
|
+
exports.isDeepEqual = require_basics.isDeepEqual;
|
|
2299
|
+
exports.isInvalidOrEmptyArray = require_guards.isInvalidOrEmptyArray;
|
|
2300
|
+
exports.isPrime = require_guards.isPrime;
|
|
2301
|
+
exports.isPrimeNumber = require_guards.isPrime;
|
|
2302
|
+
exports.joinArrayElements = require_basics.convertArrayToString;
|
|
2485
2303
|
exports.levenshteinDistance = getLevenshteinDistance;
|
|
2486
2304
|
exports.maskString = require_guards.maskString;
|
|
2487
2305
|
exports.mergeAndFlattenObjects = require_objectify.mergeAndFlattenObjects;
|
|
2488
2306
|
exports.mergeObjects = require_objectify.mergeObjects;
|
|
2489
2307
|
exports.moveArrayElement = moveArrayElement;
|
|
2490
|
-
exports.naturalSort =
|
|
2491
|
-
exports.naturalSortForString =
|
|
2308
|
+
exports.naturalSort = require_basics.naturalSort;
|
|
2309
|
+
exports.naturalSortForString = require_basics.naturalSort;
|
|
2492
2310
|
exports.normalizeNumber = require_utilities.normalizeNumber;
|
|
2493
2311
|
exports.normalizeString = require_guards.normalizeString;
|
|
2494
2312
|
exports.numberToOrdinal = require_utilities.getOrdinal;
|
|
@@ -2496,14 +2314,15 @@ exports.numberToRoman = convertToRomanNumerals;
|
|
|
2496
2314
|
exports.numberToWords = numberToWords;
|
|
2497
2315
|
exports.numberToWordsOrdinal = numberToWordsOrdinal;
|
|
2498
2316
|
exports.numericToRoman = convertToRomanNumerals;
|
|
2317
|
+
exports.objectEntries = require_guards.extractObjectEntries;
|
|
2499
2318
|
exports.omitFields = deleteFields;
|
|
2500
2319
|
exports.omitObjectFields = deleteFields;
|
|
2501
|
-
exports.parseJSON =
|
|
2502
|
-
exports.parseJsonDeep =
|
|
2320
|
+
exports.parseJSON = require_basics.parseJSON;
|
|
2321
|
+
exports.parseJsonDeep = require_basics.parseJSON;
|
|
2503
2322
|
exports.parseJsonToObject = require_objectify.parseJsonToObject;
|
|
2504
2323
|
exports.parseNumbersFromText = extractNumbersFromString;
|
|
2505
2324
|
exports.parseObjectValues = require_objectify.parseObjectValues;
|
|
2506
|
-
exports.parsePrimitivesDeep =
|
|
2325
|
+
exports.parsePrimitivesDeep = require_basics.deepParsePrimitives;
|
|
2507
2326
|
exports.parseStringifiedObjectValues = require_objectify.parseObjectValues;
|
|
2508
2327
|
exports.pickFields = pickFields;
|
|
2509
2328
|
exports.pickFieldsByCondition = pickObjectFieldsByCondition;
|
|
@@ -2528,19 +2347,19 @@ exports.roundToDecimal = roundNumber;
|
|
|
2528
2347
|
exports.roundToNearest = require_utilities.roundToNearest;
|
|
2529
2348
|
exports.roundToNearestInterval = require_utilities.roundToNearest;
|
|
2530
2349
|
exports.sanitizeData = require_objectify.sanitizeData;
|
|
2531
|
-
exports.shuffleArray = shuffleArray;
|
|
2350
|
+
exports.shuffleArray = require_guards.shuffleArray;
|
|
2532
2351
|
exports.slugifyString = require_guards.slugifyString;
|
|
2533
|
-
exports.sortAnArray =
|
|
2352
|
+
exports.sortAnArray = require_basics.sortAnArray;
|
|
2534
2353
|
exports.splitArray = splitArray;
|
|
2535
2354
|
exports.splitArrayByProperty = splitArrayByProperty;
|
|
2536
|
-
exports.stableStringify =
|
|
2537
|
-
exports.stripJsonEdgeGarbage =
|
|
2355
|
+
exports.stableStringify = require_basics.stableStringify;
|
|
2356
|
+
exports.stripJsonEdgeGarbage = require_basics.stripJsonEdgeGarbage;
|
|
2538
2357
|
exports.sumByField = sumByField;
|
|
2539
2358
|
exports.sumDigits = sumDigits;
|
|
2540
2359
|
exports.sumFieldDifference = sumFieldDifference;
|
|
2541
2360
|
exports.sumNumbers = sumNumbers;
|
|
2542
2361
|
exports.sumOfNumbers = sumNumbers;
|
|
2543
|
-
exports.throttleAction =
|
|
2362
|
+
exports.throttleAction = require_basics.throttleAction;
|
|
2544
2363
|
exports.toRoman = convertToRomanNumerals;
|
|
2545
2364
|
exports.toRomanNumeral = convertToRomanNumerals;
|
|
2546
2365
|
exports.totalDeltaByField = sumFieldDifference;
|