umt 2.3.0 → 2.5.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 (382) hide show
  1. package/README.md +277 -16
  2. package/module/Array/chunk.js +5 -3
  3. package/module/Array/chunk.js.map +1 -1
  4. package/module/Array/dualPivotQuickSort.d.ts +1 -2
  5. package/module/Array/dualPivotQuickSort.js +5 -26
  6. package/module/Array/dualPivotQuickSort.js.map +1 -1
  7. package/module/Array/groupBy.js +8 -7
  8. package/module/Array/groupBy.js.map +1 -1
  9. package/module/Array/index.d.ts +1 -0
  10. package/module/Array/index.js +1 -0
  11. package/module/Array/index.js.map +1 -1
  12. package/module/Array/quickSort.js +7 -25
  13. package/module/Array/quickSort.js.map +1 -1
  14. package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.d.ts +13 -0
  15. package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.js +20 -0
  16. package/module/Array/sortingHelpers/applyInsertionSortIfNeeded.js.map +1 -0
  17. package/module/Array/sortingHelpers/rangeValidator.d.ts +17 -0
  18. package/module/Array/sortingHelpers/rangeValidator.js +26 -0
  19. package/module/Array/sortingHelpers/rangeValidator.js.map +1 -0
  20. package/module/Array/timSort.js +2 -20
  21. package/module/Array/timSort.js.map +1 -1
  22. package/module/Array/ultraNumberSort.d.ts +7 -0
  23. package/module/Array/ultraNumberSort.js +373 -0
  24. package/module/Array/ultraNumberSort.js.map +1 -0
  25. package/module/Tool/pipe.d.ts +1 -1
  26. package/module/Tool/pipe.js.map +1 -1
  27. package/module/Validate/object/core.d.ts +2 -6
  28. package/module/Validate/object/core.js.map +1 -1
  29. package/module/Validate/type.d.ts +1 -0
  30. package/module/es5/Array/chunk.js +5 -3
  31. package/module/es5/Array/dualPivotQuickSort.d.ts +1 -2
  32. package/module/es5/Array/dualPivotQuickSort.js +8 -28
  33. package/module/es5/Array/groupBy.js +8 -7
  34. package/module/es5/Array/index.d.ts +1 -0
  35. package/module/es5/Array/index.js +11 -0
  36. package/module/es5/Array/quickSort.js +10 -25
  37. package/module/es5/Array/sortingHelpers/applyInsertionSortIfNeeded.d.ts +13 -0
  38. package/module/es5/Array/sortingHelpers/applyInsertionSortIfNeeded.js +25 -0
  39. package/module/es5/Array/sortingHelpers/rangeValidator.d.ts +17 -0
  40. package/module/es5/Array/sortingHelpers/rangeValidator.js +35 -0
  41. package/module/es5/Array/timSort.js +2 -20
  42. package/module/es5/Array/ultraNumberSort.d.ts +7 -0
  43. package/module/es5/Array/ultraNumberSort.js +475 -0
  44. package/module/es5/Tool/pipe.d.ts +1 -1
  45. package/module/es5/Validate/object/core.d.ts +2 -6
  46. package/module/es5/Validate/type.d.ts +1 -0
  47. package/module/es5/tsconfig.tsbuildinfo +1 -1
  48. package/package.json +24 -20
  49. package/module/es5/tests/integration/Array/drop-and-first.test.d.ts +0 -1
  50. package/module/es5/tests/integration/Array/drop-and-first.test.js +0 -34
  51. package/module/es5/tests/integration/Tool/parseJson-and-Validate.test.d.ts +0 -1
  52. package/module/es5/tests/integration/Tool/parseJson-and-Validate.test.js +0 -80
  53. package/module/es5/tests/unit/Advance/rangeAdvance.test.d.ts +0 -1
  54. package/module/es5/tests/unit/Advance/rangeAdvance.test.js +0 -26
  55. package/module/es5/tests/unit/Array/arraysJoin.test.d.ts +0 -1
  56. package/module/es5/tests/unit/Array/arraysJoin.test.js +0 -19
  57. package/module/es5/tests/unit/Array/binarySearch.test.d.ts +0 -1
  58. package/module/es5/tests/unit/Array/binarySearch.test.js +0 -32
  59. package/module/es5/tests/unit/Array/checkFlagAlignment.test.d.ts +0 -1
  60. package/module/es5/tests/unit/Array/checkFlagAlignment.test.js +0 -206
  61. package/module/es5/tests/unit/Array/chunk.test.d.ts +0 -1
  62. package/module/es5/tests/unit/Array/chunk.test.js +0 -51
  63. package/module/es5/tests/unit/Array/compact.test.d.ts +0 -1
  64. package/module/es5/tests/unit/Array/compact.test.js +0 -53
  65. package/module/es5/tests/unit/Array/compareFunctionDefault.test.d.ts +0 -1
  66. package/module/es5/tests/unit/Array/compareFunctionDefault.test.js +0 -29
  67. package/module/es5/tests/unit/Array/drop.test.d.ts +0 -1
  68. package/module/es5/tests/unit/Array/drop.test.js +0 -84
  69. package/module/es5/tests/unit/Array/dualPivotQuickSort.test.d.ts +0 -1
  70. package/module/es5/tests/unit/Array/dualPivotQuickSort.test.js +0 -87
  71. package/module/es5/tests/unit/Array/first.test.d.ts +0 -1
  72. package/module/es5/tests/unit/Array/first.test.js +0 -28
  73. package/module/es5/tests/unit/Array/generateNumberArray.test.d.ts +0 -1
  74. package/module/es5/tests/unit/Array/generateNumberArray.test.js +0 -34
  75. package/module/es5/tests/unit/Array/getArraysCommon.test.d.ts +0 -1
  76. package/module/es5/tests/unit/Array/getArraysCommon.test.js +0 -40
  77. package/module/es5/tests/unit/Array/getArraysDiff.test.d.ts +0 -1
  78. package/module/es5/tests/unit/Array/getArraysDiff.test.js +0 -99
  79. package/module/es5/tests/unit/Array/groupBy.test.d.ts +0 -1
  80. package/module/es5/tests/unit/Array/groupBy.test.js +0 -87
  81. package/module/es5/tests/unit/Array/insertionSort.test.d.ts +0 -1
  82. package/module/es5/tests/unit/Array/insertionSort.test.js +0 -37
  83. package/module/es5/tests/unit/Array/mergeSort.test.d.ts +0 -1
  84. package/module/es5/tests/unit/Array/mergeSort.test.js +0 -49
  85. package/module/es5/tests/unit/Array/pop.test.d.ts +0 -1
  86. package/module/es5/tests/unit/Array/pop.test.js +0 -50
  87. package/module/es5/tests/unit/Array/quickSort.test.d.ts +0 -1
  88. package/module/es5/tests/unit/Array/quickSort.test.js +0 -118
  89. package/module/es5/tests/unit/Array/randomSelect.test.d.ts +0 -1
  90. package/module/es5/tests/unit/Array/randomSelect.test.js +0 -51
  91. package/module/es5/tests/unit/Array/range.test.d.ts +0 -1
  92. package/module/es5/tests/unit/Array/range.test.js +0 -42
  93. package/module/es5/tests/unit/Array/shuffle.test.d.ts +0 -1
  94. package/module/es5/tests/unit/Array/shuffle.test.js +0 -84
  95. package/module/es5/tests/unit/Array/shuffle2DArray.test.d.ts +0 -1
  96. package/module/es5/tests/unit/Array/shuffle2DArray.test.js +0 -90
  97. package/module/es5/tests/unit/Array/sum.test.d.ts +0 -1
  98. package/module/es5/tests/unit/Array/sum.test.js +0 -44
  99. package/module/es5/tests/unit/Array/timSort.test.d.ts +0 -1
  100. package/module/es5/tests/unit/Array/timSort.test.js +0 -128
  101. package/module/es5/tests/unit/Array/zip.test.d.ts +0 -1
  102. package/module/es5/tests/unit/Array/zip.test.js +0 -69
  103. package/module/es5/tests/unit/Array/zipLongest.test.d.ts +0 -1
  104. package/module/es5/tests/unit/Array/zipLongest.test.js +0 -74
  105. package/module/es5/tests/unit/Color/cmykToRgba.test.d.ts +0 -1
  106. package/module/es5/tests/unit/Color/cmykToRgba.test.js +0 -58
  107. package/module/es5/tests/unit/Color/hexaToRgba.test.d.ts +0 -1
  108. package/module/es5/tests/unit/Color/hexaToRgba.test.js +0 -115
  109. package/module/es5/tests/unit/Color/hslaToRgba.test.d.ts +0 -1
  110. package/module/es5/tests/unit/Color/hslaToRgba.test.js +0 -141
  111. package/module/es5/tests/unit/Color/rgbaToCmyk.test.d.ts +0 -1
  112. package/module/es5/tests/unit/Color/rgbaToCmyk.test.js +0 -139
  113. package/module/es5/tests/unit/Color/rgbaToHexA.test.d.ts +0 -1
  114. package/module/es5/tests/unit/Color/rgbaToHexA.test.js +0 -114
  115. package/module/es5/tests/unit/Color/rgbaToHsla.test.d.ts +0 -1
  116. package/module/es5/tests/unit/Color/rgbaToHsla.test.js +0 -190
  117. package/module/es5/tests/unit/Consts/clock.test.d.ts +0 -1
  118. package/module/es5/tests/unit/Consts/clock.test.js +0 -71
  119. package/module/es5/tests/unit/Consts/httpClientErrorStatus.test.d.ts +0 -1
  120. package/module/es5/tests/unit/Consts/httpClientErrorStatus.test.js +0 -33
  121. package/module/es5/tests/unit/Consts/httpInformationalStatus.test.d.ts +0 -1
  122. package/module/es5/tests/unit/Consts/httpInformationalStatus.test.js +0 -13
  123. package/module/es5/tests/unit/Consts/httpRedirectionStatus.test.d.ts +0 -1
  124. package/module/es5/tests/unit/Consts/httpRedirectionStatus.test.js +0 -16
  125. package/module/es5/tests/unit/Consts/httpServerErrorStatus.test.d.ts +0 -1
  126. package/module/es5/tests/unit/Consts/httpServerErrorStatus.test.js +0 -15
  127. package/module/es5/tests/unit/Consts/httpStatus.test.d.ts +0 -1
  128. package/module/es5/tests/unit/Consts/httpStatus.test.js +0 -82
  129. package/module/es5/tests/unit/Consts/httpSuccessStatus.test.d.ts +0 -1
  130. package/module/es5/tests/unit/Consts/httpSuccessStatus.test.js +0 -16
  131. package/module/es5/tests/unit/Date/birthday.test.d.ts +0 -1
  132. package/module/es5/tests/unit/Date/birthday.test.js +0 -31
  133. package/module/es5/tests/unit/Date/dateRange.test.d.ts +0 -1
  134. package/module/es5/tests/unit/Date/dateRange.test.js +0 -40
  135. package/module/es5/tests/unit/Date/dayOfWeek.test.d.ts +0 -1
  136. package/module/es5/tests/unit/Date/dayOfWeek.test.js +0 -39
  137. package/module/es5/tests/unit/Date/deleteSpace.test.d.ts +0 -1
  138. package/module/es5/tests/unit/Date/deleteSpace.test.js +0 -35
  139. package/module/es5/tests/unit/Date/format.test.d.ts +0 -1
  140. package/module/es5/tests/unit/Date/format.test.js +0 -50
  141. package/module/es5/tests/unit/Date/getDay.test.d.ts +0 -1
  142. package/module/es5/tests/unit/Date/getDay.test.js +0 -40
  143. package/module/es5/tests/unit/Date/getTimezoneOffsetString.test.d.ts +0 -1
  144. package/module/es5/tests/unit/Date/getTimezoneOffsetString.test.js +0 -26
  145. package/module/es5/tests/unit/Date/isLeapYear.test.d.ts +0 -1
  146. package/module/es5/tests/unit/Date/isLeapYear.test.js +0 -30
  147. package/module/es5/tests/unit/Date/new.test.d.ts +0 -1
  148. package/module/es5/tests/unit/Date/new.test.js +0 -39
  149. package/module/es5/tests/unit/Date/now.test.d.ts +0 -1
  150. package/module/es5/tests/unit/Date/now.test.js +0 -42
  151. package/module/es5/tests/unit/Error/safeExecute.test.d.ts +0 -1
  152. package/module/es5/tests/unit/Error/safeExecute.test.js +0 -75
  153. package/module/es5/tests/unit/Function/curry.test.d.ts +0 -1
  154. package/module/es5/tests/unit/Function/curry.test.js +0 -138
  155. package/module/es5/tests/unit/IP/cidrToLong.test.d.ts +0 -1
  156. package/module/es5/tests/unit/IP/cidrToLong.test.js +0 -32
  157. package/module/es5/tests/unit/IP/cidrToSubnetMask.test.d.ts +0 -1
  158. package/module/es5/tests/unit/IP/cidrToSubnetMask.test.js +0 -36
  159. package/module/es5/tests/unit/IP/getIpClass.test.d.ts +0 -1
  160. package/module/es5/tests/unit/IP/getIpClass.test.js +0 -36
  161. package/module/es5/tests/unit/IP/getNetworkAddress.test.d.ts +0 -1
  162. package/module/es5/tests/unit/IP/getNetworkAddress.test.js +0 -40
  163. package/module/es5/tests/unit/IP/ipToBinaryString.test.d.ts +0 -1
  164. package/module/es5/tests/unit/IP/ipToBinaryString.test.js +0 -46
  165. package/module/es5/tests/unit/IP/ipToLong.test.d.ts +0 -1
  166. package/module/es5/tests/unit/IP/ipToLong.test.js +0 -34
  167. package/module/es5/tests/unit/IP/isInRange.test.d.ts +0 -1
  168. package/module/es5/tests/unit/IP/isInRange.test.js +0 -82
  169. package/module/es5/tests/unit/IP/isPrivateIp.test.d.ts +0 -1
  170. package/module/es5/tests/unit/IP/isPrivateIp.test.js +0 -26
  171. package/module/es5/tests/unit/IP/longToIp.test.d.ts +0 -1
  172. package/module/es5/tests/unit/IP/longToIp.test.js +0 -39
  173. package/module/es5/tests/unit/IP/subnetMaskToCidr.test.d.ts +0 -1
  174. package/module/es5/tests/unit/IP/subnetMaskToCidr.test.js +0 -41
  175. package/module/es5/tests/unit/Math/addition.test.d.ts +0 -1
  176. package/module/es5/tests/unit/Math/addition.test.js +0 -79
  177. package/module/es5/tests/unit/Math/average.test.d.ts +0 -1
  178. package/module/es5/tests/unit/Math/average.test.js +0 -48
  179. package/module/es5/tests/unit/Math/bitwise.test.d.ts +0 -1
  180. package/module/es5/tests/unit/Math/bitwise.test.js +0 -62
  181. package/module/es5/tests/unit/Math/calculator/calculator.test.d.ts +0 -1
  182. package/module/es5/tests/unit/Math/calculator/calculator.test.js +0 -76
  183. package/module/es5/tests/unit/Math/calculator/calculatorInitialization.test.d.ts +0 -1
  184. package/module/es5/tests/unit/Math/calculator/calculatorInitialization.test.js +0 -21
  185. package/module/es5/tests/unit/Math/calculator/convertCurrency.test.d.ts +0 -1
  186. package/module/es5/tests/unit/Math/calculator/convertCurrency.test.js +0 -40
  187. package/module/es5/tests/unit/Math/calculator/literalExpression.test.d.ts +0 -1
  188. package/module/es5/tests/unit/Math/calculator/literalExpression.test.js +0 -51
  189. package/module/es5/tests/unit/Math/degToRad.test.d.ts +0 -1
  190. package/module/es5/tests/unit/Math/degToRad.test.js +0 -50
  191. package/module/es5/tests/unit/Math/deviationValue.test.d.ts +0 -1
  192. package/module/es5/tests/unit/Math/deviationValue.test.js +0 -30
  193. package/module/es5/tests/unit/Math/division.test.d.ts +0 -1
  194. package/module/es5/tests/unit/Math/division.test.js +0 -81
  195. package/module/es5/tests/unit/Math/factorial.test.d.ts +0 -1
  196. package/module/es5/tests/unit/Math/factorial.test.js +0 -26
  197. package/module/es5/tests/unit/Math/factorize.test.d.ts +0 -1
  198. package/module/es5/tests/unit/Math/factorize.test.js +0 -38
  199. package/module/es5/tests/unit/Math/flexibleNumberConversion.test.d.ts +0 -1
  200. package/module/es5/tests/unit/Math/flexibleNumberConversion.test.js +0 -195
  201. package/module/es5/tests/unit/Math/gcd.test.d.ts +0 -1
  202. package/module/es5/tests/unit/Math/gcd.test.js +0 -35
  203. package/module/es5/tests/unit/Math/getDecimalLength.test.d.ts +0 -1
  204. package/module/es5/tests/unit/Math/getDecimalLength.test.js +0 -44
  205. package/module/es5/tests/unit/Math/lcm.test.d.ts +0 -1
  206. package/module/es5/tests/unit/Math/lcm.test.js +0 -43
  207. package/module/es5/tests/unit/Math/linearCongruentialGenerator.test.d.ts +0 -1
  208. package/module/es5/tests/unit/Math/linearCongruentialGenerator.test.js +0 -25
  209. package/module/es5/tests/unit/Math/mathConverter.test.d.ts +0 -1
  210. package/module/es5/tests/unit/Math/mathConverter.test.js +0 -37
  211. package/module/es5/tests/unit/Math/mathSeparator.test.d.ts +0 -1
  212. package/module/es5/tests/unit/Math/mathSeparator.test.js +0 -59
  213. package/module/es5/tests/unit/Math/max.test.d.ts +0 -1
  214. package/module/es5/tests/unit/Math/max.test.js +0 -22
  215. package/module/es5/tests/unit/Math/median.test.d.ts +0 -1
  216. package/module/es5/tests/unit/Math/median.test.js +0 -17
  217. package/module/es5/tests/unit/Math/min.test.d.ts +0 -1
  218. package/module/es5/tests/unit/Math/min.test.js +0 -22
  219. package/module/es5/tests/unit/Math/multiples.test.d.ts +0 -1
  220. package/module/es5/tests/unit/Math/multiples.test.js +0 -30
  221. package/module/es5/tests/unit/Math/multiplication.test.d.ts +0 -1
  222. package/module/es5/tests/unit/Math/multiplication.test.js +0 -48
  223. package/module/es5/tests/unit/Math/nCr.test.d.ts +0 -1
  224. package/module/es5/tests/unit/Math/nCr.test.js +0 -34
  225. package/module/es5/tests/unit/Math/nHr.test.d.ts +0 -1
  226. package/module/es5/tests/unit/Math/nHr.test.js +0 -35
  227. package/module/es5/tests/unit/Math/nPr.test.d.ts +0 -1
  228. package/module/es5/tests/unit/Math/nPr.test.js +0 -38
  229. package/module/es5/tests/unit/Math/primeFactorization.test.d.ts +0 -1
  230. package/module/es5/tests/unit/Math/primeFactorization.test.js +0 -84
  231. package/module/es5/tests/unit/Math/quotient.test.d.ts +0 -1
  232. package/module/es5/tests/unit/Math/quotient.test.js +0 -36
  233. package/module/es5/tests/unit/Math/radToDeg.test.d.ts +0 -1
  234. package/module/es5/tests/unit/Math/radToDeg.test.js +0 -50
  235. package/module/es5/tests/unit/Math/random.test.d.ts +0 -1
  236. package/module/es5/tests/unit/Math/random.test.js +0 -61
  237. package/module/es5/tests/unit/Math/reduce.test.d.ts +0 -1
  238. package/module/es5/tests/unit/Math/reduce.test.js +0 -93
  239. package/module/es5/tests/unit/Math/repeatedTrial.test.d.ts +0 -1
  240. package/module/es5/tests/unit/Math/repeatedTrial.test.js +0 -39
  241. package/module/es5/tests/unit/Math/roundOf.test.d.ts +0 -1
  242. package/module/es5/tests/unit/Math/roundOf.test.js +0 -40
  243. package/module/es5/tests/unit/Math/solveEquation.test.d.ts +0 -1
  244. package/module/es5/tests/unit/Math/solveEquation.test.js +0 -24
  245. package/module/es5/tests/unit/Math/standardDeviation.test.d.ts +0 -1
  246. package/module/es5/tests/unit/Math/standardDeviation.test.js +0 -23
  247. package/module/es5/tests/unit/Math/subtract.test.d.ts +0 -1
  248. package/module/es5/tests/unit/Math/subtract.test.js +0 -46
  249. package/module/es5/tests/unit/Math/toBaseN.test.d.ts +0 -1
  250. package/module/es5/tests/unit/Math/toBaseN.test.js +0 -40
  251. package/module/es5/tests/unit/Math/toCelsius.test.d.ts +0 -1
  252. package/module/es5/tests/unit/Math/toCelsius.test.js +0 -18
  253. package/module/es5/tests/unit/Math/toKelvin.test.d.ts +0 -1
  254. package/module/es5/tests/unit/Math/toKelvin.test.js +0 -18
  255. package/module/es5/tests/unit/Math/uuidv7.test.d.ts +0 -1
  256. package/module/es5/tests/unit/Math/uuidv7.test.js +0 -33
  257. package/module/es5/tests/unit/Math/valueSwap.test.d.ts +0 -1
  258. package/module/es5/tests/unit/Math/valueSwap.test.js +0 -28
  259. package/module/es5/tests/unit/Math/xoshiro256.test.d.ts +0 -1
  260. package/module/es5/tests/unit/Math/xoshiro256.test.js +0 -33
  261. package/module/es5/tests/unit/Object/has.test.d.ts +0 -1
  262. package/module/es5/tests/unit/Object/has.test.js +0 -60
  263. package/module/es5/tests/unit/Object/keyBy.test.d.ts +0 -1
  264. package/module/es5/tests/unit/Object/keyBy.test.js +0 -120
  265. package/module/es5/tests/unit/Object/pick.test.d.ts +0 -1
  266. package/module/es5/tests/unit/Object/pick.test.js +0 -109
  267. package/module/es5/tests/unit/Object/pickDeep.test.d.ts +0 -1
  268. package/module/es5/tests/unit/Object/pickDeep.test.js +0 -222
  269. package/module/es5/tests/unit/Simple/Array/quickSortSimple.test.d.ts +0 -1
  270. package/module/es5/tests/unit/Simple/Array/quickSortSimple.test.js +0 -18
  271. package/module/es5/tests/unit/Simple/Date/dayOfWeekSimple.test.d.ts +0 -1
  272. package/module/es5/tests/unit/Simple/Date/dayOfWeekSimple.test.js +0 -58
  273. package/module/es5/tests/unit/Simple/Math/deviationValueSimple.test.d.ts +0 -1
  274. package/module/es5/tests/unit/Simple/Math/deviationValueSimple.test.js +0 -43
  275. package/module/es5/tests/unit/String/deleteSpaces.test.d.ts +0 -1
  276. package/module/es5/tests/unit/String/deleteSpaces.test.js +0 -22
  277. package/module/es5/tests/unit/String/formatString.test.d.ts +0 -1
  278. package/module/es5/tests/unit/String/formatString.test.js +0 -47
  279. package/module/es5/tests/unit/String/fromBase64.test.d.ts +0 -1
  280. package/module/es5/tests/unit/String/fromBase64.test.js +0 -37
  281. package/module/es5/tests/unit/String/hasNoLetters.test.d.ts +0 -1
  282. package/module/es5/tests/unit/String/hasNoLetters.test.js +0 -29
  283. package/module/es5/tests/unit/String/padEnd.test.d.ts +0 -1
  284. package/module/es5/tests/unit/String/padEnd.test.js +0 -22
  285. package/module/es5/tests/unit/String/padStart.test.d.ts +0 -1
  286. package/module/es5/tests/unit/String/padStart.test.js +0 -40
  287. package/module/es5/tests/unit/String/randomString.test.d.ts +0 -1
  288. package/module/es5/tests/unit/String/randomString.test.js +0 -21
  289. package/module/es5/tests/unit/String/randomStringInitialization.test.d.ts +0 -1
  290. package/module/es5/tests/unit/String/randomStringInitialization.test.js +0 -25
  291. package/module/es5/tests/unit/String/reverseString.test.d.ts +0 -1
  292. package/module/es5/tests/unit/String/reverseString.test.js +0 -35
  293. package/module/es5/tests/unit/String/toBase64.test.d.ts +0 -1
  294. package/module/es5/tests/unit/String/toBase64.test.js +0 -20
  295. package/module/es5/tests/unit/String/toHalfWidth.test.d.ts +0 -1
  296. package/module/es5/tests/unit/String/toHalfWidth.test.js +0 -16
  297. package/module/es5/tests/unit/String/trimCharacters.test.d.ts +0 -1
  298. package/module/es5/tests/unit/String/trimCharacters.test.js +0 -17
  299. package/module/es5/tests/unit/String/trimEndCharacters.test.d.ts +0 -1
  300. package/module/es5/tests/unit/String/trimEndCharacters.test.js +0 -33
  301. package/module/es5/tests/unit/String/trimStartCharacters.test.d.ts +0 -1
  302. package/module/es5/tests/unit/String/trimStartCharacters.test.js +0 -33
  303. package/module/es5/tests/unit/Time/convertTime.test.d.ts +0 -1
  304. package/module/es5/tests/unit/Time/convertTime.test.js +0 -135
  305. package/module/es5/tests/unit/Time/normalizeTimeUnit.test.d.ts +0 -1
  306. package/module/es5/tests/unit/Time/normalizeTimeUnit.test.js +0 -29
  307. package/module/es5/tests/unit/Tool/createPipeline.test.d.ts +0 -1
  308. package/module/es5/tests/unit/Tool/createPipeline.test.js +0 -184
  309. package/module/es5/tests/unit/Tool/parseJson.test.d.ts +0 -1
  310. package/module/es5/tests/unit/Tool/parseJson.test.js +0 -46
  311. package/module/es5/tests/unit/Tool/pipe.test.d.ts +0 -1
  312. package/module/es5/tests/unit/Tool/pipe.test.js +0 -445
  313. package/module/es5/tests/unit/UA/extractBrowserFromUserAgent.test.d.ts +0 -1
  314. package/module/es5/tests/unit/UA/extractBrowserFromUserAgent.test.js +0 -47
  315. package/module/es5/tests/unit/UA/extractDeviceFromUserAgent.test.d.ts +0 -1
  316. package/module/es5/tests/unit/UA/extractDeviceFromUserAgent.test.js +0 -55
  317. package/module/es5/tests/unit/UA/extractOsFromUserAgent.test.d.ts +0 -1
  318. package/module/es5/tests/unit/UA/extractOsFromUserAgent.test.js +0 -57
  319. package/module/es5/tests/unit/UA/parseUserAgent.test.d.ts +0 -1
  320. package/module/es5/tests/unit/UA/parseUserAgent.test.js +0 -95
  321. package/module/es5/tests/unit/Unit/unitConverterInitialization.test.d.ts +0 -1
  322. package/module/es5/tests/unit/Unit/unitConverterInitialization.test.js +0 -40
  323. package/module/es5/tests/unit/Validate/array/core.test.d.ts +0 -1
  324. package/module/es5/tests/unit/Validate/array/core.test.js +0 -86
  325. package/module/es5/tests/unit/Validate/boolean/core.test.d.ts +0 -1
  326. package/module/es5/tests/unit/Validate/boolean/core.test.js +0 -29
  327. package/module/es5/tests/unit/Validate/core/core.test.d.ts +0 -1
  328. package/module/es5/tests/unit/Validate/core/core.test.js +0 -87
  329. package/module/es5/tests/unit/Validate/isArray.test.d.ts +0 -1
  330. package/module/es5/tests/unit/Validate/isArray.test.js +0 -36
  331. package/module/es5/tests/unit/Validate/isDictionaryObject.test.d.ts +0 -1
  332. package/module/es5/tests/unit/Validate/isDictionaryObject.test.js +0 -62
  333. package/module/es5/tests/unit/Validate/isDouble.test.d.ts +0 -1
  334. package/module/es5/tests/unit/Validate/isDouble.test.js +0 -47
  335. package/module/es5/tests/unit/Validate/isEqual.test.d.ts +0 -1
  336. package/module/es5/tests/unit/Validate/isEqual.test.js +0 -74
  337. package/module/es5/tests/unit/Validate/isNotEmpty.test.d.ts +0 -1
  338. package/module/es5/tests/unit/Validate/isNotEmpty.test.js +0 -43
  339. package/module/es5/tests/unit/Validate/isNumber.test.d.ts +0 -1
  340. package/module/es5/tests/unit/Validate/isNumber.test.js +0 -77
  341. package/module/es5/tests/unit/Validate/isPerfectSquare.test.d.ts +0 -1
  342. package/module/es5/tests/unit/Validate/isPerfectSquare.test.js +0 -27
  343. package/module/es5/tests/unit/Validate/isPrimeNumber.test.d.ts +0 -1
  344. package/module/es5/tests/unit/Validate/isPrimeNumber.test.js +0 -51
  345. package/module/es5/tests/unit/Validate/isValueNaN.test.d.ts +0 -1
  346. package/module/es5/tests/unit/Validate/isValueNaN.test.js +0 -54
  347. package/module/es5/tests/unit/Validate/number/core.test.d.ts +0 -1
  348. package/module/es5/tests/unit/Validate/number/core.test.js +0 -36
  349. package/module/es5/tests/unit/Validate/number/double.test.d.ts +0 -1
  350. package/module/es5/tests/unit/Validate/number/double.test.js +0 -23
  351. package/module/es5/tests/unit/Validate/number/even.test.d.ts +0 -1
  352. package/module/es5/tests/unit/Validate/number/even.test.js +0 -23
  353. package/module/es5/tests/unit/Validate/number/maxValue.test.d.ts +0 -1
  354. package/module/es5/tests/unit/Validate/number/maxValue.test.js +0 -20
  355. package/module/es5/tests/unit/Validate/number/minValue.test.d.ts +0 -1
  356. package/module/es5/tests/unit/Validate/number/minValue.test.js +0 -20
  357. package/module/es5/tests/unit/Validate/number/odd.test.d.ts +0 -1
  358. package/module/es5/tests/unit/Validate/number/odd.test.js +0 -23
  359. package/module/es5/tests/unit/Validate/number/prime.test.d.ts +0 -1
  360. package/module/es5/tests/unit/Validate/number/prime.test.js +0 -25
  361. package/module/es5/tests/unit/Validate/object/core.test.d.ts +0 -1
  362. package/module/es5/tests/unit/Validate/object/core.test.js +0 -79
  363. package/module/es5/tests/unit/Validate/string/core.test.d.ts +0 -1
  364. package/module/es5/tests/unit/Validate/string/core.test.js +0 -27
  365. package/module/es5/tests/unit/Validate/string/email.test.d.ts +0 -1
  366. package/module/es5/tests/unit/Validate/string/email.test.js +0 -21
  367. package/module/es5/tests/unit/Validate/string/length.test.d.ts +0 -1
  368. package/module/es5/tests/unit/Validate/string/length.test.js +0 -18
  369. package/module/es5/tests/unit/Validate/string/maxLength.test.d.ts +0 -1
  370. package/module/es5/tests/unit/Validate/string/maxLength.test.js +0 -18
  371. package/module/es5/tests/unit/Validate/string/minLength.test.d.ts +0 -1
  372. package/module/es5/tests/unit/Validate/string/minLength.test.js +0 -18
  373. package/module/es5/tests/unit/Validate/string/numberString.test.d.ts +0 -1
  374. package/module/es5/tests/unit/Validate/string/numberString.test.js +0 -22
  375. package/module/es5/tests/unit/Validate/string/regexMatch.test.d.ts +0 -1
  376. package/module/es5/tests/unit/Validate/string/regexMatch.test.js +0 -29
  377. package/module/es5/tests/unit/Validate/string/uuid.test.d.ts +0 -1
  378. package/module/es5/tests/unit/Validate/string/uuid.test.js +0 -72
  379. package/module/es5/tests/unit/types/arrayType.test.d.ts +0 -1
  380. package/module/es5/tests/unit/types/arrayType.test.js +0 -11
  381. package/module/es5/tests/unit/types/clockType.test.d.ts +0 -1
  382. package/module/es5/tests/unit/types/clockType.test.js +0 -37
package/README.md CHANGED
@@ -1,21 +1,6 @@
1
1
  # UMT Main Package
2
2
 
3
- Amemiya Riyaの便利関数集
4
-
5
- UMT = Useful My Tools
6
-
7
- アプデで破壊的変更がある可能性があります。
8
-
9
- Main Packageに依存関係はありません。
10
-
11
- ## 実装方針
12
-
13
- - 依存関係を持たない
14
- - 拡張性を持たせるために、最小限の機能のみを実装する
15
-
16
- ## Doc
17
-
18
- - [Doc](https://umt-main.oshaburikitchin.com/)
3
+ UMT Main Package is written in TypeScript and is a collection of useful functions for various tasks.
19
4
 
20
5
  ## Install
21
6
 
@@ -34,3 +19,279 @@ pnpm add umt
34
19
 
35
20
  bun add umt
36
21
  ```
22
+
23
+ ## Function List
24
+
25
+ ### Advance
26
+
27
+ | name | type | description | example |
28
+ |------|------|-------------|---------|
29
+ | rangeAdvance | `(start: number, end?: number, conditionalExpression?: (n: number) => boolean) => number[]` | Returns an array of numbers that satisfy the conditional expression | `rangeAdvance(1, 10, (n) => n % 2 === 0); // [2, 4, 6, 8]` |
30
+
31
+ ### Array
32
+
33
+ | name | type | description | example |
34
+ |------|------|-------------|---------|
35
+ | arraysJoin | `<A extends unknown[]>(array: unknown[], ...arrays: unknown[]) => A` | Join arrays without duplicates | `arraysJoin([1, 2, 3], [2, 3, 4]); // [1, 2, 3, 4]` |
36
+ | binarySearch | `(array: number[], target: number) => number` | Binary search implementation | `binarySearch([1, 2, 3, 4, 5], 3); // 2` |
37
+ | checkFlagAlignment | `<T extends { flag: boolean }>(matrix: T[][]) => boolean` | Check if flags are aligned in any direction (horizontal, vertical, or diagonal) | `checkFlagAlignment([[{flag: true}, {flag: true}]]); // true` |
38
+ | chunk | `<T extends unknown[], N extends number>(array: T, n: N) => ChunkArrayType<T, N>` | Split an array into smaller chunks of specified size | `chunk([1, 2, 3, 4, 5, 6, 7, 8, 9], 3); // [[1, 2, 3], [4, 5, 6], [7, 8, 9]]` |
39
+ | compact | `<T>(array: T[]) => T[]` | Creates an array with all falsey values removed | `compact([0, 1, false, 2, '', 3]); // [1, 2, 3]` |
40
+ | drop | `<T>(array: T[], n?: number, direction?: "left" \| "right" \| "between") => T[]` | Returns a new array with n elements removed from the specified direction | `drop([1, 2, 3, 4, 5], 2); // [3, 4, 5]` |
41
+ | dualPivotQuickSort | `<T>(array: T[], compareFunction?: CompareFunction<T>, startIndex?: number, endIndex?: number, insertionSortThreshold?: number) => T[]` | Sort array using dual-pivot quicksort algorithm | `dualPivotQuickSort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3]); // [1, 1, 2, 3, 3, 4, 5, 5, 6, 9]` |
42
+ | first | `<T extends unknown[]>(array: T) => First<T>` | Returns the first element of an array | `first([1, 2, 3]); // 1` |
43
+ | generateNumberArray | `(length: number, min?: number, max?: number, random?: boolean) => number[]` | Generates an array of numbers with the specified length | `generateNumberArray(5); // [0, 1, 2, 3, 4]` |
44
+ | getArraysCommon | `<O, T extends unknown[]>(array: T, ...arrays: T[]) => O` | Extract common elements from multiple arrays | `getArraysCommon([1, 2, 3], [2, 3, 4], [2, 5, 3]); // [2, 3]` |
45
+ | getArraysDiff | `<O, T extends unknown[]>(array: T, ...arrays: T[]) => O` | Extract elements that are not common between arrays | `getArraysDiff([1, 2, 3], [2, 3, 4]); // [1, 4]` |
46
+ | groupBy | `<T, K extends string \| number>(array: T[], iteratee: (value: T, index: number, array: T[]) => K) => Record<K, T[]>` | Groups elements of an array based on a given iteratee function | `groupBy([6.1, 4.2, 6.3], Math.floor); // { '4': [4.2], '6': [6.1, 6.3] }` |
47
+ | insertionSort | `<T>(array: T[], compareFunction?: CompareFunction<T>, start?: number, end?: number) => T[]` | Sort an array using insertion sort algorithm | `insertionSort([4, 2, 7, 1, 3]); // [1, 2, 3, 4, 7]` |
48
+ | mergeSort | `<T>(array: T[], compareFunction?: CompareFunction<T>) => T[]` | Merge sort implementation | `mergeSort([1, 3, 2, 4, 5], (a, b) => a - b); // [1, 2, 3, 4, 5]` |
49
+ | pop | `<T>(array: T[]) => T \| undefined` | Removes the last element from an array and returns it | `pop([1, 2, 3]); // 3` |
50
+ | quickSort | `<T>(array: T[], compareFunction?: CompareFunction<T>, startIndex?: number, endIndex?: number, insertionSortThreshold?: number) => T[]` | Sorts an array using a hybrid algorithm combining QuickSort and InsertionSort | `quickSort([1, 3, 2, 4, 5]); // [1, 2, 3, 4, 5]` |
51
+ | randomSelect | `<T>(array: T[], count: number, allowDuplicates?: boolean) => T[]` | Randomly selects a specified number of elements from an array | `randomSelect([1, 2, 3, 4, 5], 2); // [3, 1]` |
52
+ | range | `(start: number, end?: number, step?: number) => number[]` | Generates an array of sequential numbers | `range(5); // [0, 1, 2, 3, 4]` |
53
+ | shuffle | `<T>(array: T[]) => T[]` | Randomly shuffles the elements of an array | `shuffle([1, 2, 3, 4, 5]); // [3, 5, 2, 4, 1]` |
54
+ | shuffle2DArray | `<T>(array: T[][]) => T[][]` | Shuffles all elements in a 2D array while maintaining the row lengths | `shuffle2DArray([[1, 2], [3, 4], [5, 6]]); // [[1, 3], [6, 4], [2, 5]]` |
55
+ | sum | `(x: number[]) => number` | Returns the sum of an array of numbers | `sum([1, 2, 3]); // 6` |
56
+ | timSort | `<T>(array: T[], compareFunction?: CompareFunction<T>, start?: number, end?: number) => T[]` | Implementation of the TimSort algorithm | `timSort([3, 1, 4, 1, 5]); // [1, 1, 3, 4, 5]` |
57
+ | ultraNumberSort | `(array: number[], ascending?: boolean) => number[]` | Ultra-fast sorting specifically optimized for number arrays | `ultraNumberSort([3, 1, 4, 1, 5, 9, 2, 6, 5, 3]); // [1, 1, 2, 3, 3, 4, 5, 5, 6, 9]` |
58
+ | zip | `<T extends unknown[][]>(...arrays: T) => ZipArrayType<T>` | Creates a new array by combining elements from multiple arrays at corresponding positions | `zip([1, 2], ['a', 'b']); // [[1, 'a'], [2, 'b']]` |
59
+ | zipLongest | `<T extends unknown[][]>(...arrays: T) => ZipArrayType<T>` | Combines arrays of different lengths by padding shorter arrays with undefined values | `zipLongest([1, 2], ['a']); // [[1, 'a'], [2, undefined]]` |
60
+
61
+ ### Color
62
+
63
+ | name | type | description | example |
64
+ |------|------|-------------|---------|
65
+ | cmykToRgba | `(c: number, m: number, y: number, k: number, a?: number) => { r: number; g: number; b: number; a: number }` | Convert CMYK color values to RGBA color space | `cmykToRgba(100, 100, 0, 60.78) // { r: 0, g: 0, b: 100, a: 1 }` |
66
+ | hexaToRgba | `(hex: string) => { r: number; g: number; b: number; a: number }` | Convert hexadecimal color code to RGBA color values | `hexToRgba("#00000000") // { r: 0, g: 0, b: 0, a: 0 }` |
67
+ | hslaToRgba | `(h: number, s: number, l: number, a?: number) => { r: number; g: number; b: number; a: number }` | Convert HSLA color values to RGBA color space | `hslaToRgba(120, 50, 50, 1) // { r: 64, g: 191, b: 64, a: 1 }` |
68
+ | rgbaToCmyk | `(rgba: { r: number; g: number; b: number; a?: number }) => { c: number; m: number; y: number; k: number; a: number }` | Convert RGBA color to CMYK color model | `rgbaToCmyk({ r: 0, g: 0, b: 0, a: 1 }); // { c: 0, m: 0, y: 0, k: 100, a: 1 }` |
69
+ | rgbaToHexA | `(rgba: { r: number; g: number; b: number; a?: number }) => string` | Convert RGBA color to hexadecimal color code | `rgbaToHexA({ r: 0, g: 0, b: 0, a: 1 }); // "#000000ff"` |
70
+ | rgbaToHsla | `(rgba: { r: number; g: number; b: number; a?: number }) => { h: number; s: number; l: number; a: number }` | Convert RGBA color values to HSLA color space | `rgbaToHsla({ r: 100, g: 100, b: 100, a: 1 }); // { h: 0, s: 0, l: 39.22, a: 1 }` |
71
+
72
+ ### Date
73
+
74
+ | name | type | description | example |
75
+ |------|------|-------------|---------|
76
+ | birthday | `<T extends MonTypeInt>(year: number, mon: T, day: DayTypeInt<T>, timeDifference?: HoursTypeInt) => number` | Calculate age based on birthdate | `birthday(2000, 1, 1); // Returns age of someone born on Jan 1, 2000` |
77
+ | dateRange | `(startDate: Date, endDate: Date) => Date[]` | Generate an array containing all dates between the specified start and end dates | `dateRange(new Date('2025-01-01'), new Date('2025-01-03'))` |
78
+ | dayOfWeek | `<T extends MonTypeInt>(properties?: { year?: number; mon?: T; day?: DayTypeInt<T> }, timeDifference?: HoursTypeInt) => number` | Get the day of the week | `dayOfWeek({ year: 2000, mon: 1, day: 1 });` |
79
+ | format | `(date: Date, formatString?: string) => string` | Converts a date to a string according to the specified format pattern | `format(new Date('2025-04-04'), 'YYYY-MM-DD') // Returns "2025-04-04"` |
80
+ | getDay | `<T extends keyof DayList>(day: number, lang?: T) => ArrayToUnion<DayList[T]>` | Convert a number to a day of the week in the specified language | `getDay(0, "en"); // Returns "Sun"` |
81
+ | getTimezoneOffsetString | `(instance: Date) => string` | Get timezone offset string in format "+HH:mm" or "-HH:mm" | `getTimezoneOffsetString(new Date()); // "+09:00" for JST` |
82
+ | isLeapYear | `(year: number) => boolean` | Determine if a given year is a leap year | `isLeapYear(2020); // Returns true` |
83
+ | newDateInt | `<T extends MonTypeInt>(year: number, mon: T, day: DayTypeInt<T>, hours?: HoursTypeInt, minutes?: MinutesTypeInt, seconds?: SecondsTypeInt, milliseconds?: MillisecondsTypeInt) => Date` | Create a new Date object from numeric values | `newDateInt(2021, 1, 1); // Creates date for January 1, 2021` |
84
+ | newDateString | `<T extends MonTypeZero>(date: string, hours?: HoursType, minutes?: MinutesType, seconds?: SecondsType, milliseconds?: MillisecondsType, timeDifference?: HoursType) => Date` | Create a new Date object from a string date and time components | `newDateString("2021-01-01"); // Creates date for January 1, 2021 00:00:00` |
85
+ | now | `(timeDifference?: HoursTypeInt) => Date` | Get the current time with a specified UTC offset | `now(); // Returns current time in JST (UTC+9)` |
86
+
87
+ ### Error
88
+
89
+ | name | type | description | example |
90
+ |------|------|-------------|---------|
91
+ | safeExecute | `<V, E = Error>(callback: () => V) => Result<V, E>` | Safely executes a callback function and returns a Result type | `safeExecute(() => JSON.parse('{"a": 1}')); // {type: "success", value: {a: 1}}` |
92
+
93
+ ### Function
94
+
95
+ | name | type | description | example |
96
+ |------|------|-------------|---------|
97
+ | curry | `(func: (...args: unknown[]) => unknown) => Function` | Curries a function | `const add = (a, b, c) => a + b + c; curry(add)(1)(2)(3); // 6` |
98
+
99
+ ### IP
100
+
101
+ | name | type | description | example |
102
+ |------|------|-------------|---------|
103
+ | cidrToLong | `(cidr: number) => number` | Converts CIDR notation to a subnet mask number | `cidrToLong(24); // 4294967040` |
104
+ | cidrToSubnetMask | `(cidr: number) => string` | Converts CIDR notation to a subnet mask | `cidrToSubnetMask(24); // "255.255.255.0"` |
105
+ | getIpClass | `(ip: string) => string` | Gets the IP address class (A, B, C, D, or E) | `getIpClass("192.168.1.1"); // "C"` |
106
+ | getNetworkAddress | `(ip: string, subnetMask: string) => number` | Calculates the network address from an IP address and subnet mask | `getNetworkAddress("192.168.1.1", "255.255.255.0"); // 3232235776` |
107
+ | ipToBinaryString | `(ip: string) => string` | Converts an IPv4 address to its binary string representation | `ipToBinaryString("192.168.1.1"); // "11000000101010000000000100000001"` |
108
+ | ipToLong | `(ip: string) => number` | Converts an IPv4 address to a 32-bit number | `ipToLong("192.168.1.1"); // 3232235777` |
109
+ | isInRange | `(remoteIp: string, networkIp: string, cidr: number) => boolean` | Checks if an IP address is within a specified network range | `isInRange("192.168.1.100", "192.168.1.0", 24); // true` |
110
+ | isPrivateIp | `(ip: string) => boolean` | Checks if an IP address is within private IP ranges | `isPrivateIp("192.168.1.1"); // true` |
111
+ | longToIp | `(long: number) => string` | Converts a 32-bit number to an IPv4 address | `longToIp(3232235777); // "192.168.1.1"` |
112
+ | subnetMaskToCidr | `(subnetMask: string) => number` | Converts a subnet mask to CIDR notation | `subnetMaskToCidr("255.255.255.0"); // 24` |
113
+
114
+ ### Math
115
+
116
+ | name | type | description | example |
117
+ |------|------|-------------|---------|
118
+ | addition | `(...numbers: number[]) => number` | Addition without floating point errors | `addition(0.1, 0.2); // 0.3` |
119
+ | average | `(numbers: number[]) => number` | Calculates the arithmetic mean of an array of numbers | `average([1, 2, 3]); // 2` |
120
+ | bitwise | `(x: number, k: number, direction?: "left" \| "right") => number` | Performs bit rotation on a number | `bitwise(0x12345678, 8); // 0x34567812` |
121
+ | calculator | `<T extends Record<string, string \| number>>(expression: string, exchange?: T) => string` | Calculator function that handles mathematical expressions and simple equations | `calculator("1+2"); // "3"` |
122
+ | calculatorInitialization | `<T extends { [key: string]: string \| number }>(exchange: T) => (x: string) => string` | Initializes a calculator function with exchange rates | `calculatorInitialization({ $: 100 })("$1"); // "100"` |
123
+ | convertCurrency | `<T extends { [key: string]: number \| string }>(inputString: string, conversionRates?: T) => string` | Converts currency amounts in a string using currency symbols | `convertCurrency("¥100", { "¥": 0.01 }); // "1"` |
124
+ | degToRad | `(x: number) => number` | Converts degrees to radians | `degToRad(180); // 3.141592653589793` |
125
+ | deviationValue | `(value: number, averageValue: number, standardDeviationValue: number) => number` | Calculate standard score (deviation value) | `deviationValue(10, 5, 2); // 75` |
126
+ | division | `<T extends boolean = true>(x: number, y: number, isFloor?: T) => T extends true ? number : number[]` | Performs division without floating point errors | `division(0.1, 0.2); // 0.5` |
127
+ | factorial | `(x: number) => number` | Calculate factorial of a number | `factorial(5); // 120` |
128
+ | factorize | `(n: number) => number[]` | Prime factorization of a number | `factorize(12); // [2, 2, 3]` |
129
+ | flexibleNumberConversion | `(value: unknown) => number` | Flexible function to convert various inputs to numbers whenever possible | `flexibleNumberConversion("456"); // 456` |
130
+ | gcd | `(x: number, y: number, ...z: number[]) => number` | Greatest Common Divisor (GCD) | `gcd(12, 18); // 6` |
131
+ | getDecimalLength | `(value: number) => number` | Gets the number of decimal places in a number | `getDecimalLength(1.23); // 2` |
132
+ | lcm | `(x: number, y: number) => number` | Least Common Multiple (LCM) | `lcm(2, 3); // 6` |
133
+ | linearCongruentialGenerator | `(seed: number, max?: number, multiplier?: number, increment?: number) => number` | Linear Congruential Generator for random number generation | `linearCongruentialGenerator(12345);` |
134
+ | literalExpression | `(x: string) => string` | Solves literal equations with variables | `literalExpression("x+1=2"); // "1"` |
135
+ | mathConverter | `(equation: string) => string` | Expands square of n into a sum of simpler multiplications | `mathConverter("1250*1250"); // "1500*1000+400*100+200*100+50*50"` |
136
+ | mathSeparator | `(input: string \| number) => [number, number]` | Separates a number at its highest place value | `mathSeparator(1250); // [1000, 250]` |
137
+ | max | `(...number_: number[]) => number` | Returns the maximum value from the input numbers | `max(1, 2, 3); // 3` |
138
+ | median | `(array: number[]) => number` | Calculate the median of an array of numbers | `median([1, 3, 3, 6, 7, 8, 9]); // 6` |
139
+ | min | `(...number_: number[]) => number` | Returns the minimum value from the input numbers | `min(1, 2, 3); // 1` |
140
+ | multiples | `(x: number, n: number) => number[]` | Generate an array of multiples of a number | `multiples(2, 5); // [2, 4, 6, 8, 10]` |
141
+ | multiplication | `(...numbers: number[]) => number` | Performs multiplication without floating point errors for any number of arguments | `multiplication(0.1, 0.2, 0.3); // 0.006` |
142
+ | nCr | `(n: number, r: number) => number` | Calculates combinations (nCr) - number of ways to choose r items from n items | `nCr(5, 2); // 10` |
143
+ | nHr | `(n: number, r: number) => number` | Calculates combinations with repetition (nHr) | `nHr(5, 2); // 15` |
144
+ | nPr | `(n: number, r: number) => number` | Calculates permutations (nPr) - number of ways to arrange r items from n items | `nPr(5, 2); // 20` |
145
+ | primeFactorization | `(x: number) => Array<{number: number; count: number}>` | Performs prime factorization of a number | `primeFactorization(12); // [{number: 2, count: 2}, {number: 3, count: 1}]` |
146
+ | quotient | `(x: number, y: number) => number[]` | Computes quotient and remainder of division | `quotient(5, 2); // [2, 1]` |
147
+ | radToDeg | `(x: number) => number` | Converts radians to degrees | `radToDeg(Math.PI); // 180` |
148
+ | random | `(max: number, min?: number) => number` | Generates a random integer between min and max (inclusive) | `random(10); // returns number between 0 and 10` |
149
+ | reduce | `(x: number, y: number) => {x: number, y: number, gcd: number}` | Reduces a fraction to its lowest terms | `reduce(2, 4); // {x: 1, y: 2, gcd: 2}` |
150
+ | repeatedTrial | `(n: number, r: number, p: {x: number; y: number}) => number[]` | Calculate probability in repeated trials | `repeatedTrial(5, 2, {x: 1/3, y: 2/3}); // [10, 27]` |
151
+ | roundOf | `(value: number, precision?: number) => number` | Rounds a number to specified decimal places | `roundOf(1.234, 2); // 1.23` |
152
+ | solveEquation | `(coefficients: number[][], constants: number[]) => number[]` | Solves a system of linear equations using Gaussian elimination | `solveEquation([[1, 1], [1, 2]], [4, 10]); // [-2, 6]` |
153
+ | standardDeviation | `(values: number[]) => number` | Calculates the standard deviation of a set of values | `standardDeviation([1, 2, 3]); // 0.816496580927726` |
154
+ | subtract | `(...numbers: number[]) => number` | Performs subtraction with arbitrary number of arguments without floating point errors | `subtract(0.1, 0.2); // -0.1` |
155
+ | toBaseN | `(value: number, radix?: number) => string` | Converts a number to a string representation in the specified base | `toBaseN(10); // "1010" (binary)` |
156
+ | toCelsius | `(kelvin: number) => number` | Converts temperature from Kelvin to Celsius | `toCelsius(300); // 26.85` |
157
+ | toKelvin | `(celsius: number) => number` | Converts temperature from Celsius to Kelvin | `toKelvin(26.85); // 300` |
158
+ | uuidv7 | `() => string` | Generates a UUID v7 (Universally Unique Identifier version 7) | `uuidv7(); // e.g. "018d6e78-e1e5-7c3c-8bf9-ae5942f2ba1c"` |
159
+ | valueSwap | `(x: number, y: number) => [number, number]` | Swaps two numbers to ensure x < y | `valueSwap(2, 1); // [1, 2]` |
160
+ | xoshiro256 | `(state: [number, number, number, number], min?: number, max?: number) => number` | Generates random numbers using the Xoshiro256** algorithm | `xoshiro256([1, 2, 3, 4]); // random number between 0 and 1` |
161
+
162
+ ### Object
163
+
164
+ | name | type | description | example |
165
+ |------|------|-------------|---------|
166
+ | has | `<T extends { [key: string]: unknown }>(object: T, path: string \| string[]) => boolean` | Determines if an object has a specified path | `has({ a: { b: 1 } }, "a.b"); // true` |
167
+ | keyBy | `<T>(collection: T[] \| Record<PropertyName, T>, iteratee?: Iteratee<T>) => Record<PropertyName, T>` | Creates an object composed of keys generated from the results of running each element of collection through iteratee | `keyBy([{id: 1, name: 'a'}, {id: 2, name: 'b'}], 'id'); // {1: {id: 1, name: 'a'}, 2: {id: 2, name: 'b'}}` |
168
+ | pick | `<T extends object, K extends keyof T>(object: T, ...keys: K[]) => Pick<T, K>` | Creates a new object with only the specified properties from the source object | `pick({ id: 1, name: 'Alice', age: 30 }, 'id', 'name'); // { id: 1, name: 'Alice' }` |
169
+ | pickDeep | `<T extends object, K extends PickDeepKey<T>>(object: T, ...keys: K[]) => PickDeep<T>` | Creates a new object by deeply selecting properties from the source object based on specified keys | `pickDeep({ a: { b: { c: 1, d: 2 }, e: 3 }, f: 4 }, 'a.b.c', 'f'); // { a: { b: { c: 1 } }, f: 4 }` |
170
+
171
+ ### Simple
172
+
173
+ | name | type | description | example |
174
+ |------|------|-------------|---------|
175
+ | quickSortSimple | `<T>(array: T[], compareFunction?: CompareFunction<T>, startID?: number, endID?: number) => T[]` | Quick sort implementation for arrays | `quickSort([1, 3, 2, 4, 5], (a, b) => a - b); // [1, 2, 3, 4, 5]` |
176
+ | birthdaySimple | `(birthdays: Date \| string \| { year: number; mon: number; day: number }, timeDifference?: HoursTypeInt) => number` | Calculate age from birthdate | `birthdaySimple("2000-01-01");` |
177
+ | dayOfWeekSimple | `(properties?: Date \| string \| { year?: number; mon?: T; day?: DayTypeInt<T> }, timeDifference?: HoursTypeInt) => number` | Get day of the week | `dayOfWeekSimple("2000-01-01");` |
178
+ | nowSimple | `(timeDifference?: HoursTypeInt \| HoursType) => Date` | Get current date and time | `nowSimple(); // 2021-01-01T00:00:00.000Z` |
179
+ | deviationValueSimple | `(value: number, averageValue: number[] \| number, standardDeviationValue?: number) => number` | Calculate deviation score (T-score) | `deviationValueSimple(60, 50, 10); // 60` |
180
+
181
+ ### String
182
+
183
+ | name | type | description | example |
184
+ |------|------|-------------|---------|
185
+ | deleteSpaces | `(string_: string) => string` | Removes all whitespace characters from a string | `deleteSpaces("Hello World"); // "HelloWorld"` |
186
+ | formatString | `(template: string, ...values: unknown[]) => string` | Replaces placeholders in a template string with specified values | `formatString("Hello, {0}!", "World"); // "Hello, World!"` |
187
+ | fromBase64 | `(base64String: string) => string` | Converts Base64 to string | `fromBase64("SGVsbG8="); // "Hello"` |
188
+ | hasNoLetters | `(text: string) => boolean` | Checks if the string contains no letters (contains only emojis, numbers, or special characters) | `hasNoLetters("123"); // true` |
189
+ | padEnd | `(string_: string, targetLength: number, padString: string) => string` | Adds the specified string to the end of the string until it reaches the specified length | `padEnd("123", 5, "0"); // "12300"` |
190
+ | padStart | `(string_: string, targetLength: number, padString: string) => string` | Pads the start of a string with another string until the target length is reached | `padStart("123", 5, "0"); // "00123"` |
191
+ | randomString | `(size?: number, char?: string) => string` | Generates a random string | `randomString(8); // "aB3dEf9h"` |
192
+ | randomStringInitialization | `(char?: string) => (size: number) => string` | Initializes a function that generates random strings | `const gen = randomStringInitialization("ABC"); gen(5); // "ABCAB"` |
193
+ | reverseString | `(char: string) => string` | Reverses a string | `reverseString("Hello"); // "olleH"` |
194
+ | toBase64 | `(char: string) => string` | Convert string to Base64 | `toBase64("Hello"); // "SGVsbG8="` |
195
+ | toHalfWidth | `(str: string) => string` | Convert full-width characters to half-width characters | `toHalfWidth("123ABC"); // "123ABC"` |
196
+ | trimCharacters | `(string_: string, chars: string) => string` | Removes specified characters from both ends of a string | `trimCharacters("!!!hello!!!", "!"); // "hello"` |
197
+ | trimEndCharacters | `(string_: string, chars: string) => string` | Removes specified characters from the end of a string | `trimEndCharacters("hello!!!", "!"); // "hello"` |
198
+ | trimStartCharacters | `(string_: string, chars: string) => string` | Removes specified characters from the start of a string | `trimStartCharacters("!!!hello", "!"); // "hello"` |
199
+
200
+ ### Time
201
+
202
+ | name | type | description | example |
203
+ |------|------|-------------|---------|
204
+ | convertTime | `(value: string \| number, fromUnit: TimeUnit \| TimeUnitShort, toUnit: TimeUnit \| TimeUnitShort) => number` | Converts time between different units | `convertTime(1, "hours", "minutes"); // 60` |
205
+ | normalizeTimeUnit | `(unit: TimeUnit \| TimeUnitShort, to: "long" \| "short") => TimeUnit \| TimeUnitShort` | Normalize time unit | `normalizeTimeUnit("h", "long"); // "hours"` |
206
+
207
+ ### Tool
208
+
209
+ | name | type | description | example |
210
+ |------|------|-------------|---------|
211
+ | createPipeline | `<T>(initialValue: T) => Pipeline<T>` | Function that creates a Pipeline instance | `createPipeline(1)((x) => x + 1)(); // 2` |
212
+ | parseJson | `<T = unknown>(json: string) => T` | Parses a JSON string into a typed JavaScript value | `parseJson<{a: number}>('{"a": 1}'); // {a: 1}` |
213
+ | pipe | `<T>(initialValue: T) => Pipe<T>` | Creates a new Pipe instance with an initial value | `pipe(1).map(x => x + 1).end(); // 2` |
214
+
215
+ ### UA
216
+
217
+ | name | type | description | example |
218
+ |------|------|-------------|---------|
219
+ | extractBrowserFromUserAgent | `(ua: string) => SimplifiedUserAgentInfoBrowser` | Extracts browser information from a User-Agent string | `extractBrowserFromUserAgent(navigator.userAgent); // "chrome"` |
220
+ | extractDeviceFromUserAgent | `(ua: string) => SimplifiedUserAgentInfoDevice` | Extracts device type information from a User-Agent string | `extractDeviceFromUserAgent(navigator.userAgent); // "desktop"` |
221
+ | extractOsFromUserAgent | `(ua: string) => SimplifiedUserAgentInfoOs` | Extracts operating system information from a User-Agent string | `extractOsFromUserAgent(navigator.userAgent); // "macos"` |
222
+ | parseUserAgent | `(userAgent: string) => SimplifiedUserAgentInfo` | Parse a User-Agent string to extract browser, device, and OS information | `parseUserAgent(navigator.userAgent); // {browser: "chrome", device: "desktop", os: "macos"}` |
223
+
224
+ ### Unit
225
+
226
+ | name | type | description | example |
227
+ |------|------|-------------|---------|
228
+ | unitConverterInitialization | `<T extends { [k in K]: number }, K extends string \| number \| symbol>(toBaseUnitRatios: T) => (value: number, from: keyof T, to: keyof T) => number` | Unit converter initialization function | `const converter = unitConverterInitialization({meters: 1, kilometers: 1000}); converter(5, "kilometers", "meters"); // 5000` |
229
+
230
+ ### Validate
231
+
232
+ | name | type | description | example |
233
+ |------|------|-------------|---------|
234
+ | array | `<A extends string \| number \| boolean, O extends {}>(option?: O, message?: string) => (values: A[]) => ValidateCoreReturnType<A[]>` | Creates an array validator with type-specific validation rules | `array()([1, 2, 3]); // {validate: true, message: "", type: [1, 2, 3]}` |
235
+ | boolean | `(message?: string) => (value: boolean) => ValidateCoreReturnType<boolean>` | Creates a boolean validator | `boolean()(true); // {validate: true, message: "", type: true}` |
236
+ | number | `<T extends ValidateReturnType<number>[]>(option?: T, message?: string) => (value: number) => ValidateCoreReturnType<number>` | Creates a number validator with optional validation rules | `number()(42); // {validate: true, message: "", type: 42}` |
237
+ | object | `<T extends {}>(option?: T, message?: string) => (value: Types<{}>) => ValidateCoreReturnType<{}>` | Creates an object validator with property-specific validation rules | `object({id: number()})({id: 1}); // {validate: true, message: "", type: {id: 1}}` |
238
+ | string | `<T extends ValidateReturnType<string>[]>(option?: T, message?: string) => (value: string) => ValidateCoreReturnType<string>` | Creates a string validator with optional validation rules | `string()("hello"); // {validate: true, message: "", type: "hello"}` |
239
+ | isArray | `<T>(array: unknown) => array is T[]` | Determines if the value is an array | `isArray([1, 2, 3]); // true` |
240
+ | isBrowser | `() => boolean` | Determines if the current environment is a browser | `isBrowser(); // true in browser` |
241
+ | isBun | `() => boolean` | Determines if the current environment is Bun runtime | `isBun(); // true in Bun` |
242
+ | isDictionaryObject | `<T extends { [key: string]: unknown }>(object: unknown) => object is T` | Determines if the value is a dictionary-type object | `isDictionaryObject({}); // true` |
243
+ | isDouble | `<T extends boolean = true>(x: unknown, loose?: T) => x is T extends true ? number \| string : number` | Determines if the value is a decimal number | `isDouble(0.1); // true` |
244
+ | isEqual | `(a: unknown, b: unknown) => boolean` | Evaluates true strict equality | `isEqual(1, 1); // true` |
245
+ | isNode | `() => boolean` | Determines if the current environment is Node.js | `isNode(); // true in Node.js` |
246
+ | isNodeWebkit | `() => boolean` | Determines if the current environment is Node-Webkit | `isNodeWebkit(); // true in Node-Webkit` |
247
+ | isNotEmpty | `(object: object) => boolean` | Checks if an object is not empty | `isNotEmpty({ a: 1 }); // true` |
248
+ | isNumber | `<T extends boolean>(number: unknown, loose?: T) => number is T extends true ? number \| string : number` | Determines if the value represents a number | `isNumber(0.1); // true` |
249
+ | isPerfectSquare | `(number_: number) => boolean` | Determines if a given integer is a perfect square | `isPerfectSquare(16); // true` |
250
+ | isPrimeNumber | `(n: number) => boolean` | Determines if a number is prime | `isPrimeNumber(17); // true` |
251
+ | isString | `(value: unknown) => value is string` | Determines if the value is a string | `isString("test"); // true` |
252
+ | isValueNaN | `(value: unknown, loose?: boolean) => boolean` | Determines if a value is NaN | `isValueNaN(parseInt("not a number")); // true` |
253
+
254
+ #### Validate Number Options
255
+
256
+ | name | type | description | example |
257
+ |------|------|-------------|---------|
258
+ | double | `(message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is a floating point value | `number([double()])(-0.5); // valid` |
259
+ | even | `(message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is even | `number([even()])(4); // valid` |
260
+ | maxValue | `(maxValue: number, message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is less than or equal to a maximum value | `number([maxValue(100)])(50); // valid` |
261
+ | minValue | `(minValue: number, message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is greater than or equal to a minimum value | `number([minValue(0)])(10); // valid` |
262
+ | odd | `(message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is odd | `number([odd()])(3); // valid` |
263
+ | prime | `(message?: string) => ValidateReturnType<number>` | Creates a validator for checking if a number is prime | `number([prime()])(7); // valid` |
264
+
265
+ #### Validate String Options
266
+
267
+ | name | type | description | example |
268
+ |------|------|-------------|---------|
269
+ | email | `(message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string is a valid email address | `string([email()])("test@example.com"); // valid` |
270
+ | length_ | `(length: number, message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string has an exact length | `string([length_(5)])("hello"); // valid` |
271
+ | maxLength | `(maxLength: number, message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string's length is less than or equal to a maximum value | `string([maxLength(10)])("hello"); // valid` |
272
+ | minLength | `(minLength: number, message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string's length is greater than or equal to a minimum value | `string([minLength(3)])("hello"); // valid` |
273
+ | numberString | `(message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string represents a valid number | `string([numberString()])("123.45"); // valid` |
274
+ | regexMatch | `(pattern: RegExp, message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string matches a regular expression pattern | `string([regexMatch(/^[A-Z]/)])("Hello"); // valid` |
275
+ | uuid | `(versions?: number[], message?: string) => ValidateReturnType<string>` | Creates a validator for checking if a string is a valid UUID | `string([uuid()])("550e8400-e29b-41d4-a716-446655440000"); // valid` |
276
+
277
+ ### Consts
278
+
279
+ | name | type | description | example |
280
+ |------|------|-------------|---------|
281
+ | OneSecondMs | `1000` | Number of milliseconds in one second | `OneSecondMs; // 1000` |
282
+ | OneMinuteMs | `60000` | Number of milliseconds in one minute | `OneMinuteMs; // 60000` |
283
+ | OneHourMs | `3600000` | Number of milliseconds in one hour | `OneHourMs; // 3600000` |
284
+ | OneDayMs | `86400000` | Number of milliseconds in one day | `OneDayMs; // 86400000` |
285
+ | OneWeekMs | `604800000` | Number of milliseconds in one week | `OneWeekMs; // 604800000` |
286
+ | OneMonthMs28 | `2419200000` | Number of milliseconds in one month (28 days) | `OneMonthMs28; // 2419200000` |
287
+ | OneMonthMs29 | `2505600000` | Number of milliseconds in one month (29 days) | `OneMonthMs29; // 2505600000` |
288
+ | OneMonthMs | `2592000000` | Number of milliseconds in one month (30 days) | `OneMonthMs; // 2592000000` |
289
+ | OneMonthMs31 | `2678400000` | Number of milliseconds in one month (31 days) | `OneMonthMs31; // 2678400000` |
290
+ | OneYearMs | `31536000000` | Number of milliseconds in one year (365 days) | `OneYearMs; // 31536000000` |
291
+ | OneYearMs366 | `31622400000` | Number of milliseconds in one year (366 days) | `OneYearMs366; // 31622400000` |
292
+ | HttpStatus | `Object` | All HTTP status codes | `HttpStatus.OK; // 200` |
293
+ | HttpInformationalStatus | `Object` | HTTP 1xx Informational Status Codes | `HttpInformationalStatus.CONTINUE; // 100` |
294
+ | HttpSuccessStatus | `Object` | HTTP 2xx Success Status Codes | `HttpSuccessStatus.OK; // 200` |
295
+ | HttpRedirectionStatus | `Object` | HTTP 3xx Redirection Status Codes | `HttpRedirectionStatus.MOVED_PERMANENTLY; // 301` |
296
+ | HttpClientErrorStatus | `Object` | HTTP 4xx Client Error Status Codes | `HttpClientErrorStatus.NOT_FOUND; // 404` |
297
+ | HttpServerErrorStatus | `Object` | HTTP 5xx Server Error Status Codes | `HttpServerErrorStatus.INTERNAL_SERVER_ERROR; // 500` |
@@ -1,7 +1,9 @@
1
1
  export const chunk = (array, n) => {
2
- const result = [];
3
- for (let index = 0; index < array.length; index += n) {
4
- result.push(array.slice(index, index + n));
2
+ const length = array.length;
3
+ // eslint-disable-next-line unicorn/no-new-array
4
+ const result = new Array(Math.ceil(length / n));
5
+ for (let index = 0, k = 0; index < length; index += n, k++) {
6
+ result[k] = array.slice(index, index + n);
5
7
  }
6
8
  return result;
7
9
  };
@@ -1 +1 @@
1
- {"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/Array/chunk.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,KAAQ,EACR,CAAI,EACkB,EAAE;IACxB,MAAM,MAAM,GAAU,EAAE,CAAC;IACzB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC;QACrD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAmB,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,MAA8B,CAAC;AACxC,CAAC,CAAC"}
1
+ {"version":3,"file":"chunk.js","sourceRoot":"","sources":["../../src/Array/chunk.ts"],"names":[],"mappings":"AAOA,MAAM,CAAC,MAAM,KAAK,GAAG,CACnB,KAAQ,EACR,CAAI,EACkB,EAAE;IACxB,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,gDAAgD;IAChD,MAAM,MAAM,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC3D,MAAM,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAmB,CAAC;IAC9D,CAAC;IAED,OAAO,MAA8B,CAAC;AACxC,CAAC,CAAC"}
@@ -1,4 +1,4 @@
1
- type CompareFunction<T> = (a: T, b: T) => number;
1
+ import type { CompareFunction } from "../types/array/compareFunction";
2
2
  /**
3
3
  * Sort array using dual-pivot quicksort algorithm
4
4
  * More efficient than traditional quicksort for arrays with many duplicate values
@@ -13,4 +13,3 @@ type CompareFunction<T> = (a: T, b: T) => number;
13
13
  * dualPivotQuickSort(['banana', 'apple', 'orange']); // ['apple', 'banana', 'orange']
14
14
  */
15
15
  export declare const dualPivotQuickSort: <T>(array: T[], compareFunction?: CompareFunction<T>, startIndex?: number, endIndex?: number, insertionSortThreshold?: number) => T[];
16
- export {};
@@ -1,4 +1,6 @@
1
1
  import { compareFunctionDefault } from "./compareFunctionDefault";
2
+ import { applyInsertionSortIfNeeded } from "./sortingHelpers/applyInsertionSortIfNeeded";
3
+ import { validateRange } from "./sortingHelpers/rangeValidator";
2
4
  /**
3
5
  * Get the median of three elements in the array
4
6
  * @param array - The input array
@@ -83,24 +85,6 @@ const partition = (array, low, high, compareFunction) => {
83
85
  [array[high], array[right]] = [array[right], array[high]];
84
86
  return { leftPivotIndex: left, rightPivotIndex: right };
85
87
  };
86
- /**
87
- * Sort small arrays using selection sort
88
- * @param array - Array to be sorted
89
- * @param start - Starting index
90
- * @param end - Ending index
91
- * @param compareFunction - Comparison function
92
- */
93
- const insertionSort = (array, start, end, compareFunction) => {
94
- for (let index = start + 1; index <= end; index++) {
95
- const current = array[index];
96
- let index_ = index - 1;
97
- while (index_ >= start && compareFunction(array[index_], current) > 0) {
98
- array[index_ + 1] = array[index_];
99
- index_--;
100
- }
101
- array[index_ + 1] = current;
102
- }
103
- };
104
88
  /**
105
89
  * Internal implementation of dual-pivot quicksort
106
90
  * @param array - Array to be sorted
@@ -110,9 +94,7 @@ const insertionSort = (array, start, end, compareFunction) => {
110
94
  * @param insertionSortThreshold - Threshold for switching to insertion sort
111
95
  */
112
96
  const sortRange = (array, start, end, compareFunction, insertionSortThreshold) => {
113
- // Use insertion sort for small arrays
114
- if (end - start + 1 <= insertionSortThreshold) {
115
- insertionSort(array, start, end, compareFunction);
97
+ if (applyInsertionSortIfNeeded(array, start, end, compareFunction, insertionSortThreshold)) {
116
98
  return;
117
99
  }
118
100
  // Get partition indices
@@ -140,11 +122,8 @@ const sortRange = (array, start, end, compareFunction, insertionSortThreshold) =
140
122
  * dualPivotQuickSort(['banana', 'apple', 'orange']); // ['apple', 'banana', 'orange']
141
123
  */
142
124
  export const dualPivotQuickSort = (array, compareFunction = (compareFunctionDefault), startIndex = 0, endIndex = array.length - 1, insertionSortThreshold = 10) => {
143
- // Validate and adjust indices
144
- const validStartIndex = Math.max(0, Math.min(startIndex, array.length - 1));
145
- const validEndIndex = Math.max(validStartIndex, Math.min(endIndex, array.length - 1));
146
- // Sort array if valid range exists
147
- if (validEndIndex >= validStartIndex) {
125
+ const { startIndex: validStartIndex, endIndex: validEndIndex, shouldSort, } = validateRange(array, startIndex, endIndex);
126
+ if (shouldSort) {
148
127
  sortRange(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
149
128
  }
150
129
  return array;
@@ -1 +1 @@
1
- {"version":3,"file":"dualPivotQuickSort.js","sourceRoot":"","sources":["../../src/Array/dualPivotQuickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AASlE;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CACpB,KAAU,EACV,CAAS,EACT,CAAS,EACT,CAAS,EACT,eAAmC,EAC3B,EAAE;IACV,uCAAuC;IACvC,MAAM,MAAM,GAAG;QACb,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC7B,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;QAC7B,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE;KAC9B,CAAC;IAEF,6CAA6C;IAC7C,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACzD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;AACzB,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG,CAChB,KAAU,EACV,GAAW,EACX,IAAY,EACZ,eAAmC,EAClB,EAAE;IACnB,0BAA0B;IAC1B,MAAM,MAAM,GAAG,IAAI,GAAG,GAAG,CAAC;IAC1B,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;IAEhD,+BAA+B;IAC/B,MAAM,cAAc,GAAG,aAAa,CAClC,KAAK,EACL,GAAG,EACH,GAAG,GA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,GAAG,CAChC,KAAU,EACV,kBAAsC,CAAA,sBAAyB,CAAA,EAC/D,UAAU,GAAG,CAAC,EACd,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAC3B,sBAAsB,GAAG,EAAE,EACtB,EAAE;IACP,MAAM,EACJ,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,aAAa,EACvB,UAAU,GACX,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE/C,IAAI,UAAU,EAAE,CAAC;QACf,SAAS,CACP,KAAK,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -9,13 +9,14 @@
9
9
  * groupBy(["apple", "banana", "carrot"], (str) => str[0]); // { 'a': ['apple'], 'b': ['banana'], 'c': ['carrot'] }
10
10
  */
11
11
  export const groupBy = (array, iteratee) => {
12
- return array.reduce((accumulator, value, index, array) => {
12
+ const result = Object.create(null);
13
+ const length = array.length;
14
+ for (let index = 0; index < length; index++) {
15
+ const value = array[index];
13
16
  const key = iteratee(value, index, array);
14
- if (!accumulator[key]) {
15
- accumulator[key] = [];
16
- }
17
- accumulator[key].push(value);
18
- return accumulator;
19
- }, {});
17
+ // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
18
+ (result[key] || (result[key] = [])).push(value);
19
+ }
20
+ return result;
20
21
  };
21
22
  //# sourceMappingURL=groupBy.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"groupBy.js","sourceRoot":"","sources":["../../src/Array/groupBy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAU,EACV,QAAoD,EACpC,EAAE;IAClB,OAAO,KAAK,CAAC,MAAM,CACjB,CAAC,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE;QACnC,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,WAAW,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC;QACxB,CAAC;QACD,WAAW,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC7B,OAAO,WAAW,CAAC;IACrB,CAAC,EACD,EAAoB,CACrB,CAAC;AACJ,CAAC,CAAC"}
1
+ {"version":3,"file":"groupBy.js","sourceRoot":"","sources":["../../src/Array/groupBy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,KAAU,EACV,QAAoD,EACpC,EAAE;IAClB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACnC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC;IAC5B,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC5C,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC;QAC3B,MAAM,GAAG,GAAG,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC1C,oEAAoE;QACpE,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -20,5 +20,6 @@ export * from "./shuffle";
20
20
  export * from "./shuffle2DArray";
21
21
  export * from "./sum";
22
22
  export * from "./timSort";
23
+ export * from "./ultraNumberSort";
23
24
  export * from "./zip";
24
25
  export * from "./zipLongest";
@@ -20,6 +20,7 @@ export * from "./shuffle";
20
20
  export * from "./shuffle2DArray";
21
21
  export * from "./sum";
22
22
  export * from "./timSort";
23
+ export * from "./ultraNumberSort";
23
24
  export * from "./zip";
24
25
  export * from "./zipLongest";
25
26
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Array/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/Array/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,sBAAsB,CAAC;AACrC,cAAc,SAAS,CAAC;AACxB,cAAc,uBAAuB,CAAC;AACtC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,OAAO,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,OAAO,CAAC;AACtB,cAAc,WAAW,CAAC;AAC1B,cAAc,mBAAmB,CAAC;AAClC,cAAc,OAAO,CAAC;AACtB,cAAc,cAAc,CAAC"}
@@ -1,4 +1,6 @@
1
1
  import { compareFunctionDefault } from "./compareFunctionDefault";
2
+ import { applyInsertionSortIfNeeded } from "./sortingHelpers/applyInsertionSortIfNeeded";
3
+ import { validateRange } from "./sortingHelpers/rangeValidator";
2
4
  /**
3
5
  * Finds the median value among three elements in the array
4
6
  * @param array The array containing the elements
@@ -54,25 +56,6 @@ const partition = (array, low, high, compareFunction) => {
54
56
  [array[left], array[right]] = [array[right], array[left]];
55
57
  }
56
58
  };
57
- /**
58
- * Sorts a portion of the array using insertion sort algorithm
59
- * @param array Array to sort
60
- * @param low Starting index of the range to sort
61
- * @param high Ending index of the range to sort
62
- * @param compareFunction Function to compare elements
63
- */
64
- const insertionSort = (array, low, high, compareFunction) => {
65
- for (let index = low + 1; index <= high; index++) {
66
- const key = array[index];
67
- let currentIndex = index - 1;
68
- while (currentIndex >= low &&
69
- compareFunction(array[currentIndex], key) > 0) {
70
- array[currentIndex + 1] = array[currentIndex];
71
- currentIndex--;
72
- }
73
- array[currentIndex + 1] = key;
74
- }
75
- };
76
59
  /**
77
60
  * Internal implementation of the quicksort algorithm with tail-call optimization
78
61
  * @param array Array to sort
@@ -85,8 +68,7 @@ const sortImpl = (array, lowInit, highInit, compareFunction, insertionSortThresh
85
68
  let low = lowInit;
86
69
  let high = highInit;
87
70
  while (low < high) {
88
- if (high - low < insertionSortThreshold) {
89
- insertionSort(array, low, high, compareFunction);
71
+ if (applyInsertionSortIfNeeded(array, low, high, compareFunction, insertionSortThreshold)) {
90
72
  return;
91
73
  }
92
74
  const pivotIndex = partition(array, low, high, compareFunction);
@@ -114,10 +96,10 @@ const sortImpl = (array, lowInit, highInit, compareFunction, insertionSortThresh
114
96
  * quickSort(['b', 'a', 'c']); // ['a', 'b', 'c']
115
97
  */
116
98
  export const quickSort = (array, compareFunction = (compareFunctionDefault), startIndex = 0, endIndex = array.length - 1, insertionSortThreshold = 10) => {
117
- // Only sort within valid range
118
- const validStartIndex = Math.max(0, Math.min(startIndex, array.length - 1));
119
- const validEndIndex = Math.max(validStartIndex, Math.min(endIndex, array.length - 1));
120
- sortImpl(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
99
+ const { startIndex: validStartIndex, endIndex: validEndIndex, shouldSort, } = validateRange(array, startIndex, endIndex);
100
+ if (shouldSort) {
101
+ sortImpl(array, validStartIndex, validEndIndex, compareFunction, insertionSortThreshold);
102
+ }
121
103
  return array;
122
104
  };
123
105
  //# sourceMappingURL=quickSort.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"quickSort.js","sourceRoot":"","sources":["../../src/Array/quickSort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAIlE;;;;;;;;GAQG;AACH,MAAM,aAAa,GAAG,CACpB,KAAU,EACV,CAAS,EACT,CAAS,EACT,CAAS,EACT,eAAmC,EAChC,EAAE;IACL,MAAM,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/C,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QACX,MAAM,EAAE,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/C,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;YACX,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;QACD,IAAI,eAAe,CAAC,KAAK,CAAC,CAAC,CAA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ACf,sBAAsB,CACvB,EACD,CAAC;YACD,OAAO;QACT,CAAC;QACD,MAAM,UAAU,GAAG,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,eAAe,CAAC,CAAC;QAChE,IAAI,UAAU,GAAG,GAAG,GAAG,IAAI,GAAG,UAAU,EAAE,CAAC;YACzC,QAAQ,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,sBAAsB,CAAC,CAAC;YAC1E,GAAG,GAAG,UAAU,GAAG,CAAC,CAAC;QACvB,CAAC;aAAM,CAAC;YACN,QAAQ,CACN,KAAK,EACL,UAAU,GAAG,CAAC,EACd,IAAI,EACJ,eAAe,EACf,sBAAsB,CACvB,CAAC;YACF,IAAI,GAAG,UAAU,CAAC;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,KAAU,EACV,kBAAsC,CAAA,sBAAyB,CAAA,EAC/D,UAAU,GAAG,CAAC,EACd,QAAQ,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAC3B,sBAAsB,GAAG,EAAE,EACtB,EAAE;IACP,MAAM,EACJ,UAAU,EAAE,eAAe,EAC3B,QAAQ,EAAE,aAAa,EACvB,UAAU,GACX,GAAG,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;IAE/C,IAAI,UAAU,EAAE,CAAC;QACf,QAAQ,CACN,KAAK,EACL,eAAe,EACf,aAAa,EACb,eAAe,EACf,sBAAsB,CACvB,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { CompareFunction } from "../../types/array/compareFunction";
2
+ /**
3
+ * Checks if a partition is small enough to apply insertion sort and applies it if so.
4
+ *
5
+ * @template T The type of elements in the array.
6
+ * @param {T[]} array The array containing the partition.
7
+ * @param {number} low The starting index of the partition.
8
+ * @param {number} high The ending index of the partition.
9
+ * @param {CompareFunction<T>} compareFunction The function to compare elements.
10
+ * @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
11
+ * @returns {boolean} True if insertion sort was applied, false otherwise.
12
+ */
13
+ export declare const applyInsertionSortIfNeeded: <T>(array: T[], low: number, high: number, compareFunction: CompareFunction<T>, insertionSortThreshold: number) => boolean;
@@ -0,0 +1,20 @@
1
+ import { insertionSort } from "../../Array/insertionSort";
2
+ /**
3
+ * Checks if a partition is small enough to apply insertion sort and applies it if so.
4
+ *
5
+ * @template T The type of elements in the array.
6
+ * @param {T[]} array The array containing the partition.
7
+ * @param {number} low The starting index of the partition.
8
+ * @param {number} high The ending index of the partition.
9
+ * @param {CompareFunction<T>} compareFunction The function to compare elements.
10
+ * @param {number} insertionSortThreshold The size threshold for switching to insertion sort.
11
+ * @returns {boolean} True if insertion sort was applied, false otherwise.
12
+ */
13
+ export const applyInsertionSortIfNeeded = (array, low, high, compareFunction, insertionSortThreshold) => {
14
+ if (high - low + 1 <= insertionSortThreshold) {
15
+ insertionSort(array, compareFunction, low, high);
16
+ return true;
17
+ }
18
+ return false;
19
+ };
20
+ //# sourceMappingURL=applyInsertionSortIfNeeded.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyInsertionSortIfNeeded.js","sourceRoot":"","sources":["../../../src/Array/sortingHelpers/applyInsertionSortIfNeeded.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,KAAU,EACV,GAAW,EACX,IAAY,EACZ,eAAmC,EACnC,sBAA8B,EACrB,EAAE;IACX,IAAI,IAAI,GAAG,GAAG,GAAG,CAAC,IAAI,sBAAsB,EAAE,CAAC;QAC7C,aAAa,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACjD,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC"}