@vielzeug/toolkit 1.0.13 → 1.0.14

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.
Files changed (82) hide show
  1. package/dist/array/{sortBy.cjs → arrange.cjs} +2 -2
  2. package/dist/array/arrange.cjs.map +1 -0
  3. package/dist/array/arrange.js +6 -0
  4. package/dist/array/arrange.js.map +1 -0
  5. package/dist/array/chunk.cjs.map +1 -1
  6. package/dist/array/chunk.js.map +1 -1
  7. package/dist/array/list.cjs +1 -1
  8. package/dist/array/list.cjs.map +1 -1
  9. package/dist/array/list.js +86 -53
  10. package/dist/array/list.js.map +1 -1
  11. package/dist/array/remoteList.cjs +2 -0
  12. package/dist/array/remoteList.cjs.map +1 -0
  13. package/dist/array/remoteList.js +123 -0
  14. package/dist/array/remoteList.js.map +1 -0
  15. package/dist/date/expires.cjs.map +1 -1
  16. package/dist/date/expires.js.map +1 -1
  17. package/dist/date/interval.cjs.map +1 -1
  18. package/dist/date/interval.js.map +1 -1
  19. package/dist/date/timeDiff.cjs.map +1 -1
  20. package/dist/date/timeDiff.js.map +1 -1
  21. package/dist/function/memo.cjs.map +1 -1
  22. package/dist/function/memo.js.map +1 -1
  23. package/dist/function/parallel.cjs +2 -0
  24. package/dist/function/parallel.cjs.map +1 -0
  25. package/dist/function/parallel.js +28 -0
  26. package/dist/function/parallel.js.map +1 -0
  27. package/dist/function/proxy.cjs.map +1 -1
  28. package/dist/function/proxy.js.map +1 -1
  29. package/dist/function/prune.cjs +2 -0
  30. package/dist/function/prune.cjs.map +1 -0
  31. package/dist/function/prune.js +30 -0
  32. package/dist/function/prune.js.map +1 -0
  33. package/dist/index.cjs +1 -1
  34. package/dist/index.d.ts +400 -51
  35. package/dist/index.js +218 -194
  36. package/dist/index.js.map +1 -1
  37. package/dist/math/abs.cjs +2 -0
  38. package/dist/math/abs.cjs.map +1 -0
  39. package/dist/math/abs.js +7 -0
  40. package/dist/math/abs.js.map +1 -0
  41. package/dist/math/add.cjs +2 -0
  42. package/dist/math/add.cjs.map +1 -0
  43. package/dist/math/add.js +9 -0
  44. package/dist/math/add.js.map +1 -0
  45. package/dist/math/allocate.cjs +2 -0
  46. package/dist/math/allocate.cjs.map +1 -0
  47. package/dist/math/allocate.js +29 -0
  48. package/dist/math/allocate.js.map +1 -0
  49. package/dist/math/distribute.cjs +2 -0
  50. package/dist/math/distribute.cjs.map +1 -0
  51. package/dist/math/distribute.js +18 -0
  52. package/dist/math/distribute.js.map +1 -0
  53. package/dist/math/divide.cjs +2 -0
  54. package/dist/math/divide.cjs.map +1 -0
  55. package/dist/math/divide.js +11 -0
  56. package/dist/math/divide.js.map +1 -0
  57. package/dist/math/multiply.cjs +2 -0
  58. package/dist/math/multiply.cjs.map +1 -0
  59. package/dist/math/multiply.js +9 -0
  60. package/dist/math/multiply.js.map +1 -0
  61. package/dist/math/subtract.cjs +2 -0
  62. package/dist/math/subtract.cjs.map +1 -0
  63. package/dist/math/subtract.js +9 -0
  64. package/dist/math/subtract.js.map +1 -0
  65. package/dist/money/currency.cjs +2 -0
  66. package/dist/money/currency.cjs.map +1 -0
  67. package/dist/money/currency.js +49 -0
  68. package/dist/money/currency.js.map +1 -0
  69. package/dist/money/exchange.cjs +2 -0
  70. package/dist/money/exchange.cjs.map +1 -0
  71. package/dist/money/exchange.js +13 -0
  72. package/dist/money/exchange.js.map +1 -0
  73. package/dist/object/merge.cjs.map +1 -1
  74. package/dist/object/merge.js.map +1 -1
  75. package/dist/object/parseJSON.cjs.map +1 -1
  76. package/dist/object/parseJSON.js.map +1 -1
  77. package/dist/object/path.cjs.map +1 -1
  78. package/dist/object/path.js.map +1 -1
  79. package/package.json +1 -1
  80. package/dist/array/sortBy.cjs.map +0 -1
  81. package/dist/array/sortBy.js +0 -6
  82. package/dist/array/sortBy.js.map +0 -1
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(t,e){if(typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number")return t*e;throw new TypeError("Both arguments must be of the same type (number or bigint)")}exports.multiply=r;
2
+ //# sourceMappingURL=multiply.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiply.cjs","sources":["../../src/math/multiply.ts"],"sourcesContent":["/**\n * Multiplies a number by a scalar with precision handling for financial calculations.\n * Supports both regular numbers and bigint for exact precision.\n *\n * @example\n * ```ts\n * multiply(10, 5); // 50\n * multiply(0.1, 3); // 0.3 (precision-safe)\n * multiply(100n, 5n); // 500n\n * ```\n *\n * @param a - Number to multiply\n * @param b - Multiplier\n * @returns Product of a and b\n */\nexport function multiply(a: number, b: number): number;\nexport function multiply(a: bigint, b: bigint): bigint;\nexport function multiply(a: number | bigint, b: number | bigint): number | bigint {\n if (typeof a === 'bigint' && typeof b === 'bigint') {\n return a * b;\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return a * b;\n }\n throw new TypeError('Both arguments must be of the same type (number or bigint)');\n}\n"],"names":["multiply","a","b"],"mappings":"gFAiBO,SAASA,EAASC,EAAoBC,EAAqC,CAIhF,GAHI,OAAOD,GAAM,UAAY,OAAOC,GAAM,UAGtC,OAAOD,GAAM,UAAY,OAAOC,GAAM,SACxC,OAAOD,EAAIC,EAEb,MAAM,IAAI,UAAU,4DAA4D,CAClF"}
@@ -0,0 +1,9 @@
1
+ function r(t, e) {
2
+ if (typeof t == "bigint" && typeof e == "bigint" || typeof t == "number" && typeof e == "number")
3
+ return t * e;
4
+ throw new TypeError("Both arguments must be of the same type (number or bigint)");
5
+ }
6
+ export {
7
+ r as multiply
8
+ };
9
+ //# sourceMappingURL=multiply.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiply.js","sources":["../../src/math/multiply.ts"],"sourcesContent":["/**\n * Multiplies a number by a scalar with precision handling for financial calculations.\n * Supports both regular numbers and bigint for exact precision.\n *\n * @example\n * ```ts\n * multiply(10, 5); // 50\n * multiply(0.1, 3); // 0.3 (precision-safe)\n * multiply(100n, 5n); // 500n\n * ```\n *\n * @param a - Number to multiply\n * @param b - Multiplier\n * @returns Product of a and b\n */\nexport function multiply(a: number, b: number): number;\nexport function multiply(a: bigint, b: bigint): bigint;\nexport function multiply(a: number | bigint, b: number | bigint): number | bigint {\n if (typeof a === 'bigint' && typeof b === 'bigint') {\n return a * b;\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return a * b;\n }\n throw new TypeError('Both arguments must be of the same type (number or bigint)');\n}\n"],"names":["multiply","a","b"],"mappings":"AAiBO,SAASA,EAASC,GAAoBC,GAAqC;AAIhF,MAHI,OAAOD,KAAM,YAAY,OAAOC,KAAM,YAGtC,OAAOD,KAAM,YAAY,OAAOC,KAAM;AACxC,WAAOD,IAAIC;AAEb,QAAM,IAAI,UAAU,4DAA4D;AAClF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(t,e){if(typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number")return t-e;throw new TypeError("Both arguments must be of the same type (number or bigint)")}exports.subtract=r;
2
+ //# sourceMappingURL=subtract.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subtract.cjs","sources":["../../src/math/subtract.ts"],"sourcesContent":["/**\n * Subtracts one number from another with precision handling for financial calculations.\n * Supports both regular numbers and bigint for exact precision.\n *\n * @example\n * ```ts\n * subtract(20, 10); // 10\n * subtract(0.3, 0.1); // 0.2 (precision-safe)\n * subtract(300n, 100n); // 200n\n * ```\n *\n * @param a - Number to subtract from\n * @param b - Number to subtract\n * @returns Difference of a and b\n */\nexport function subtract(a: number, b: number): number;\nexport function subtract(a: bigint, b: bigint): bigint;\nexport function subtract(a: number | bigint, b: number | bigint): number | bigint {\n if (typeof a === 'bigint' && typeof b === 'bigint') {\n return a - b;\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n throw new TypeError('Both arguments must be of the same type (number or bigint)');\n}\n"],"names":["subtract","a","b"],"mappings":"gFAiBO,SAASA,EAASC,EAAoBC,EAAqC,CAIhF,GAHI,OAAOD,GAAM,UAAY,OAAOC,GAAM,UAGtC,OAAOD,GAAM,UAAY,OAAOC,GAAM,SACxC,OAAOD,EAAIC,EAEb,MAAM,IAAI,UAAU,4DAA4D,CAClF"}
@@ -0,0 +1,9 @@
1
+ function r(t, e) {
2
+ if (typeof t == "bigint" && typeof e == "bigint" || typeof t == "number" && typeof e == "number")
3
+ return t - e;
4
+ throw new TypeError("Both arguments must be of the same type (number or bigint)");
5
+ }
6
+ export {
7
+ r as subtract
8
+ };
9
+ //# sourceMappingURL=subtract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subtract.js","sources":["../../src/math/subtract.ts"],"sourcesContent":["/**\n * Subtracts one number from another with precision handling for financial calculations.\n * Supports both regular numbers and bigint for exact precision.\n *\n * @example\n * ```ts\n * subtract(20, 10); // 10\n * subtract(0.3, 0.1); // 0.2 (precision-safe)\n * subtract(300n, 100n); // 200n\n * ```\n *\n * @param a - Number to subtract from\n * @param b - Number to subtract\n * @returns Difference of a and b\n */\nexport function subtract(a: number, b: number): number;\nexport function subtract(a: bigint, b: bigint): bigint;\nexport function subtract(a: number | bigint, b: number | bigint): number | bigint {\n if (typeof a === 'bigint' && typeof b === 'bigint') {\n return a - b;\n }\n if (typeof a === 'number' && typeof b === 'number') {\n return a - b;\n }\n throw new TypeError('Both arguments must be of the same type (number or bigint)');\n}\n"],"names":["subtract","a","b"],"mappings":"AAiBO,SAASA,EAASC,GAAoBC,GAAqC;AAIhF,MAHI,OAAOD,KAAM,YAAY,OAAOC,KAAM,YAGtC,OAAOD,KAAM,YAAY,OAAOC,KAAM;AACxC,WAAOD,IAAIC;AAEb,QAAM,IAAI,UAAU,4DAA4D;AAClF;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function u(e,t={}){const{locale:c="en-US",style:i="symbol",minimumFractionDigits:s,maximumFractionDigits:a}=t,n=l(e.currency),o=10**n,m=Number(e.amount)/o;let r;switch(i){case"symbol":r="symbol";break;case"code":r="code";break;case"name":r="name";break;default:r="symbol"}return new Intl.NumberFormat(c,{currency:e.currency,currencyDisplay:r,maximumFractionDigits:a??n,minimumFractionDigits:s??n,style:"currency"}).format(m)}function l(e){const t=["BIF","CLP","DJF","GNF","JPY","KMF","KRW","MGA","PYG","RWF","UGX","VND","VUV","XAF","XOF","XPF"],c=["BHD","IQD","JOD","KWD","LYD","OMR","TND"];return t.includes(e.toUpperCase())?0:c.includes(e.toUpperCase())?3:2}exports.currency=u;
2
+ //# sourceMappingURL=currency.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.cjs","sources":["../../src/money/currency.ts"],"sourcesContent":["import type { Money } from './types';\n\n/**\n * Options for currency formatting.\n */\nexport type CurrencyFormatOptions = {\n locale?: string; // BCP 47 language tag (e.g., 'en-US', 'de-DE')\n style?: 'symbol' | 'code' | 'name'; // Display style\n minimumFractionDigits?: number; // Minimum decimal places\n maximumFractionDigits?: number; // Maximum decimal places\n};\n\n/**\n * Formats a monetary amount as a currency string with proper locale and symbol.\n * Handles decimal places automatically based on currency.\n *\n * @example\n * ```ts\n * const money = { amount: 123456n, currency: 'USD' };\n *\n * currency(money); // '$1,234.56' (default en-US)\n * currency(money, { locale: 'de-DE' }); // '1.234,56 $'\n * currency(money, { style: 'code' }); // 'USD 1,234.56'\n * currency(money, { style: 'name' }); // '1,234.56 US dollars'\n * ```\n *\n * @param money - Money object to format\n * @param options - Formatting options\n * @returns Formatted currency string\n */\nexport function currency(money: Money, options: CurrencyFormatOptions = {}): string {\n const { locale = 'en-US', style = 'symbol', minimumFractionDigits, maximumFractionDigits } = options;\n\n // Get decimal places for currency (default to 2 for most currencies)\n const decimalPlaces = getCurrencyDecimals(money.currency);\n\n // Convert bigint amount to decimal (divide by 10^decimalPlaces)\n const divisor = 10 ** decimalPlaces;\n const amount = Number(money.amount) / divisor;\n\n // Determine Intl.NumberFormat style\n let currencyDisplay: 'symbol' | 'code' | 'name';\n switch (style) {\n case 'symbol':\n currencyDisplay = 'symbol';\n break;\n case 'code':\n currencyDisplay = 'code';\n break;\n case 'name':\n currencyDisplay = 'name';\n break;\n default:\n currencyDisplay = 'symbol';\n }\n\n const formatter = new Intl.NumberFormat(locale, {\n currency: money.currency,\n currencyDisplay,\n maximumFractionDigits: maximumFractionDigits ?? decimalPlaces,\n minimumFractionDigits: minimumFractionDigits ?? decimalPlaces,\n style: 'currency',\n });\n\n return formatter.format(amount);\n}\n\n/**\n * Gets the number of decimal places for a currency.\n * Most currencies use 2 decimal places, but some use 0 or 3.\n */\nfunction getCurrencyDecimals(currencyCode: string): number {\n const zeroDecimalCurrencies = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n ];\n const threeDecimalCurrencies = ['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND'];\n\n if (zeroDecimalCurrencies.includes(currencyCode.toUpperCase())) {\n return 0;\n }\n if (threeDecimalCurrencies.includes(currencyCode.toUpperCase())) {\n return 3;\n }\n return 2; // Default for most currencies\n}\n"],"names":["currency","money","options","locale","style","minimumFractionDigits","maximumFractionDigits","decimalPlaces","getCurrencyDecimals","divisor","amount","currencyDisplay","currencyCode","zeroDecimalCurrencies","threeDecimalCurrencies"],"mappings":"gFA8BO,SAASA,EAASC,EAAcC,EAAiC,GAAY,CAClF,KAAM,CAAE,OAAAC,EAAS,QAAS,MAAAC,EAAQ,SAAU,sBAAAC,EAAuB,sBAAAC,GAA0BJ,EAGvFK,EAAgBC,EAAoBP,EAAM,QAAQ,EAGlDQ,EAAU,IAAMF,EAChBG,EAAS,OAAOT,EAAM,MAAM,EAAIQ,EAGtC,IAAIE,EACJ,OAAQP,EAAA,CACN,IAAK,SACHO,EAAkB,SAClB,MACF,IAAK,OACHA,EAAkB,OAClB,MACF,IAAK,OACHA,EAAkB,OAClB,MACF,QACEA,EAAkB,QAAA,CAWtB,OARkB,IAAI,KAAK,aAAaR,EAAQ,CAC9C,SAAUF,EAAM,SAChB,gBAAAU,EACA,sBAAuBL,GAAyBC,EAChD,sBAAuBF,GAAyBE,EAChD,MAAO,UAAA,CACR,EAEgB,OAAOG,CAAM,CAChC,CAMA,SAASF,EAAoBI,EAA8B,CACzD,MAAMC,EAAwB,CAC5B,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,MACA,KAAA,EAEIC,EAAyB,CAAC,MAAO,MAAO,MAAO,MAAO,MAAO,MAAO,KAAK,EAE/E,OAAID,EAAsB,SAASD,EAAa,YAAA,CAAa,EACpD,EAELE,EAAuB,SAASF,EAAa,YAAA,CAAa,EACrD,EAEF,CACT"}
@@ -0,0 +1,49 @@
1
+ function D(e, c = {}) {
2
+ const { locale: t = "en-US", style: i = "symbol", minimumFractionDigits: s, maximumFractionDigits: a } = c, n = u(e.currency), m = 10 ** n, o = Number(e.amount) / m;
3
+ let r;
4
+ switch (i) {
5
+ case "symbol":
6
+ r = "symbol";
7
+ break;
8
+ case "code":
9
+ r = "code";
10
+ break;
11
+ case "name":
12
+ r = "name";
13
+ break;
14
+ default:
15
+ r = "symbol";
16
+ }
17
+ return new Intl.NumberFormat(t, {
18
+ currency: e.currency,
19
+ currencyDisplay: r,
20
+ maximumFractionDigits: a ?? n,
21
+ minimumFractionDigits: s ?? n,
22
+ style: "currency"
23
+ }).format(o);
24
+ }
25
+ function u(e) {
26
+ const c = [
27
+ "BIF",
28
+ "CLP",
29
+ "DJF",
30
+ "GNF",
31
+ "JPY",
32
+ "KMF",
33
+ "KRW",
34
+ "MGA",
35
+ "PYG",
36
+ "RWF",
37
+ "UGX",
38
+ "VND",
39
+ "VUV",
40
+ "XAF",
41
+ "XOF",
42
+ "XPF"
43
+ ], t = ["BHD", "IQD", "JOD", "KWD", "LYD", "OMR", "TND"];
44
+ return c.includes(e.toUpperCase()) ? 0 : t.includes(e.toUpperCase()) ? 3 : 2;
45
+ }
46
+ export {
47
+ D as currency
48
+ };
49
+ //# sourceMappingURL=currency.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"currency.js","sources":["../../src/money/currency.ts"],"sourcesContent":["import type { Money } from './types';\n\n/**\n * Options for currency formatting.\n */\nexport type CurrencyFormatOptions = {\n locale?: string; // BCP 47 language tag (e.g., 'en-US', 'de-DE')\n style?: 'symbol' | 'code' | 'name'; // Display style\n minimumFractionDigits?: number; // Minimum decimal places\n maximumFractionDigits?: number; // Maximum decimal places\n};\n\n/**\n * Formats a monetary amount as a currency string with proper locale and symbol.\n * Handles decimal places automatically based on currency.\n *\n * @example\n * ```ts\n * const money = { amount: 123456n, currency: 'USD' };\n *\n * currency(money); // '$1,234.56' (default en-US)\n * currency(money, { locale: 'de-DE' }); // '1.234,56 $'\n * currency(money, { style: 'code' }); // 'USD 1,234.56'\n * currency(money, { style: 'name' }); // '1,234.56 US dollars'\n * ```\n *\n * @param money - Money object to format\n * @param options - Formatting options\n * @returns Formatted currency string\n */\nexport function currency(money: Money, options: CurrencyFormatOptions = {}): string {\n const { locale = 'en-US', style = 'symbol', minimumFractionDigits, maximumFractionDigits } = options;\n\n // Get decimal places for currency (default to 2 for most currencies)\n const decimalPlaces = getCurrencyDecimals(money.currency);\n\n // Convert bigint amount to decimal (divide by 10^decimalPlaces)\n const divisor = 10 ** decimalPlaces;\n const amount = Number(money.amount) / divisor;\n\n // Determine Intl.NumberFormat style\n let currencyDisplay: 'symbol' | 'code' | 'name';\n switch (style) {\n case 'symbol':\n currencyDisplay = 'symbol';\n break;\n case 'code':\n currencyDisplay = 'code';\n break;\n case 'name':\n currencyDisplay = 'name';\n break;\n default:\n currencyDisplay = 'symbol';\n }\n\n const formatter = new Intl.NumberFormat(locale, {\n currency: money.currency,\n currencyDisplay,\n maximumFractionDigits: maximumFractionDigits ?? decimalPlaces,\n minimumFractionDigits: minimumFractionDigits ?? decimalPlaces,\n style: 'currency',\n });\n\n return formatter.format(amount);\n}\n\n/**\n * Gets the number of decimal places for a currency.\n * Most currencies use 2 decimal places, but some use 0 or 3.\n */\nfunction getCurrencyDecimals(currencyCode: string): number {\n const zeroDecimalCurrencies = [\n 'BIF',\n 'CLP',\n 'DJF',\n 'GNF',\n 'JPY',\n 'KMF',\n 'KRW',\n 'MGA',\n 'PYG',\n 'RWF',\n 'UGX',\n 'VND',\n 'VUV',\n 'XAF',\n 'XOF',\n 'XPF',\n ];\n const threeDecimalCurrencies = ['BHD', 'IQD', 'JOD', 'KWD', 'LYD', 'OMR', 'TND'];\n\n if (zeroDecimalCurrencies.includes(currencyCode.toUpperCase())) {\n return 0;\n }\n if (threeDecimalCurrencies.includes(currencyCode.toUpperCase())) {\n return 3;\n }\n return 2; // Default for most currencies\n}\n"],"names":["currency","money","options","locale","style","minimumFractionDigits","maximumFractionDigits","decimalPlaces","getCurrencyDecimals","divisor","amount","currencyDisplay","currencyCode","zeroDecimalCurrencies","threeDecimalCurrencies"],"mappings":"AA8BO,SAASA,EAASC,GAAcC,IAAiC,IAAY;AAClF,QAAM,EAAE,QAAAC,IAAS,SAAS,OAAAC,IAAQ,UAAU,uBAAAC,GAAuB,uBAAAC,MAA0BJ,GAGvFK,IAAgBC,EAAoBP,EAAM,QAAQ,GAGlDQ,IAAU,MAAMF,GAChBG,IAAS,OAAOT,EAAM,MAAM,IAAIQ;AAGtC,MAAIE;AACJ,UAAQP,GAAA;AAAA,IACN,KAAK;AACH,MAAAO,IAAkB;AAClB;AAAA,IACF,KAAK;AACH,MAAAA,IAAkB;AAClB;AAAA,IACF,KAAK;AACH,MAAAA,IAAkB;AAClB;AAAA,IACF;AACE,MAAAA,IAAkB;AAAA,EAAA;AAWtB,SARkB,IAAI,KAAK,aAAaR,GAAQ;AAAA,IAC9C,UAAUF,EAAM;AAAA,IAChB,iBAAAU;AAAA,IACA,uBAAuBL,KAAyBC;AAAA,IAChD,uBAAuBF,KAAyBE;AAAA,IAChD,OAAO;AAAA,EAAA,CACR,EAEgB,OAAOG,CAAM;AAChC;AAMA,SAASF,EAAoBI,GAA8B;AACzD,QAAMC,IAAwB;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA,GAEIC,IAAyB,CAAC,OAAO,OAAO,OAAO,OAAO,OAAO,OAAO,KAAK;AAE/E,SAAID,EAAsB,SAASD,EAAa,YAAA,CAAa,IACpD,IAELE,EAAuB,SAASF,EAAa,YAAA,CAAa,IACrD,IAEF;AACT;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(e,t){if(e.currency!==t.from)throw new Error(`Currency mismatch: expected ${t.from}, got ${e.currency}`);const n=BigInt(Math.round(t.rate*1e6));return{amount:e.amount*n/1000000n,currency:t.to}}exports.exchange=r;
2
+ //# sourceMappingURL=exchange.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.cjs","sources":["../../src/money/exchange.ts"],"sourcesContent":["import type { Money } from './types';\n\n/**\n * Exchange rate for currency conversion.\n */\nexport type ExchangeRate = {\n from: string; // Source currency code\n to: string; // Target currency code\n rate: number; // Exchange rate multiplier\n};\n\n/**\n * Converts money from one currency to another using the provided exchange rate.\n * Maintains precision by using bigint arithmetic.\n *\n * @example\n * ```ts\n * const usd = { amount: 100000n, currency: 'USD' }; // $1,000.00\n * const rate = { from: 'USD', to: 'EUR', rate: 0.85 };\n *\n * exchange(usd, rate);\n * // { amount: 85000n, currency: 'EUR' } // €850.00\n * ```\n *\n * @param money - Money to convert\n * @param rate - Exchange rate information\n * @returns Converted money in target currency\n * @throws {Error} If source currency doesn't match rate.from\n */\nexport function exchange(money: Money, rate: ExchangeRate): Money {\n if (money.currency !== rate.from) {\n throw new Error(`Currency mismatch: expected ${rate.from}, got ${money.currency}`);\n }\n\n // Convert rate to avoid floating point issues\n // Multiply by 1000000 for precision, then divide back\n const rateBigInt = BigInt(Math.round(rate.rate * 1000000));\n const convertedAmount = (money.amount * rateBigInt) / 1000000n;\n\n return {\n amount: convertedAmount,\n currency: rate.to,\n };\n}\n"],"names":["exchange","money","rate","rateBigInt"],"mappings":"gFA6BO,SAASA,EAASC,EAAcC,EAA2B,CAChE,GAAID,EAAM,WAAaC,EAAK,KAC1B,MAAM,IAAI,MAAM,+BAA+BA,EAAK,IAAI,SAASD,EAAM,QAAQ,EAAE,EAKnF,MAAME,EAAa,OAAO,KAAK,MAAMD,EAAK,KAAO,GAAO,CAAC,EAGzD,MAAO,CACL,OAHuBD,EAAM,OAASE,EAAc,SAIpD,SAAUD,EAAK,EAAA,CAEnB"}
@@ -0,0 +1,13 @@
1
+ function o(r, n) {
2
+ if (r.currency !== n.from)
3
+ throw new Error(`Currency mismatch: expected ${n.from}, got ${r.currency}`);
4
+ const t = BigInt(Math.round(n.rate * 1e6));
5
+ return {
6
+ amount: r.amount * t / 1000000n,
7
+ currency: n.to
8
+ };
9
+ }
10
+ export {
11
+ o as exchange
12
+ };
13
+ //# sourceMappingURL=exchange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exchange.js","sources":["../../src/money/exchange.ts"],"sourcesContent":["import type { Money } from './types';\n\n/**\n * Exchange rate for currency conversion.\n */\nexport type ExchangeRate = {\n from: string; // Source currency code\n to: string; // Target currency code\n rate: number; // Exchange rate multiplier\n};\n\n/**\n * Converts money from one currency to another using the provided exchange rate.\n * Maintains precision by using bigint arithmetic.\n *\n * @example\n * ```ts\n * const usd = { amount: 100000n, currency: 'USD' }; // $1,000.00\n * const rate = { from: 'USD', to: 'EUR', rate: 0.85 };\n *\n * exchange(usd, rate);\n * // { amount: 85000n, currency: 'EUR' } // €850.00\n * ```\n *\n * @param money - Money to convert\n * @param rate - Exchange rate information\n * @returns Converted money in target currency\n * @throws {Error} If source currency doesn't match rate.from\n */\nexport function exchange(money: Money, rate: ExchangeRate): Money {\n if (money.currency !== rate.from) {\n throw new Error(`Currency mismatch: expected ${rate.from}, got ${money.currency}`);\n }\n\n // Convert rate to avoid floating point issues\n // Multiply by 1000000 for precision, then divide back\n const rateBigInt = BigInt(Math.round(rate.rate * 1000000));\n const convertedAmount = (money.amount * rateBigInt) / 1000000n;\n\n return {\n amount: convertedAmount,\n currency: rate.to,\n };\n}\n"],"names":["exchange","money","rate","rateBigInt"],"mappings":"AA6BO,SAASA,EAASC,GAAcC,GAA2B;AAChE,MAAID,EAAM,aAAaC,EAAK;AAC1B,UAAM,IAAI,MAAM,+BAA+BA,EAAK,IAAI,SAASD,EAAM,QAAQ,EAAE;AAKnF,QAAME,IAAa,OAAO,KAAK,MAAMD,EAAK,OAAO,GAAO,CAAC;AAGzD,SAAO;AAAA,IACL,QAHuBD,EAAM,SAASE,IAAc;AAAA,IAIpD,UAAUD,EAAK;AAAA,EAAA;AAEnB;"}
@@ -1 +1 @@
1
- {"version":3,"file":"merge.cjs","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":"2JAoDO,SAASA,EAAuBC,EAA0B,UAAWC,EAAyB,CACnG,OAAIA,EAAM,SAAW,EAAU,CAAA,EAE3BD,IAAa,UACR,OAAO,OAAO,CAAA,EAAI,GAAGC,CAAK,EAG5BA,EAAM,OAAO,CAACC,EAAKC,IAAQC,EAAUF,EAAKC,EAAKH,CAAQ,EAA0B,EAAc,CACxG,CAcA,SAASI,EAAwCC,EAAWC,EAAWN,EAA0C,CAC/G,GAAI,CAACO,EAAAA,SAASD,CAAM,EAAG,OAAOA,EAE9B,MAAME,EAAS,CAAE,GAAGH,CAAA,EAEpB,UAAWI,KAAOH,EAAQ,CACxB,GAAI,CAAC,OAAO,OAAOA,EAAQG,CAAG,EAAG,SAEjC,MAAMC,EAAcJ,EAAOG,CAAG,EACxBE,EAAcH,EAAOC,CAAG,EAG7BD,EAAeC,CAAG,EACjBG,EAAAA,QAAQF,CAAW,GAAKE,EAAAA,QAAQD,CAAW,EACvCE,EAAiBF,EAAaD,EAAaV,CAAQ,EACnDO,EAAAA,SAASG,CAAW,GAAKH,EAAAA,SAASI,CAAW,EAC3CP,EAAUO,EAAaD,EAAaV,CAAQ,EAC5Cc,EAAmBH,EAAaD,EAAaV,CAAQ,CAC/D,CAEA,OAAOQ,CACT,CASA,SAASK,EAAuBE,EAA8BC,EAAkBhB,EAAoC,CAClH,OAAKe,EAEDf,IAAa,cAAsBe,EAAY,OAAOC,CAAkB,EACxEhB,IAAa,eAAuBgB,EACjC,MAAM,KAAK,IAAI,IAAI,CAAC,GAAGD,EAAa,GAAGC,CAAW,CAAC,CAAC,EAJlCA,CAK3B,CAQA,SAASF,EAAyBT,EAAWC,EAAWN,EAAgC,CACtF,OAAI,OAAOA,GAAa,WAAmBA,EAASK,EAAQC,CAAM,EAC3DN,IAAa,YAAcM,IAAW,OAAYA,EAASD,CACpE"}
1
+ {"version":3,"file":"merge.cjs","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\n// #region MergeStrategy\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n// #endregion MergeStrategy\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":"2JAsDO,SAASA,EAAuBC,EAA0B,UAAWC,EAAyB,CACnG,OAAIA,EAAM,SAAW,EAAU,CAAA,EAE3BD,IAAa,UACR,OAAO,OAAO,CAAA,EAAI,GAAGC,CAAK,EAG5BA,EAAM,OAAO,CAACC,EAAKC,IAAQC,EAAUF,EAAKC,EAAKH,CAAQ,EAA0B,EAAc,CACxG,CAcA,SAASI,EAAwCC,EAAWC,EAAWN,EAA0C,CAC/G,GAAI,CAACO,EAAAA,SAASD,CAAM,EAAG,OAAOA,EAE9B,MAAME,EAAS,CAAE,GAAGH,CAAA,EAEpB,UAAWI,KAAOH,EAAQ,CACxB,GAAI,CAAC,OAAO,OAAOA,EAAQG,CAAG,EAAG,SAEjC,MAAMC,EAAcJ,EAAOG,CAAG,EACxBE,EAAcH,EAAOC,CAAG,EAG7BD,EAAeC,CAAG,EACjBG,EAAAA,QAAQF,CAAW,GAAKE,EAAAA,QAAQD,CAAW,EACvCE,EAAiBF,EAAaD,EAAaV,CAAQ,EACnDO,EAAAA,SAASG,CAAW,GAAKH,EAAAA,SAASI,CAAW,EAC3CP,EAAUO,EAAaD,EAAaV,CAAQ,EAC5Cc,EAAmBH,EAAaD,EAAaV,CAAQ,CAC/D,CAEA,OAAOQ,CACT,CASA,SAASK,EAAuBE,EAA8BC,EAAkBhB,EAAoC,CAClH,OAAKe,EAEDf,IAAa,cAAsBe,EAAY,OAAOC,CAAkB,EACxEhB,IAAa,eAAuBgB,EACjC,MAAM,KAAK,IAAI,IAAI,CAAC,GAAGD,EAAa,GAAGC,CAAW,CAAC,CAAC,EAJlCA,CAK3B,CAQA,SAASF,EAAyBT,EAAWC,EAAWN,EAAgC,CACtF,OAAI,OAAOA,GAAa,WAAmBA,EAASK,EAAQC,CAAM,EAC3DN,IAAa,YAAcM,IAAW,OAAYA,EAASD,CACpE"}
@@ -1 +1 @@
1
- {"version":3,"file":"merge.js","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":";;AAoDO,SAASA,EAAuBC,IAA0B,WAAWC,GAAyB;AACnG,SAAIA,EAAM,WAAW,IAAU,CAAA,IAE3BD,MAAa,YACR,OAAO,OAAO,CAAA,GAAI,GAAGC,CAAK,IAG5BA,EAAM,OAAO,CAACC,GAAKC,MAAQC,EAAUF,GAAKC,GAAKH,CAAQ,GAA0B,EAAc;AACxG;AAcA,SAASI,EAAwCC,GAAWC,GAAWN,GAA0C;AAC/G,MAAI,CAACO,EAASD,CAAM,EAAG,QAAOA;AAE9B,QAAME,IAAS,EAAE,GAAGH,EAAA;AAEpB,aAAWI,KAAOH,GAAQ;AACxB,QAAI,CAAC,OAAO,OAAOA,GAAQG,CAAG,EAAG;AAEjC,UAAMC,IAAcJ,EAAOG,CAAG,GACxBE,IAAcH,EAAOC,CAAG;AAG7B,IAAAD,EAAeC,CAAG,IACjBG,EAAQF,CAAW,KAAKE,EAAQD,CAAW,IACvCE,EAAiBF,GAAaD,GAAaV,CAAQ,IACnDO,EAASG,CAAW,KAAKH,EAASI,CAAW,IAC3CP,EAAUO,GAAaD,GAAaV,CAAQ,IAC5Cc,EAAmBH,GAAaD,GAAaV,CAAQ;AAAA,EAC/D;AAEA,SAAOQ;AACT;AASA,SAASK,EAAuBE,GAA8BC,GAAkBhB,GAAoC;AAClH,SAAKe,IAEDf,MAAa,gBAAsBe,EAAY,OAAOC,CAAkB,IACxEhB,MAAa,iBAAuBgB,IACjC,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAGD,GAAa,GAAGC,CAAW,CAAC,CAAC,IAJlCA;AAK3B;AAQA,SAASF,EAAyBT,GAAWC,GAAWN,GAAgC;AACtF,SAAI,OAAOA,KAAa,aAAmBA,EAASK,GAAQC,CAAM,IAC3DN,MAAa,cAAcM,MAAW,SAAYA,IAASD;AACpE;"}
1
+ {"version":3,"file":"merge.js","sources":["../../src/object/merge.ts"],"sourcesContent":["import { isArray } from '../typed/isArray';\nimport { isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\n// #region MergeStrategy\ntype MergeStrategy =\n | 'deep'\n | 'shallow'\n | 'lastWins'\n | 'arrayConcat'\n | 'arrayReplace'\n // biome-ignore lint/suspicious/noExplicitAny: -\n | ((target: any, source: any) => any);\n// #endregion MergeStrategy\n\ntype DeepMerge<T, U> = T extends Obj\n ? U extends Obj\n ? {\n [K in keyof T | keyof U]: K extends keyof T\n ? K extends keyof U\n ? DeepMerge<T[K], U[K]>\n : T[K]\n : K extends keyof U\n ? U[K]\n : never;\n }\n : U\n : U;\n\ntype Merge<T extends Obj[]> = T extends [infer First, ...infer Rest]\n ? First extends Obj\n ? Rest extends Obj[]\n ? DeepMerge<First, Merge<Rest>>\n : First\n : Obj\n : Obj;\n\n/**\n * Merges multiple objects based on a specified merge strategy.\n *\n * @example\n * ```ts\n * const obj1 = { a: 1, b: { x: 10, y: \"hello\" }, c: [1] };\n * const obj2 = { b: { y: 20, z: true }, c: [2] };\n * const obj3 = { d: false, c: [3] };\n *\n * merge(\"deep\", obj1, obj2, obj3); // { a: 1, b: { x: 10, y: 20, z: true }, c: [1, 2, 3], d: false }\n * merge(\"shallow\", obj1, obj2, obj3); // { a: 1, b: { y: 20, z: true }, c: [3], d: false }\n * ```\n *\n * @param [strategy='deep'] - The merging strategy to use.\n * @param items - The objects to merge.\n * @returns A new merged object.\n */\nexport function merge<T extends Obj[]>(strategy: MergeStrategy = 'deep', ...items: [...T]): Merge<T> {\n if (items.length === 0) return {} as Merge<T>;\n\n if (strategy === 'shallow') {\n return Object.assign({}, ...items) as Merge<T>;\n }\n\n return items.reduce((acc, obj) => deepMerge(acc, obj, strategy) as unknown as Merge<T>, {} as Merge<T>);\n}\n\n/**\n * Deeply merges two objects based on the provided strategy.\n *\n * - Uses **direct property access** for performance.\n * - **Avoids redundant deep merging** where unnecessary.\n * - Optimized **array merging strategies**.\n *\n * @param target - The target object.\n * @param source - The source object.\n * @param strategy - The merge strategy.\n * @returns A new merged object.\n */\nfunction deepMerge<T extends Obj, U extends Obj>(target: T, source: U, strategy: MergeStrategy): DeepMerge<T, U> {\n if (!isObject(source)) return source as DeepMerge<T, U>;\n\n const result = { ...target } as DeepMerge<T, U>;\n\n for (const key in source) {\n if (!Object.hasOwn(source, key)) continue; // Prevent prototype pollution\n\n const sourceValue = source[key];\n const targetValue = result[key];\n\n // biome-ignore lint/suspicious/noExplicitAny: -\n (result as any)[key] =\n isArray(sourceValue) && isArray(targetValue)\n ? handleArrayMerge(targetValue, sourceValue, strategy)\n : isObject(sourceValue) && isObject(targetValue)\n ? deepMerge(targetValue, sourceValue, strategy)\n : applyMergeStrategy(targetValue, sourceValue, strategy);\n }\n\n return result;\n}\n\n/**\n * Optimized array merge based on strategy.\n *\n * - `\"arrayConcat\"` → Concatenates arrays.\n * - `\"arrayReplace\"` → Replaces the existing array.\n * - Default: **Unique merge** (Set-based optimization).\n */\nfunction handleArrayMerge<T, U>(targetArray: T[] | undefined, sourceArray: U[], strategy: MergeStrategy): (T | U)[] {\n if (!targetArray) return sourceArray;\n // biome-ignore lint/suspicious/noExplicitAny: -\n if (strategy === 'arrayConcat') return targetArray.concat(sourceArray as any);\n if (strategy === 'arrayReplace') return sourceArray;\n return Array.from(new Set([...targetArray, ...sourceArray])); // Unique merge\n}\n\n/**\n * Determines the appropriate value to assign based on the merge strategy.\n *\n * - `\"lastWins\"` → Overwrites with the latest value.\n * - Custom functions → Allows user-defined behavior.\n */\nfunction applyMergeStrategy<T, U>(target: T, source: U, strategy: MergeStrategy): T | U {\n if (typeof strategy === 'function') return strategy(target, source);\n return strategy === 'lastWins' || source !== undefined ? source : target;\n}\n"],"names":["merge","strategy","items","acc","obj","deepMerge","target","source","isObject","result","key","sourceValue","targetValue","isArray","handleArrayMerge","applyMergeStrategy","targetArray","sourceArray"],"mappings":";;AAsDO,SAASA,EAAuBC,IAA0B,WAAWC,GAAyB;AACnG,SAAIA,EAAM,WAAW,IAAU,CAAA,IAE3BD,MAAa,YACR,OAAO,OAAO,CAAA,GAAI,GAAGC,CAAK,IAG5BA,EAAM,OAAO,CAACC,GAAKC,MAAQC,EAAUF,GAAKC,GAAKH,CAAQ,GAA0B,EAAc;AACxG;AAcA,SAASI,EAAwCC,GAAWC,GAAWN,GAA0C;AAC/G,MAAI,CAACO,EAASD,CAAM,EAAG,QAAOA;AAE9B,QAAME,IAAS,EAAE,GAAGH,EAAA;AAEpB,aAAWI,KAAOH,GAAQ;AACxB,QAAI,CAAC,OAAO,OAAOA,GAAQG,CAAG,EAAG;AAEjC,UAAMC,IAAcJ,EAAOG,CAAG,GACxBE,IAAcH,EAAOC,CAAG;AAG7B,IAAAD,EAAeC,CAAG,IACjBG,EAAQF,CAAW,KAAKE,EAAQD,CAAW,IACvCE,EAAiBF,GAAaD,GAAaV,CAAQ,IACnDO,EAASG,CAAW,KAAKH,EAASI,CAAW,IAC3CP,EAAUO,GAAaD,GAAaV,CAAQ,IAC5Cc,EAAmBH,GAAaD,GAAaV,CAAQ;AAAA,EAC/D;AAEA,SAAOQ;AACT;AASA,SAASK,EAAuBE,GAA8BC,GAAkBhB,GAAoC;AAClH,SAAKe,IAEDf,MAAa,gBAAsBe,EAAY,OAAOC,CAAkB,IACxEhB,MAAa,iBAAuBgB,IACjC,MAAM,KAAK,oBAAI,IAAI,CAAC,GAAGD,GAAa,GAAGC,CAAW,CAAC,CAAC,IAJlCA;AAK3B;AAQA,SAASF,EAAyBT,GAAWC,GAAWN,GAAgC;AACtF,SAAI,OAAOA,KAAa,aAAmBA,EAASK,GAAQC,CAAM,IAC3DN,MAAa,cAAcM,MAAW,SAAYA,IAASD;AACpE;"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseJSON.cjs","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\ninterface ParseJSONOptions<T> {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n}\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":"8LAoCO,SAASA,EAA+BC,EAAeC,EAA+B,GAAmB,CAC9G,KAAM,CAAE,aAAAC,EAAc,QAAAC,EAAS,UAAAC,EAAW,OAAAC,EAAS,IAAUJ,EAE7D,GAAI,CAACK,EAAAA,SAASN,CAAI,SAAUO,EAAAA,MAAMP,CAAI,EAAIE,EAAgBF,EAE1D,GAAI,CACF,MAAMQ,EAAS,KAAK,MAAMR,EAAgBG,CAAO,EAEjD,GAAIC,GAAa,CAACA,EAAUI,CAAM,EAChC,MAAM,IAAI,UAAU,mDAAmD,EAGzE,OAAOA,GAAUN,CACnB,OAASO,EAAK,CACZ,OAAKJ,GACHK,QAAM,MAAM,wCAAyCD,CAAG,EAGnDP,CACT,CACF"}
1
+ {"version":3,"file":"parseJSON.cjs","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\n// #region ParseJSONOptions\ntype ParseJSONOptions<T> = {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n};\n// #endregion ParseJSONOptions\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":"8LAsCO,SAASA,EAA+BC,EAAeC,EAA+B,GAAmB,CAC9G,KAAM,CAAE,aAAAC,EAAc,QAAAC,EAAS,UAAAC,EAAW,OAAAC,EAAS,IAAUJ,EAE7D,GAAI,CAACK,EAAAA,SAASN,CAAI,SAAUO,EAAAA,MAAMP,CAAI,EAAIE,EAAgBF,EAE1D,GAAI,CACF,MAAMQ,EAAS,KAAK,MAAMR,EAAgBG,CAAO,EAEjD,GAAIC,GAAa,CAACA,EAAUI,CAAM,EAChC,MAAM,IAAI,UAAU,mDAAmD,EAGzE,OAAOA,GAAUN,CACnB,OAASO,EAAK,CACZ,OAAKJ,GACHK,QAAM,MAAM,wCAAyCD,CAAG,EAGnDP,CACT,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"parseJSON.js","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\ninterface ParseJSONOptions<T> {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n}\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":";;;AAoCO,SAASA,EAA+BC,GAAeC,IAA+B,IAAmB;AAC9G,QAAM,EAAE,cAAAC,GAAc,SAAAC,GAAS,WAAAC,GAAW,QAAAC,IAAS,OAAUJ;AAE7D,MAAI,CAACK,EAASN,CAAI,UAAUO,EAAMP,CAAI,IAAIE,IAAgBF;AAE1D,MAAI;AACF,UAAMQ,IAAS,KAAK,MAAMR,GAAgBG,CAAO;AAEjD,QAAIC,KAAa,CAACA,EAAUI,CAAM;AAChC,YAAM,IAAI,UAAU,mDAAmD;AAGzE,WAAOA,KAAUN;AAAA,EACnB,SAASO,GAAK;AACZ,WAAKJ,KACHK,EAAM,MAAM,yCAAyCD,CAAG,GAGnDP;AAAA,EACT;AACF;"}
1
+ {"version":3,"file":"parseJSON.js","sources":["../../src/object/parseJSON.ts"],"sourcesContent":["import { Logit } from '@vielzeug/logit';\nimport { isNil } from '../typed/isNil';\nimport { isString } from '../typed/isString';\n\ntype JSONValue = string | number | boolean | null | JSONValue[] | { [key: string]: JSONValue };\n\n// #region ParseJSONOptions\ntype ParseJSONOptions<T> = {\n defaultValue?: T;\n // biome-ignore lint/suspicious/noExplicitAny: -\n reviver?: (key: string, value: any) => any;\n // biome-ignore lint/suspicious/noExplicitAny: -\n validator?: (value: any) => boolean;\n silent?: boolean;\n};\n// #endregion ParseJSONOptions\n\n/**\n * Parses a JSON string and returns the resulting object.\n *\n * @example\n * ```ts\n * const json = '{\"a\":1,\"b\":2,\"c\":3}';\n * const result = parseJSON<Record<string, number>>(json, {\n * defaultValue: { a: 0, b: 0, c: 0 },\n * validator: (value) => Object.values(value).every(v => typeof v === 'number'),\n * errorHandler: (err) => console.warn('Parsing failed:', err.message),\n * silent: true\n * });\n * console.log(result); // { a: 1, b: 2, c: 3 }\n * ```\n *\n * @template T - The expected type of the parsed JSON.\n * @param json - The JSON string to parse. If not a string, it is returned as is.\n * @param options - Configuration options for parsing.\n *\n * @returns The parsed object if successful, otherwise the default value.\n */\nexport function parseJSON<T extends JSONValue>(json: unknown, options: ParseJSONOptions<T> = {}): T | undefined {\n const { defaultValue, reviver, validator, silent = false } = options;\n\n if (!isString(json)) return isNil(json) ? defaultValue : (json as T);\n\n try {\n const parsed = JSON.parse(json as string, reviver);\n\n if (validator && !validator(parsed)) {\n throw new TypeError('Parsed JSON does not match the expected structure');\n }\n\n return parsed ?? defaultValue;\n } catch (err) {\n if (!silent) {\n Logit.error('parseJSON() -> failed to parse object', err);\n }\n\n return defaultValue;\n }\n}\n"],"names":["parseJSON","json","options","defaultValue","reviver","validator","silent","isString","isNil","parsed","err","Logit"],"mappings":";;;AAsCO,SAASA,EAA+BC,GAAeC,IAA+B,IAAmB;AAC9G,QAAM,EAAE,cAAAC,GAAc,SAAAC,GAAS,WAAAC,GAAW,QAAAC,IAAS,OAAUJ;AAE7D,MAAI,CAACK,EAASN,CAAI,UAAUO,EAAMP,CAAI,IAAIE,IAAgBF;AAE1D,MAAI;AACF,UAAMQ,IAAS,KAAK,MAAMR,GAAgBG,CAAO;AAEjD,QAAIC,KAAa,CAACA,EAAUI,CAAM;AAChC,YAAM,IAAI,UAAU,mDAAmD;AAGzE,WAAOA,KAAUN;AAAA,EACnB,SAASO,GAAK;AACZ,WAAKJ,KACHK,EAAM,MAAM,yCAAyCD,CAAG,GAGnDP;AAAA,EACT;AACF;"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.cjs","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":"+NA2CO,SAASA,EACdC,EACAD,EACAE,EACAC,EAAuB,CAAA,EACM,CAC7BC,EAAAA,OAAOC,EAAAA,SAASJ,CAAI,EAAGK,sBAAqB,CAAE,KAAM,CAAE,KAAAL,CAAA,EAAQ,KAAM,UAAW,EAE/E,KAAM,CAAE,eAAAM,EAAiB,GAAO,gBAAAC,EAAkB,IAAUL,EAEtDM,EAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO,EAEtD,IAAIU,EAAeT,EAEnB,UAAWU,KAAYF,EAAW,CAChC,GAAIG,EAAAA,MAAMF,CAAO,GAAK,OAAOA,GAAY,SACvC,OAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,GAAIH,EAAgBL,CAAY,EAMrG,GAHAQ,EACEF,GAAmBM,EAAAA,QAAQJ,CAAO,GAAK,QAAQ,KAAKC,CAAQ,EAAID,EAAQ,OAAOC,CAAQ,CAAC,EAAID,EAAQC,CAAQ,EAE1GD,IAAY,OACd,OAAOG,EAAY,aAAaF,CAAQ,mBAAoBJ,EAAgBL,CAAY,CAE5F,CAEA,OAAOQ,CACT,CAEA,SAASG,EACPE,EACAR,EACAL,EAC6B,CAC7B,GAAIK,EAAgB,MAAM,IAAI,MAAMQ,CAAO,EAC3C,OAAOb,CACT"}
1
+ {"version":3,"file":"path.cjs","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\n// #region PathOptions\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n// #endregion PathOptions\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":"+NA6CO,SAASA,EACdC,EACAD,EACAE,EACAC,EAAuB,CAAA,EACM,CAC7BC,EAAAA,OAAOC,EAAAA,SAASJ,CAAI,EAAGK,sBAAqB,CAAE,KAAM,CAAE,KAAAL,CAAA,EAAQ,KAAM,UAAW,EAE/E,KAAM,CAAE,eAAAM,EAAiB,GAAO,gBAAAC,EAAkB,IAAUL,EAEtDM,EAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO,EAEtD,IAAIU,EAAeT,EAEnB,UAAWU,KAAYF,EAAW,CAChC,GAAIG,EAAAA,MAAMF,CAAO,GAAK,OAAOA,GAAY,SACvC,OAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,GAAIH,EAAgBL,CAAY,EAMrG,GAHAQ,EACEF,GAAmBM,EAAAA,QAAQJ,CAAO,GAAK,QAAQ,KAAKC,CAAQ,EAAID,EAAQ,OAAOC,CAAQ,CAAC,EAAID,EAAQC,CAAQ,EAE1GD,IAAY,OACd,OAAOG,EAAY,aAAaF,CAAQ,mBAAoBJ,EAAgBL,CAAY,CAE5F,CAEA,OAAOQ,CACT,CAEA,SAASG,EACPE,EACAR,EACAL,EAC6B,CAC7B,GAAIK,EAAgB,MAAM,IAAI,MAAMQ,CAAO,EAC3C,OAAOb,CACT"}
@@ -1 +1 @@
1
- {"version":3,"file":"path.js","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":";;;;AA2CO,SAASA,EACdC,GACAD,GACAE,GACAC,IAAuB,CAAA,GACM;AAC7B,EAAAC,EAAOC,EAASJ,CAAI,GAAGK,GAAqB,EAAE,MAAM,EAAE,MAAAL,EAAA,GAAQ,MAAM,WAAW;AAE/E,QAAM,EAAE,gBAAAM,IAAiB,IAAO,iBAAAC,IAAkB,OAAUL,GAEtDM,IAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO;AAEtD,MAAIU,IAAeT;AAEnB,aAAWU,KAAYF,GAAW;AAChC,QAAIG,EAAMF,CAAO,KAAK,OAAOA,KAAY;AACvC,aAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,IAAIH,GAAgBL,CAAY;AAMrG,QAHAQ,IACEF,KAAmBM,EAAQJ,CAAO,KAAK,QAAQ,KAAKC,CAAQ,IAAID,EAAQ,OAAOC,CAAQ,CAAC,IAAID,EAAQC,CAAQ,GAE1GD,MAAY;AACd,aAAOG,EAAY,aAAaF,CAAQ,oBAAoBJ,GAAgBL,CAAY;AAAA,EAE5F;AAEA,SAAOQ;AACT;AAEA,SAASG,EACPE,GACAR,GACAL,GAC6B;AAC7B,MAAIK,EAAgB,OAAM,IAAI,MAAMQ,CAAO;AAC3C,SAAOb;AACT;"}
1
+ {"version":3,"file":"path.js","sources":["../../src/object/path.ts"],"sourcesContent":["import { assert } from '../function/assert';\nimport { isArray } from '../typed/isArray';\nimport { isNil } from '../typed/isNil';\nimport { IS_OBJECT_ERROR_MSG, isObject } from '../typed/isObject';\nimport type { Obj } from '../types';\n\ntype PathValue<T, P extends string> = P extends `${infer Key}.${infer Rest}`\n ? Key extends keyof T\n ? PathValue<T[Key], Rest>\n : undefined\n : P extends keyof T\n ? T[P]\n : undefined;\n\n// #region PathOptions\ntype PathOptions = {\n throwOnMissing?: boolean;\n allowArrayIndex?: boolean;\n};\n// #endregion PathOptions\n\n/**\n * Retrieves the value at a given path of the object. If the value is undefined, the default value is returned.\n *\n * @example\n * ```ts\n * const obj = { a: { b: { c: 3 } }, d: [1, 2, 3] };\n *\n * getValue(obj, 'a.b.c'); // 3\n * getValue(obj, 'a.b.d', 'default'); // 'default'\n * getValue(obj, 'd[1]', undefined, { allowArrayIndex: true }); // 2\n * getValue(obj, 'e.f.g', 'default', { throwOnMissing: true }); // throws Error\n * ```\n *\n * @template T - The type of the object to query.\n * @template P - The type of the path string.\n * @param item - The object to query.\n * @param path - The path of the property to get.\n * @param [defaultValue] - The value returned for undefined resolved values.\n * @param [options] - Additional options for value retrieval.\n *\n * @returns The resolved value.\n *\n * @throws If throwOnMissing is true and the path doesn't exist.\n */\nexport function path<T extends Obj, P extends string>(\n item: T,\n path: P,\n defaultValue?: unknown,\n options: PathOptions = {},\n): PathValue<T, P> | undefined {\n assert(isObject(item), IS_OBJECT_ERROR_MSG, { args: { item }, type: TypeError });\n\n const { throwOnMissing = false, allowArrayIndex = false } = options;\n\n const fragments = path.split(/[.[\\]]+/).filter(Boolean);\n // biome-ignore lint/suspicious/noExplicitAny: -\n let current: any = item;\n\n for (const fragment of fragments) {\n if (isNil(current) || typeof current !== 'object') {\n return handleError(`Cannot read property '${fragment}' of ${current}`, throwOnMissing, defaultValue);\n }\n\n current =\n allowArrayIndex && isArray(current) && /^\\d+$/.test(fragment) ? current[Number(fragment)] : current[fragment];\n\n if (current === undefined) {\n return handleError(`Property '${fragment}' does not exist`, throwOnMissing, defaultValue);\n }\n }\n\n return current as PathValue<T, P>;\n}\n\nfunction handleError<T extends Obj, P extends string>(\n message: string,\n throwOnMissing: boolean,\n defaultValue?: unknown,\n): PathValue<T, P> | undefined {\n if (throwOnMissing) throw new Error(message);\n return defaultValue as PathValue<T, P>;\n}\n"],"names":["path","item","defaultValue","options","assert","isObject","IS_OBJECT_ERROR_MSG","throwOnMissing","allowArrayIndex","fragments","current","fragment","isNil","handleError","isArray","message"],"mappings":";;;;AA6CO,SAASA,EACdC,GACAD,GACAE,GACAC,IAAuB,CAAA,GACM;AAC7B,EAAAC,EAAOC,EAASJ,CAAI,GAAGK,GAAqB,EAAE,MAAM,EAAE,MAAAL,EAAA,GAAQ,MAAM,WAAW;AAE/E,QAAM,EAAE,gBAAAM,IAAiB,IAAO,iBAAAC,IAAkB,OAAUL,GAEtDM,IAAYT,EAAK,MAAM,SAAS,EAAE,OAAO,OAAO;AAEtD,MAAIU,IAAeT;AAEnB,aAAWU,KAAYF,GAAW;AAChC,QAAIG,EAAMF,CAAO,KAAK,OAAOA,KAAY;AACvC,aAAOG,EAAY,yBAAyBF,CAAQ,QAAQD,CAAO,IAAIH,GAAgBL,CAAY;AAMrG,QAHAQ,IACEF,KAAmBM,EAAQJ,CAAO,KAAK,QAAQ,KAAKC,CAAQ,IAAID,EAAQ,OAAOC,CAAQ,CAAC,IAAID,EAAQC,CAAQ,GAE1GD,MAAY;AACd,aAAOG,EAAY,aAAaF,CAAQ,oBAAoBJ,GAAgBL,CAAY;AAAA,EAE5F;AAEA,SAAOQ;AACT;AAEA,SAASG,EACPE,GACAR,GACAL,GAC6B;AAC7B,MAAIK,EAAgB,OAAM,IAAI,MAAMQ,CAAO;AAC3C,SAAOb;AACT;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vielzeug/toolkit",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -1 +0,0 @@
1
- {"version":3,"file":"sortBy.cjs","sources":["../../src/array/sortBy.ts"],"sourcesContent":["import { compareBy } from '../function/compareBy';\n\n/**\n * Sorts an array of objects based on multiple selectors.\n *\n * @example\n * ```ts\n * const data = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * { name: 'Charlie', age: 35 },\n * { name: 'Alice', age: 25 },\n * { name: 'Bob', age: 30 },\n * { name: 'Charlie', age: 30 },\n * ].sortBy(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]\n * ```\n *\n * @param array - The array to sort.\n * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.\n * @returns A new sorted array.\n */\nexport const sortBy = <T>(array: T[], selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n return [...array].sort(compareBy(selectors));\n};\n"],"names":["sortBy","array","selectors","compareBy"],"mappings":"6HAqBaA,EAAS,CAAIC,EAAYC,IAC7B,CAAC,GAAGD,CAAK,EAAE,KAAKE,EAAAA,UAAUD,CAAS,CAAC"}
@@ -1,6 +0,0 @@
1
- import { compareBy as t } from "../function/compareBy.js";
2
- const m = (r, o) => [...r].sort(t(o));
3
- export {
4
- m as sortBy
5
- };
6
- //# sourceMappingURL=sortBy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sortBy.js","sources":["../../src/array/sortBy.ts"],"sourcesContent":["import { compareBy } from '../function/compareBy';\n\n/**\n * Sorts an array of objects based on multiple selectors.\n *\n * @example\n * ```ts\n * const data = [\n * { name: 'Alice', age: 30 },\n * { name: 'Bob', age: 25 },\n * { name: 'Charlie', age: 35 },\n * { name: 'Alice', age: 25 },\n * { name: 'Bob', age: 30 },\n * { name: 'Charlie', age: 30 },\n * ].sortBy(data, { name: 'asc', age: 'desc' }); // [ { name: 'Alice', age: 30 }, { name: 'Alice', age: 25 }, { name: 'Bob', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Charlie', age: 30 } ]\n * ```\n *\n * @param array - The array to sort.\n * @param selectors - An object where keys are the properties to sort by and values are 'asc' or 'desc'.\n * @returns A new sorted array.\n */\nexport const sortBy = <T>(array: T[], selectors: Partial<Record<keyof T, 'asc' | 'desc'>>) => {\n return [...array].sort(compareBy(selectors));\n};\n"],"names":["sortBy","array","selectors","compareBy"],"mappings":";AAqBO,MAAMA,IAAS,CAAIC,GAAYC,MAC7B,CAAC,GAAGD,CAAK,EAAE,KAAKE,EAAUD,CAAS,CAAC;"}