umt 2.11.0 → 2.12.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.
Files changed (119) hide show
  1. package/module/Advance/rangeAdvance.d.ts +1 -1
  2. package/module/Advance/rangeAdvance.js.map +1 -1
  3. package/module/Array/checkFlagAlignment.js +3 -0
  4. package/module/Array/checkFlagAlignment.js.map +1 -1
  5. package/module/Array/compact.js.map +1 -1
  6. package/module/Array/getArraysCommon.js +33 -12
  7. package/module/Array/getArraysCommon.js.map +1 -1
  8. package/module/Array/groupBy.js +1 -1
  9. package/module/Array/range.js +1 -1
  10. package/module/Array/range.js.map +1 -1
  11. package/module/Array/timSort.js +1 -1
  12. package/module/Array/timSort.js.map +1 -1
  13. package/module/Array/ultraNumberSort.js +2 -2
  14. package/module/Array/ultraNumberSort.js.map +1 -1
  15. package/module/Consts/clock.d.ts +1 -1
  16. package/module/Consts/clock.js.map +1 -1
  17. package/module/DataStructure/priorityQueue.d.ts +4 -4
  18. package/module/DataStructure/priorityQueue.js +3 -2
  19. package/module/DataStructure/priorityQueue.js.map +1 -1
  20. package/module/Date/dayOfWeek.js +1 -1
  21. package/module/Date/format.js +1 -1
  22. package/module/IP/ipToBinaryString.js +1 -1
  23. package/module/IP/ipToBinaryString.js.map +1 -1
  24. package/module/IP/subnetMaskToCidr.js +1 -1
  25. package/module/IP/subnetMaskToCidr.js.map +1 -1
  26. package/module/Math/calculator/core.js +15 -5
  27. package/module/Math/calculator/core.js.map +1 -1
  28. package/module/Math/gcd.js +5 -2
  29. package/module/Math/gcd.js.map +1 -1
  30. package/module/Math/mathConverter.js +1 -1
  31. package/module/Math/mathConverter.js.map +1 -1
  32. package/module/Math/mode.js +1 -1
  33. package/module/Math/nCr.js +4 -1
  34. package/module/Math/nCr.js.map +1 -1
  35. package/module/Math/nPr.js +4 -1
  36. package/module/Math/nPr.js.map +1 -1
  37. package/module/Math/primeFactorization.js +5 -1
  38. package/module/Math/primeFactorization.js.map +1 -1
  39. package/module/Math/reduce.js +4 -1
  40. package/module/Math/reduce.js.map +1 -1
  41. package/module/Math/uuidv7.js +11 -14
  42. package/module/Math/uuidv7.js.map +1 -1
  43. package/module/Object/mergeDeep.js.map +1 -1
  44. package/module/Object/omit.js +1 -0
  45. package/module/Object/omit.js.map +1 -1
  46. package/module/Object/pickDeep.js +1 -1
  47. package/module/String/formatString/applyFormatter.js +1 -1
  48. package/module/String/formatString/applyFormatter.js.map +1 -1
  49. package/module/String/formatString/getValue.js +1 -1
  50. package/module/String/formatString/getValue.js.map +1 -1
  51. package/module/String/fromBase64.js +2 -1
  52. package/module/String/fromBase64.js.map +1 -1
  53. package/module/String/fuzzySearch.d.ts +2 -2
  54. package/module/String/fuzzySearch.js.map +1 -1
  55. package/module/String/levenshteinDistance.d.ts +2 -2
  56. package/module/String/levenshteinDistance.js +28 -18
  57. package/module/String/levenshteinDistance.js.map +1 -1
  58. package/module/String/padStart.d.ts +0 -1
  59. package/module/String/padStart.js +2 -6
  60. package/module/String/padStart.js.map +1 -1
  61. package/module/Tool/index.d.ts +1 -0
  62. package/module/Tool/index.js +1 -0
  63. package/module/Tool/index.js.map +1 -1
  64. package/module/Tool/unwrap.d.ts +9 -0
  65. package/module/Tool/unwrap.js +15 -0
  66. package/module/Tool/unwrap.js.map +1 -0
  67. package/module/Validate/array/core.js +1 -1
  68. package/module/Validate/core/index.js +2 -2
  69. package/module/Validate/isDeepEqual.js.map +1 -1
  70. package/module/Validate/object/core.js +1 -1
  71. package/module/Validate/parseEmail.d.ts +2 -2
  72. package/module/Validate/string/uuid.js +10 -11
  73. package/module/Validate/string/uuid.js.map +1 -1
  74. package/module/Validate/string/validateEmail.js +1 -1
  75. package/module/es5/Advance/rangeAdvance.d.ts +1 -1
  76. package/module/es5/Array/checkFlagAlignment.js +3 -0
  77. package/module/es5/Array/getArraysCommon.js +45 -19
  78. package/module/es5/Array/groupBy.js +2 -1
  79. package/module/es5/Array/range.js +1 -1
  80. package/module/es5/Array/timSort.js +1 -1
  81. package/module/es5/Array/ultraNumberSort.js +16 -16
  82. package/module/es5/Consts/clock.d.ts +1 -1
  83. package/module/es5/DataStructure/priorityQueue.d.ts +4 -4
  84. package/module/es5/DataStructure/priorityQueue.js +3 -2
  85. package/module/es5/Date/dayOfWeek.js +2 -1
  86. package/module/es5/Date/format.js +1 -1
  87. package/module/es5/IP/ipToBinaryString.js +1 -1
  88. package/module/es5/IP/subnetMaskToCidr.js +1 -1
  89. package/module/es5/Math/calculator/core.js +15 -5
  90. package/module/es5/Math/gcd.js +5 -2
  91. package/module/es5/Math/mathConverter.js +1 -1
  92. package/module/es5/Math/mode.js +2 -1
  93. package/module/es5/Math/nCr.js +4 -1
  94. package/module/es5/Math/nPr.js +4 -1
  95. package/module/es5/Math/primeFactorization.js +8 -1
  96. package/module/es5/Math/reduce.js +8 -1
  97. package/module/es5/Math/uuidv7.js +13 -14
  98. package/module/es5/Object/omit.js +1 -0
  99. package/module/es5/Object/pickDeep.js +2 -1
  100. package/module/es5/String/formatString/applyFormatter.js +1 -1
  101. package/module/es5/String/formatString/getValue.js +1 -1
  102. package/module/es5/String/fromBase64.js +2 -1
  103. package/module/es5/String/fuzzySearch.d.ts +2 -2
  104. package/module/es5/String/levenshteinDistance.d.ts +2 -2
  105. package/module/es5/String/levenshteinDistance.js +33 -30
  106. package/module/es5/String/padStart.d.ts +0 -1
  107. package/module/es5/String/padStart.js +2 -7
  108. package/module/es5/Tool/index.d.ts +1 -0
  109. package/module/es5/Tool/index.js +11 -0
  110. package/module/es5/Tool/unwrap.d.ts +9 -0
  111. package/module/es5/Tool/unwrap.js +20 -0
  112. package/module/es5/Validate/array/core.js +1 -1
  113. package/module/es5/Validate/core/index.js +3 -2
  114. package/module/es5/Validate/object/core.js +1 -1
  115. package/module/es5/Validate/parseEmail.d.ts +2 -2
  116. package/module/es5/Validate/string/uuid.js +5 -4
  117. package/module/es5/Validate/string/validateEmail.js +1 -1
  118. package/module/es5/tsconfig.tsbuildinfo +1 -1
  119. package/package.json +68 -42
@@ -22,7 +22,7 @@ var range = exports.range = function range(start, end) {
22
22
  return array;
23
23
  }
24
24
  var actualStart = end === undefined ? 0 : start;
25
- var actualEnd = end === undefined ? start : end;
25
+ var actualEnd = end !== null && end !== void 0 ? end : start;
26
26
 
27
27
  // Return empty array if invalid range
28
28
  if (step > 0 && actualStart >= actualEnd || step < 0 && actualStart <= actualEnd) {
@@ -89,7 +89,7 @@ var timSort = exports.timSort = function timSort(array) {
89
89
  var n = end - start + 1;
90
90
  var minRun = getMinRunLength(n);
91
91
  for (var runStart = start; runStart <= end; runStart += minRun) {
92
- var runEnd = Math.min(runStart + MIN_RUN - 1, end);
92
+ var runEnd = Math.min(runStart + minRun - 1, end);
93
93
  (0, _insertionSortRange.insertionSortRange)(result, compareFunction, runStart, runEnd);
94
94
  }
95
95
  for (var size = minRun; size < n; size *= 2) {
@@ -190,15 +190,15 @@ var countingSort = function countingSort(array, min, max, ascending) {
190
190
  for (var index_ = 0; index_ < range; index_++) {
191
191
  var cnt = count[index_];
192
192
  var value = index_ + min;
193
- for (var _index_ = 0; _index_ < cnt; _index_++) {
193
+ for (var index__ = 0; index__ < cnt; index__++) {
194
194
  array[index++] = value;
195
195
  }
196
196
  }
197
197
  } else {
198
- for (var _index_2 = range - 1; _index_2 >= 0; _index_2--) {
199
- var _cnt = count[_index_2];
200
- var _value = _index_2 + min;
201
- for (var _index_3 = 0; _index_3 < _cnt; _index_3++) {
198
+ for (var _index_ = range - 1; _index_ >= 0; _index_--) {
199
+ var _cnt = count[_index_];
200
+ var _value = _index_ + min;
201
+ for (var _index__ = 0; _index__ < _cnt; _index__++) {
202
202
  array[index++] = _value;
203
203
  }
204
204
  }
@@ -240,11 +240,11 @@ var radixSort = function radixSort(array, ascending) {
240
240
  var index = 0;
241
241
  if (ascending) {
242
242
  // Negative numbers first (in reverse order)
243
- for (var _index_4 = negative.length - 1; _index_4 >= 0; _index_4--) {
244
- array[index++] = -negative[_index_4];
243
+ for (var _index_2 = negative.length - 1; _index_2 >= 0; _index_2--) {
244
+ array[index++] = -negative[_index_2];
245
245
  }
246
246
  // Zeros
247
- for (var _index_5 = 0; _index_5 < zeroCount; _index_5++) {
247
+ for (var _index_3 = 0; _index_3 < zeroCount; _index_3++) {
248
248
  array[index++] = 0;
249
249
  }
250
250
  // Positive numbers
@@ -262,11 +262,11 @@ var radixSort = function radixSort(array, ascending) {
262
262
  }
263
263
  } else {
264
264
  // Positive numbers first (in reverse order)
265
- for (var _index_6 = positive.length - 1; _index_6 >= 0; _index_6--) {
266
- array[index++] = positive[_index_6];
265
+ for (var _index_4 = positive.length - 1; _index_4 >= 0; _index_4--) {
266
+ array[index++] = positive[_index_4];
267
267
  }
268
268
  // Zeros
269
- for (var _index_7 = 0; _index_7 < zeroCount; _index_7++) {
269
+ for (var _index_5 = 0; _index_5 < zeroCount; _index_5++) {
270
270
  array[index++] = 0;
271
271
  }
272
272
  // Negative numbers
@@ -384,12 +384,12 @@ var numericInsertionSort = function numericInsertionSort(array, low, high, ascen
384
384
  } else {
385
385
  for (var _index6 = low + 1; _index6 <= high; _index6++) {
386
386
  var _key = array[_index6];
387
- var _index_8 = _index6 - 1;
388
- while (_index_8 >= low && array[_index_8] < _key) {
389
- array[_index_8 + 1] = array[_index_8];
390
- _index_8--;
387
+ var _index_6 = _index6 - 1;
388
+ while (_index_6 >= low && array[_index_6] < _key) {
389
+ array[_index_6 + 1] = array[_index_6];
390
+ _index_6--;
391
391
  }
392
- array[_index_8 + 1] = _key;
392
+ array[_index_6 + 1] = _key;
393
393
  }
394
394
  }
395
395
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Number of milliseconds in one second
3
3
  */
4
- export declare const OneSecondMs: 1000;
4
+ export declare const OneSecondMs = 1000;
5
5
  /**
6
6
  * Number of milliseconds in one minute
7
7
  */
@@ -64,10 +64,10 @@ export declare class PriorityQueue<T> {
64
64
  * ]);
65
65
  * ```
66
66
  */
67
- constructor(initialElements?: Array<{
67
+ constructor(initialElements?: {
68
68
  value: T;
69
69
  priority: number;
70
- }>);
70
+ }[]);
71
71
  /**
72
72
  * Returns the number of elements in the queue.
73
73
  * @returns The number of elements in the queue
@@ -205,10 +205,10 @@ export declare class PriorityQueue<T> {
205
205
  * // [{ value: "high", priority: 10 }, { value: "low", priority: 1 }] (order may vary)
206
206
  * ```
207
207
  */
208
- toArrayWithPriorities(): Array<{
208
+ toArrayWithPriorities(): {
209
209
  value: T;
210
210
  priority: number;
211
- }>;
211
+ }[];
212
212
  /**
213
213
  * Updates the minimum priority when adding elements.
214
214
  * @param priority - The priority being added
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.PriorityQueue = void 0;
7
+ var _unwrap = require("@/Tool/unwrap");
7
8
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
8
9
  function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
9
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
@@ -204,8 +205,8 @@ var PriorityQueue = exports.PriorityQueue = /*#__PURE__*/function () {
204
205
  return (_this$heap$pop = this.heap.pop()) === null || _this$heap$pop === void 0 ? void 0 : _this$heap$pop.value;
205
206
  }
206
207
  var result = this.heap[0].value;
207
- // biome-ignore lint/style/noNonNullAssertion: pop() cannot return undefined when heap.length > 1
208
- this.heap[0] = this.heap.pop();
208
+ // pop() cannot return undefined when heap.length > 1
209
+ this.heap[0] = (0, _unwrap.unwrap)(this.heap.pop(), "panic: heap is empty");
209
210
  this.heapifyDown(0);
210
211
  return result;
211
212
  }
@@ -17,7 +17,8 @@ var dayOfWeek = exports.dayOfWeek = function dayOfWeek(properties) {
17
17
  var timeDifference = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 9;
18
18
  var nowTime = (0, _now.now)(timeDifference);
19
19
  if (properties) {
20
- return (0, _new.newDateInt)(properties.year || nowTime.getFullYear(), properties.mon || nowTime.getMonth() + 1, properties.day || nowTime.getDate()).getDay();
20
+ var _properties$year, _properties$mon, _properties$day;
21
+ return (0, _new.newDateInt)((_properties$year = properties.year) !== null && _properties$year !== void 0 ? _properties$year : nowTime.getFullYear(), (_properties$mon = properties.mon) !== null && _properties$mon !== void 0 ? _properties$mon : nowTime.getMonth() + 1, (_properties$day = properties.day) !== null && _properties$day !== void 0 ? _properties$day : nowTime.getDate()).getDay();
21
22
  }
22
23
  return nowTime.getDay();
23
24
  };
@@ -77,6 +77,6 @@ var format = exports.format = function format(date) {
77
77
  ZZ: timezoneOffsetString.replace(":", "")
78
78
  };
79
79
  return formatString.replaceAll(/\[([^\]]+)]|(Y{1,4}|M{1,2}|D{1,2}|d{1,2}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS)/g, function (_match, $1, $2) {
80
- return $1 || matches[$2];
80
+ return $1 !== null && $1 !== void 0 ? $1 : matches[$2];
81
81
  });
82
82
  };
@@ -34,7 +34,7 @@ var ipToBinaryString = exports.ipToBinaryString = function ipToBinaryString(ip)
34
34
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
35
35
  var octet = _step.value;
36
36
  // Check for empty octet or leading zeros
37
- if (!octet || octet.length > 1 && octet[0] === "0") {
37
+ if (!octet || octet.length > 1 && octet.startsWith("0")) {
38
38
  throw new Error("Invalid IP address format");
39
39
  }
40
40
  var number = Number.parseInt(octet, 10);
@@ -33,7 +33,7 @@ var subnetMaskToCidr = exports.subnetMaskToCidr = function subnetMaskToCidr(subn
33
33
 
34
34
  // Join octets and count consecutive 1s
35
35
  var binaryString = binaryOctets.join("");
36
- var match = binaryString.match(/^1*0*$/);
36
+ var match = /^1*0*$/.exec(binaryString);
37
37
  if (!match) {
38
38
  throw new Error("Invalid subnet mask: must be consecutive 1s followed by 0s");
39
39
  }
@@ -78,12 +78,22 @@ var calculatorCore = exports.calculatorCore = function calculatorCore(expression
78
78
  var sanitizeSigns = function sanitizeSigns(expr) {
79
79
  return expr.replaceAll("--", "+").replaceAll("++", "+").replaceAll("+-", "+0-").replaceAll("-+", "+0-");
80
80
  };
81
+ var currencyRegexCache = new Map();
82
+ var getCurrencyRegex = function getCurrencyRegex(currencySymbol) {
83
+ var cached = currencyRegexCache.get(currencySymbol);
84
+ if (cached) {
85
+ return cached;
86
+ }
87
+ var regex = new RegExp("\\".concat(currencySymbol, "([0-9]+)"));
88
+ currencyRegexCache.set(currencySymbol, regex);
89
+ return regex;
90
+ };
81
91
  var applyCurrencyExchange = function applyCurrencyExchange(expr, rates) {
82
92
  var returnExpr = expr;
83
93
  // Currency exchange logic
84
94
  for (var index in rates) {
85
95
  if (returnExpr.includes(index)) {
86
- var $ = returnExpr.match(new RegExp("\\".concat(index, "([0-9]+)")));
96
+ var $ = getCurrencyRegex(index).exec(returnExpr);
87
97
  if ($) {
88
98
  returnExpr = returnExpr.replace($[0], (0, _convertCurrency.convertCurrency)($[0], rates));
89
99
  }
@@ -96,7 +106,7 @@ var containsParentheses = function containsParentheses(expr) {
96
106
  };
97
107
  var resolveParentheses = function resolveParentheses(expr) {
98
108
  // Logic for calculations inside parentheses
99
- var match = expr.match(/\((-?\d+(?:\.\d+)?)([*+/-])(-?\d+(?:\.\d+)?)\)/);
109
+ var match = /\((-?\d+(?:\.\d+)?)([*+/-])(-?\d+(?:\.\d+)?)\)/.exec(expr);
100
110
  if (match) {
101
111
  return expr.replace(match[0], calculatorCore(match[0].replaceAll(/\(|\)/g, "")));
102
112
  }
@@ -110,7 +120,7 @@ var containsDiv = function containsDiv(expr) {
110
120
  };
111
121
  var resolveMulExp = function resolveMulExp(expr) {
112
122
  // Logic for multiplication and exponentiation
113
- var match = expr.match(/(.*?)(-?\d+(?:\.\d+)?)([*^])(-?\d+(?:\.\d+)?)$/);
123
+ var match = /(.*?)(-?\d+(?:\.\d+)?)([*^])(-?\d+(?:\.\d+)?)$/.exec(expr);
114
124
  if (match) {
115
125
  var result = match[3] === "^" ? Math.pow(Number(match[2]), Number(match[4])) : (0, _multiplication.multiplication)(Number(match[2]), Number(match[4]));
116
126
  return "".concat(match[1]).concat(result);
@@ -119,7 +129,7 @@ var resolveMulExp = function resolveMulExp(expr) {
119
129
  };
120
130
  var resolveDiv = function resolveDiv(expr) {
121
131
  // Logic for division
122
- var match = expr.match(/(-?\d+(?:\.\d+)?)\/(-?\d+(?:\.\d+)?)/);
132
+ var match = /(-?\d+(?:\.\d+)?)\/(-?\d+(?:\.\d+)?)/.exec(expr);
123
133
  if (match) {
124
134
  var result = (0, _division.division)(Number(match[1]), Number(match[2]));
125
135
  return expr.replace(match[0], String(result));
@@ -131,7 +141,7 @@ var containsAddSub = function containsAddSub(expr) {
131
141
  };
132
142
  var resolveAddSub = function resolveAddSub(expr) {
133
143
  // Logic for addition and subtraction
134
- var match = expr.match(/(-?\d+(?:\.\d+)?)(\+|-)(-?\d+(?:\.\d+)?)/);
144
+ var match = /(-?\d+(?:\.\d+)?)(\+|-)(-?\d+(?:\.\d+)?)/.exec(expr);
135
145
  if (match) {
136
146
  var result = match[2] === "+" ? (0, _addition.addition)(Number(match[1]), Number(match[3])) : (0, _subtract.subtract)(Number(match[1]), Number(match[3]));
137
147
  return expr.replace(match[0], String(result));
@@ -62,8 +62,11 @@ var _gcdInteger = function gcdInteger(x, y) {
62
62
  var copyZ = z.map(function (element) {
63
63
  return Math.abs(Math.round(element));
64
64
  });
65
- if (copyX === 0 || copyY === 0) {
66
- return 0;
65
+ if (copyX === 0) {
66
+ return copyY;
67
+ }
68
+ if (copyY === 0) {
69
+ return copyX;
67
70
  }
68
71
  /* Euclidean algorithm */
69
72
  var _ref = [Math.max(copyX, copyY), Math.min(copyX, copyY)];
@@ -24,7 +24,7 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
24
24
  var _mathConverter = exports.mathConverter = function mathConverter(equation) {
25
25
  var convertedEquation = equation;
26
26
  while (true) {
27
- var multiplicationOrExponentiation = convertedEquation.match(/\d+\.?(\d+)?(\*|\^)\d+\.?(\d+)?/);
27
+ var multiplicationOrExponentiation = /\d+\.?(\d+)?(\*|\^)\d+\.?(\d+)?/.exec(convertedEquation);
28
28
  if (!multiplicationOrExponentiation) {
29
29
  return convertedEquation;
30
30
  }
@@ -33,8 +33,9 @@ var mode = exports.mode = function mode(array) {
33
33
  _step;
34
34
  try {
35
35
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
36
+ var _frequency$get;
36
37
  var value = _step.value;
37
- var count = (frequency.get(value) || 0) + 1;
38
+ var count = ((_frequency$get = frequency.get(value)) !== null && _frequency$get !== void 0 ? _frequency$get : 0) + 1;
38
39
  frequency.set(value, count);
39
40
  maxFrequency = Math.max(maxFrequency, count);
40
41
  }
@@ -16,9 +16,12 @@ var _nPr = require("./nPr");
16
16
  * where the order doesn't matter. Uses the formula nCr = nPr / r!
17
17
  */
18
18
  var nCr = exports.nCr = function nCr(n, r) {
19
- if (n === 0 || r === 0 || n < r) {
19
+ if (n < r || n < 0 || r < 0) {
20
20
  return Number.NaN;
21
21
  }
22
+ if (r === 0 || n === r) {
23
+ return 1;
24
+ }
22
25
  var numerator = (0, _nPr.nPr)(n, r);
23
26
  var denominator = 1;
24
27
  for (var index = 2; index <= r; index++) {
@@ -15,9 +15,12 @@ exports.nPr = void 0;
15
15
  * nPr = n * (n-1) * (n-2) * ... * (n-r+1)
16
16
  */
17
17
  var nPr = exports.nPr = function nPr(n, r) {
18
- if (n === 0 || r === 0 || n < r) {
18
+ if (n < r || n < 0 || r < 0) {
19
19
  return Number.NaN;
20
20
  }
21
+ if (r === 0) {
22
+ return 1;
23
+ }
21
24
  var result = 1;
22
25
  for (var index = 0; index < r; index++) {
23
26
  result *= n - index;
@@ -17,7 +17,7 @@ var primeFactorization = exports.primeFactorization = function primeFactorizatio
17
17
  var n = 0;
18
18
  var copyX = x;
19
19
  var out = [];
20
- for (var index = 2; index <= copyX; index++) {
20
+ for (var index = 2; index * index <= copyX; index++) {
21
21
  if (copyX % index === 0) {
22
22
  n = 0;
23
23
  while (copyX % index === 0) {
@@ -30,5 +30,12 @@ var primeFactorization = exports.primeFactorization = function primeFactorizatio
30
30
  });
31
31
  }
32
32
  }
33
+ // If remaining value is greater than 1, it's a prime factor
34
+ if (copyX > 1) {
35
+ out.push({
36
+ number: copyX,
37
+ count: 1
38
+ });
39
+ }
33
40
  return out;
34
41
  };
@@ -18,12 +18,19 @@ var _gcd = require("./gcd");
18
18
  * - gcd: greatest common divisor used for reduction
19
19
  */
20
20
  var reduce = exports.reduce = function reduce(x, y) {
21
- if (x === 0 || y === 0) {
21
+ if (y === 0) {
22
22
  return {
23
23
  x: Number.NaN,
24
24
  y: Number.NaN
25
25
  };
26
26
  }
27
+ if (x === 0) {
28
+ return {
29
+ x: 0,
30
+ y: 1,
31
+ gcd: Math.abs(y)
32
+ };
33
+ }
27
34
  var gcdValue = (0, _gcd.gcd)(Math.abs(x), Math.abs(y));
28
35
  var sign = y < 0 ? -1 : 1;
29
36
  return {
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.uuidv7 = void 0;
7
- var _random = require("./random");
8
7
  function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
9
8
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
10
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
@@ -28,23 +27,23 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
28
27
  var uuidv7 = exports.uuidv7 = function uuidv7() {
29
28
  var DIGITS = "0123456789abcdef";
30
29
  var unixTsMs = Date.now();
31
- var randA = (0, _random.random)(0xfff);
32
- var randBHi = (0, _random.random)(0x3fffffff);
33
- var randBLo = (0, _random.random)(0xffffffff);
34
30
  var bytes = new Uint8Array(16);
35
31
  for (var index = 0; index < 6; index++) {
36
32
  bytes[index] = unixTsMs >>> (5 - index) * 8 & 0xff;
37
33
  }
38
- bytes[6] = 0x70 | randA >>> 8;
39
- bytes[7] = randA & 0xff;
40
- bytes[8] = 0x80 | randBHi >>> 24;
41
- bytes[9] = randBHi >>> 16 & 0xff;
42
- bytes[10] = randBHi >>> 8 & 0xff;
43
- bytes[11] = randBHi & 0xff;
44
- bytes[12] = randBLo >>> 24 & 0xff;
45
- bytes[13] = randBLo >>> 16 & 0xff;
46
- bytes[14] = randBLo >>> 8 & 0xff;
47
- bytes[15] = randBLo & 0xff;
34
+
35
+ // Generate 10 random bytes for the rest
36
+ var randomBytes = new Uint8Array(10);
37
+ globalThis.crypto.getRandomValues(randomBytes);
38
+
39
+ // Version 7 (0x70) + 4 bits from randomBytes[0]
40
+ bytes[6] = 0x70 | randomBytes[0] & 0x0f;
41
+ // Random byte
42
+ bytes[7] = randomBytes[1];
43
+ // Variant 2 (0x80) + 6 bits from randomBytes[2]
44
+ bytes[8] = 0x80 | randomBytes[2] & 0x3f;
45
+ // Remaining random bytes
46
+ bytes.set(randomBytes.subarray(3), 9);
48
47
  var uuid = "";
49
48
  var _iterator = _createForOfIteratorHelper(bytes.entries()),
50
49
  _step;
@@ -23,6 +23,7 @@ var omit = exports.omit = function omit(object) {
23
23
  }
24
24
  for (var _i = 0, _keys = keys; _i < _keys.length; _i++) {
25
25
  var key = _keys[_i];
26
+ // eslint-disable-next-line @typescript-eslint/no-dynamic-delete
26
27
  delete result[key];
27
28
  }
28
29
  return result;
@@ -57,7 +57,8 @@ var pickDeep = exports.pickDeep = function pickDeep(object) {
57
57
  if (index === parts.length - 1) {
58
58
  target[part] = current[part];
59
59
  } else {
60
- target[part] = target[part] || {};
60
+ var _target$part;
61
+ target[part] = (_target$part = target[part]) !== null && _target$part !== void 0 ? _target$part : {};
61
62
  current = current[part];
62
63
  target = target[part];
63
64
  }
@@ -39,7 +39,7 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
39
39
  * applyFormatter("test", "invalid!@#", {}) // → "test"
40
40
  */
41
41
  function applyFormatter(value, formatterString, formatters) {
42
- var match = formatterString.match(/^(\w+)(?:\(([^)]*)\))?$/);
42
+ var match = /^(\w+)(?:\(([^)]*)\))?$/.exec(formatterString);
43
43
  if (!match) {
44
44
  return String(value);
45
45
  }
@@ -46,7 +46,7 @@ function getValue(object, path) {
46
46
  try {
47
47
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
48
48
  var part = _step.value;
49
- var arrayMatch = part.match(/^(.+?)\[(-?\d+)\]$/);
49
+ var arrayMatch = /^(.+?)\[(-?\d+)\]$/.exec(part);
50
50
  if (arrayMatch) {
51
51
  var _arrayMatch = _slicedToArray(arrayMatch, 3),
52
52
  key = _arrayMatch[1],
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.fromBase64 = void 0;
7
+ var _unwrap = require("@/Tool/unwrap");
7
8
  /**
8
9
  * Converts Base64 to string
9
10
  * @param {string} base64String - Base64 encoded string
@@ -16,7 +17,7 @@ var fromBase64 = exports.fromBase64 = function fromBase64(base64String) {
16
17
  }
17
18
  try {
18
19
  return new TextDecoder().decode(Uint8Array.from(atob(base64String).split("").map(function (c) {
19
- return c.codePointAt(0);
20
+ return (0, _unwrap.unwrap)(c.codePointAt(0), "panic: invalid base64 string");
20
21
  })));
21
22
  } catch (_unused) {
22
23
  throw new Error("Invalid Base64 string");
@@ -8,7 +8,7 @@
8
8
  * fuzzySearch("hello", ["hello", "world", "helo", "help"]);
9
9
  * // [{ item: "hello", score: 1 }, { item: "helo", score: 0.8 }, { item: "help", score: 0.6 }]
10
10
  */
11
- export declare const fuzzySearch: (query: string, items: string[], threshold?: number) => Array<{
11
+ export declare const fuzzySearch: (query: string, items: string[], threshold?: number) => {
12
12
  item: string;
13
13
  score: number;
14
- }>;
14
+ }[];
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * Calculates the Levenshtein distance between two strings
3
3
  * Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
4
- * @param str1 - First string to compare
5
- * @param str2 - Second string to compare
4
+ * @param string1 - First string to compare
5
+ * @param string2 - Second string to compare
6
6
  * @returns The Levenshtein distance
7
7
  */
8
8
  export declare const levenshteinDistance: (string1: string, string2: string) => number;
@@ -7,15 +7,16 @@ exports.levenshteinDistance = void 0;
7
7
  /**
8
8
  * Calculates the Levenshtein distance between two strings
9
9
  * Returns the minimum number of single-character edits (insertions, deletions, or substitutions)
10
- * @param str1 - First string to compare
11
- * @param str2 - Second string to compare
10
+ * @param string1 - First string to compare
11
+ * @param string2 - Second string to compare
12
12
  * @returns The Levenshtein distance
13
13
  */
14
- var levenshteinDistance = exports.levenshteinDistance = function levenshteinDistance(string1, string2) {
14
+ var _levenshteinDistance = exports.levenshteinDistance = function levenshteinDistance(string1, string2) {
15
+ if (string1 === string2) {
16
+ return 0;
17
+ }
15
18
  var length1 = string1.length;
16
19
  var length2 = string2.length;
17
-
18
- // Return the length of the other string if one is empty
19
20
  if (length1 === 0) {
20
21
  return length2;
21
22
  }
@@ -23,36 +24,38 @@ var levenshteinDistance = exports.levenshteinDistance = function levenshteinDist
23
24
  return length1;
24
25
  }
25
26
 
26
- // Create a 2D array for dynamic programming
27
- var matrix = Array.from({
28
- length: length1 + 1
29
- }, function () {
30
- return Array.from({
31
- length: length2 + 1
32
- }, function () {
33
- return 0;
34
- });
35
- });
27
+ // Ensure string1 is the shorter string to minimize space complexity to O(min(N, M))
28
+ if (length1 > length2) {
29
+ return _levenshteinDistance(string2, string1);
30
+ }
31
+
32
+ // Create a single row array to store distances
33
+ // We only need the current row and the previous diagonal value
34
+ // eslint-disable-next-line unicorn/no-new-array
35
+ var row = new Array(length1 + 1);
36
36
 
37
- // Initialize first column and row
37
+ // Initialize first row (0 to length1)
38
38
  for (var index = 0; index <= length1; index++) {
39
- matrix[index][0] = index;
40
- }
41
- for (var _index = 0; _index <= length2; _index++) {
42
- matrix[0][_index] = _index;
39
+ row[index] = index;
43
40
  }
44
41
 
45
- // Calculate distances
46
- for (var _index2 = 1; _index2 <= length1; _index2++) {
47
- for (var index_ = 1; index_ <= length2; index_++) {
48
- var cost = string1[_index2 - 1] === string2[index_ - 1] ? 0 : 1;
49
- matrix[_index2][index_] = Math.min(matrix[_index2 - 1][index_] + 1,
50
- // deletion
51
- matrix[_index2][index_ - 1] + 1,
52
- // insertion
53
- matrix[_index2 - 1][index_ - 1] + cost // substitution
42
+ // Iterate through each character of string2
43
+ for (var _index = 1; _index <= length2; _index++) {
44
+ var previousDiagonal = row[0]; // Stores the value of matrix[i-1][j-1]
45
+ row[0] = _index; // Update first element for the new row (matrix[0][j])
46
+
47
+ var char2 = string2[_index - 1];
48
+ for (var _index2 = 1; _index2 <= length1; _index2++) {
49
+ var temporary = row[_index2]; // Store current value to become prevDiagonal for next iteration
50
+ var cost = string1[_index2 - 1] === char2 ? 0 : 1;
51
+ row[_index2] = Math.min(row[_index2] + 1,
52
+ // deletion (value from previous row, same column)
53
+ row[_index2 - 1] + 1,
54
+ // insertion (value from current row, previous column)
55
+ previousDiagonal + cost // substitution (value from previous row, previous column)
54
56
  );
57
+ previousDiagonal = temporary;
55
58
  }
56
59
  }
57
- return matrix[length1][length2];
60
+ return row[length1];
58
61
  };
@@ -5,7 +5,6 @@
5
5
  * @param {number} targetLength - The target length after padding
6
6
  * @param {string} padString - The string to use for padding
7
7
  * @returns {string} The padded string
8
- * @throws {Error} If padString is empty
9
8
  * @example
10
9
  * ```typescript
11
10
  * padStart("123", 5, "0"); // Returns: "00123"
@@ -11,7 +11,6 @@ exports.padStart = void 0;
11
11
  * @param {number} targetLength - The target length after padding
12
12
  * @param {string} padString - The string to use for padding
13
13
  * @returns {string} The padded string
14
- * @throws {Error} If padString is empty
15
14
  * @example
16
15
  * ```typescript
17
16
  * padStart("123", 5, "0"); // Returns: "00123"
@@ -19,12 +18,8 @@ exports.padStart = void 0;
19
18
  * ```
20
19
  */
21
20
  var padStart = exports.padStart = function padStart(string_, targetLength, padString) {
22
- if (padString === "") {
23
- throw new Error("padString cannot be empty");
24
- }
25
-
26
- // Return original string if it's longer than target length
27
- if (string_.length >= targetLength) {
21
+ // Return original string if padString is empty or string is already long enough
22
+ if (padString === "" || string_.length >= targetLength) {
28
23
  return string_;
29
24
  }
30
25
  var padding = "";
@@ -1,3 +1,4 @@
1
1
  export * from "./createPipeline";
2
2
  export * from "./parseJson";
3
3
  export * from "./pipe";
4
+ export * from "./unwrap";
@@ -35,4 +35,15 @@ Object.keys(_pipe).forEach(function (key) {
35
35
  return _pipe[key];
36
36
  }
37
37
  });
38
+ });
39
+ var _unwrap = require("./unwrap");
40
+ Object.keys(_unwrap).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _unwrap[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function get() {
46
+ return _unwrap[key];
47
+ }
48
+ });
38
49
  });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Unwraps a value that may be undefined or null, throwing an error if the value is absent
3
+ * @template T The type of the value to unwrap
4
+ * @param value The value to unwrap (may be undefined or null)
5
+ * @param message The error message to throw if the value is absent
6
+ * @returns The unwrapped value of type T
7
+ * @throws {Error} If the value is undefined or null
8
+ */
9
+ export declare const unwrap: <T>(value: T | undefined | null, message: string) => T;