@develia/commons 0.4.24 → 0.4.25

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 (361) hide show
  1. package/dist/array.d.ts.map +1 -0
  2. package/dist/array.js.map +1 -0
  3. package/dist/async-pool-executor.d.ts.map +1 -0
  4. package/dist/async-pool-executor.js.map +1 -0
  5. package/dist/browser/form-utilities.d.ts.map +1 -0
  6. package/dist/browser/form-utilities.js.map +1 -0
  7. package/dist/browser/geo-location.d.ts.map +1 -0
  8. package/dist/browser/geo-location.js.map +1 -0
  9. package/dist/browser/index.d.ts.map +1 -0
  10. package/dist/browser/index.js.map +1 -0
  11. package/dist/browser/native-bridge.d.ts.map +1 -0
  12. package/dist/browser/native-bridge.js.map +1 -0
  13. package/dist/cancellable-promise.d.ts.map +1 -0
  14. package/dist/cancellable-promise.js.map +1 -0
  15. package/dist/clean-url-search-params.d.ts.map +1 -0
  16. package/dist/clean-url-search-params.js.map +1 -0
  17. package/dist/collections/cache-dictionary.d.ts.map +1 -0
  18. package/dist/collections/cache-dictionary.js.map +1 -0
  19. package/dist/collections/default-map.d.ts.map +1 -0
  20. package/dist/collections/default-map.js.map +1 -0
  21. package/dist/collections/default-weak-map.d.ts.map +1 -0
  22. package/dist/collections/default-weak-map.js.map +1 -0
  23. package/dist/collections/from.d.ts.map +1 -0
  24. package/dist/collections/from.js.map +1 -0
  25. package/dist/collections/index.d.ts.map +1 -0
  26. package/dist/collections/index.js.map +1 -0
  27. package/dist/debouncer.d.ts.map +1 -0
  28. package/dist/debouncer.js.map +1 -0
  29. package/dist/draft.d.ts.map +1 -0
  30. package/dist/draft.js.map +1 -0
  31. package/dist/event-bus.d.ts.map +1 -0
  32. package/dist/event-bus.js.map +1 -0
  33. package/dist/functions.d.ts.map +1 -0
  34. package/dist/functions.js.map +1 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js.map +1 -0
  37. package/dist/key-value-pair.d.ts.map +1 -0
  38. package/dist/key-value-pair.js.map +1 -0
  39. package/dist/keyed-debouncer.d.ts.map +1 -0
  40. package/dist/keyed-debouncer.js.map +1 -0
  41. package/dist/lazy.d.ts.map +1 -0
  42. package/dist/lazy.js.map +1 -0
  43. package/dist/math.d.ts.map +1 -0
  44. package/dist/math.js.map +1 -0
  45. package/dist/order.d.ts.map +1 -0
  46. package/dist/order.js.map +1 -0
  47. package/dist/parse.d.ts.map +1 -0
  48. package/dist/parse.js.map +1 -0
  49. package/dist/patch.d.ts.map +1 -0
  50. package/dist/patch.js.map +1 -0
  51. package/dist/range.d.ts.map +1 -0
  52. package/dist/range.js.map +1 -0
  53. package/dist/result.d.ts.map +1 -0
  54. package/dist/result.js.map +1 -0
  55. package/dist/stopwatch.d.ts.map +1 -0
  56. package/dist/stopwatch.js.map +1 -0
  57. package/dist/string.d.ts.map +1 -0
  58. package/dist/string.js.map +1 -0
  59. package/dist/timer.d.ts.map +1 -0
  60. package/dist/timer.js.map +1 -0
  61. package/dist/timespan.d.ts.map +1 -0
  62. package/dist/timespan.js.map +1 -0
  63. package/dist/triggers.d.ts.map +1 -0
  64. package/dist/triggers.js.map +1 -0
  65. package/dist/type-code.d.ts.map +1 -0
  66. package/dist/type-code.js.map +1 -0
  67. package/dist/type.d.ts.map +1 -0
  68. package/dist/type.js.map +1 -0
  69. package/dist/types.d.ts.map +1 -0
  70. package/dist/types.js.map +1 -0
  71. package/dist/utilities.d.ts.map +1 -0
  72. package/dist/utilities.js.map +1 -0
  73. package/package.json +13 -62
  74. package/dist/cjs/array.js +0 -106
  75. package/dist/cjs/array.js.map +0 -1
  76. package/dist/cjs/async-pool-executor.js +0 -79
  77. package/dist/cjs/async-pool-executor.js.map +0 -1
  78. package/dist/cjs/browser/form-utilities.js +0 -162
  79. package/dist/cjs/browser/form-utilities.js.map +0 -1
  80. package/dist/cjs/browser/geo-location.js +0 -78
  81. package/dist/cjs/browser/geo-location.js.map +0 -1
  82. package/dist/cjs/browser/index.js +0 -99
  83. package/dist/cjs/browser/index.js.map +0 -1
  84. package/dist/cjs/browser/native-bridge.js +0 -81
  85. package/dist/cjs/browser/native-bridge.js.map +0 -1
  86. package/dist/cjs/cancellable-promise.js +0 -81
  87. package/dist/cjs/cancellable-promise.js.map +0 -1
  88. package/dist/cjs/clean-url-search-params.js +0 -34
  89. package/dist/cjs/clean-url-search-params.js.map +0 -1
  90. package/dist/cjs/collections/cache-dictionary.js +0 -102
  91. package/dist/cjs/collections/cache-dictionary.js.map +0 -1
  92. package/dist/cjs/collections/default-map.js +0 -45
  93. package/dist/cjs/collections/default-map.js.map +0 -1
  94. package/dist/cjs/collections/default-weak-map.js +0 -46
  95. package/dist/cjs/collections/default-weak-map.js.map +0 -1
  96. package/dist/cjs/collections/from.js +0 -778
  97. package/dist/cjs/collections/from.js.map +0 -1
  98. package/dist/cjs/collections/index.js +0 -15
  99. package/dist/cjs/collections/index.js.map +0 -1
  100. package/dist/cjs/debouncer.js +0 -121
  101. package/dist/cjs/debouncer.js.map +0 -1
  102. package/dist/cjs/draft.js +0 -225
  103. package/dist/cjs/draft.js.map +0 -1
  104. package/dist/cjs/event-bus.js +0 -71
  105. package/dist/cjs/event-bus.js.map +0 -1
  106. package/dist/cjs/functions.js +0 -262
  107. package/dist/cjs/functions.js.map +0 -1
  108. package/dist/cjs/index.js +0 -84
  109. package/dist/cjs/index.js.map +0 -1
  110. package/dist/cjs/key-value-pair.js +0 -22
  111. package/dist/cjs/key-value-pair.js.map +0 -1
  112. package/dist/cjs/keyed-debouncer.js +0 -144
  113. package/dist/cjs/keyed-debouncer.js.map +0 -1
  114. package/dist/cjs/lazy.js +0 -29
  115. package/dist/cjs/lazy.js.map +0 -1
  116. package/dist/cjs/math.js +0 -37
  117. package/dist/cjs/math.js.map +0 -1
  118. package/dist/cjs/order.js +0 -9
  119. package/dist/cjs/order.js.map +0 -1
  120. package/dist/cjs/parse.js +0 -174
  121. package/dist/cjs/parse.js.map +0 -1
  122. package/dist/cjs/patch.js +0 -52
  123. package/dist/cjs/patch.js.map +0 -1
  124. package/dist/cjs/range.js +0 -154
  125. package/dist/cjs/range.js.map +0 -1
  126. package/dist/cjs/result.js +0 -3
  127. package/dist/cjs/result.js.map +0 -1
  128. package/dist/cjs/stopwatch.js +0 -46
  129. package/dist/cjs/stopwatch.js.map +0 -1
  130. package/dist/cjs/string.js +0 -154
  131. package/dist/cjs/string.js.map +0 -1
  132. package/dist/cjs/timer.js +0 -57
  133. package/dist/cjs/timer.js.map +0 -1
  134. package/dist/cjs/timespan.js +0 -367
  135. package/dist/cjs/timespan.js.map +0 -1
  136. package/dist/cjs/triggers.js +0 -103
  137. package/dist/cjs/triggers.js.map +0 -1
  138. package/dist/cjs/type-code.js +0 -18
  139. package/dist/cjs/type-code.js.map +0 -1
  140. package/dist/cjs/type.js +0 -296
  141. package/dist/cjs/type.js.map +0 -1
  142. package/dist/cjs/types.js +0 -3
  143. package/dist/cjs/types.js.map +0 -1
  144. package/dist/cjs/utilities.js +0 -621
  145. package/dist/cjs/utilities.js.map +0 -1
  146. package/dist/esm/array.js.map +0 -1
  147. package/dist/esm/async-pool-executor.js.map +0 -1
  148. package/dist/esm/browser/form-utilities.js.map +0 -1
  149. package/dist/esm/browser/geo-location.js.map +0 -1
  150. package/dist/esm/browser/index.js.map +0 -1
  151. package/dist/esm/browser/native-bridge.js.map +0 -1
  152. package/dist/esm/cancellable-promise.js.map +0 -1
  153. package/dist/esm/clean-url-search-params.js.map +0 -1
  154. package/dist/esm/collections/cache-dictionary.js.map +0 -1
  155. package/dist/esm/collections/default-map.js.map +0 -1
  156. package/dist/esm/collections/default-weak-map.js.map +0 -1
  157. package/dist/esm/collections/from.js.map +0 -1
  158. package/dist/esm/collections/index.js.map +0 -1
  159. package/dist/esm/debouncer.js.map +0 -1
  160. package/dist/esm/draft.js.map +0 -1
  161. package/dist/esm/event-bus.js.map +0 -1
  162. package/dist/esm/functions.js.map +0 -1
  163. package/dist/esm/index.js.map +0 -1
  164. package/dist/esm/key-value-pair.js.map +0 -1
  165. package/dist/esm/keyed-debouncer.js.map +0 -1
  166. package/dist/esm/lazy.js.map +0 -1
  167. package/dist/esm/math.js.map +0 -1
  168. package/dist/esm/order.js.map +0 -1
  169. package/dist/esm/parse.js.map +0 -1
  170. package/dist/esm/patch.js.map +0 -1
  171. package/dist/esm/range.js.map +0 -1
  172. package/dist/esm/result.js.map +0 -1
  173. package/dist/esm/stopwatch.js.map +0 -1
  174. package/dist/esm/string.js.map +0 -1
  175. package/dist/esm/timer.js.map +0 -1
  176. package/dist/esm/timespan.js.map +0 -1
  177. package/dist/esm/triggers.js.map +0 -1
  178. package/dist/esm/type-code.js.map +0 -1
  179. package/dist/esm/type.js.map +0 -1
  180. package/dist/esm/types.js.map +0 -1
  181. package/dist/esm/utilities.js.map +0 -1
  182. package/dist/types/array.d.ts.map +0 -1
  183. package/dist/types/async-pool-executor.d.ts.map +0 -1
  184. package/dist/types/browser/form-utilities.d.ts.map +0 -1
  185. package/dist/types/browser/geo-location.d.ts.map +0 -1
  186. package/dist/types/browser/index.d.ts.map +0 -1
  187. package/dist/types/browser/native-bridge.d.ts.map +0 -1
  188. package/dist/types/cancellable-promise.d.ts.map +0 -1
  189. package/dist/types/clean-url-search-params.d.ts.map +0 -1
  190. package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
  191. package/dist/types/collections/default-map.d.ts.map +0 -1
  192. package/dist/types/collections/default-weak-map.d.ts.map +0 -1
  193. package/dist/types/collections/from.d.ts.map +0 -1
  194. package/dist/types/collections/index.d.ts.map +0 -1
  195. package/dist/types/debouncer.d.ts.map +0 -1
  196. package/dist/types/draft.d.ts.map +0 -1
  197. package/dist/types/event-bus.d.ts.map +0 -1
  198. package/dist/types/functions.d.ts.map +0 -1
  199. package/dist/types/index.d.ts.map +0 -1
  200. package/dist/types/key-value-pair.d.ts.map +0 -1
  201. package/dist/types/keyed-debouncer.d.ts.map +0 -1
  202. package/dist/types/lazy.d.ts.map +0 -1
  203. package/dist/types/math.d.ts.map +0 -1
  204. package/dist/types/order.d.ts.map +0 -1
  205. package/dist/types/parse.d.ts.map +0 -1
  206. package/dist/types/patch.d.ts.map +0 -1
  207. package/dist/types/range.d.ts.map +0 -1
  208. package/dist/types/result.d.ts.map +0 -1
  209. package/dist/types/stopwatch.d.ts.map +0 -1
  210. package/dist/types/string.d.ts.map +0 -1
  211. package/dist/types/timer.d.ts.map +0 -1
  212. package/dist/types/timespan.d.ts.map +0 -1
  213. package/dist/types/triggers.d.ts.map +0 -1
  214. package/dist/types/type-code.d.ts.map +0 -1
  215. package/dist/types/type.d.ts.map +0 -1
  216. package/dist/types/types.d.ts.map +0 -1
  217. package/dist/types/utilities.d.ts.map +0 -1
  218. package/dist/web/array.js +0 -98
  219. package/dist/web/array.js.map +0 -1
  220. package/dist/web/async-pool-executor.js +0 -76
  221. package/dist/web/async-pool-executor.js.map +0 -1
  222. package/dist/web/browser/form-utilities.js +0 -155
  223. package/dist/web/browser/form-utilities.js.map +0 -1
  224. package/dist/web/browser/geo-location.js +0 -75
  225. package/dist/web/browser/geo-location.js.map +0 -1
  226. package/dist/web/browser/index.js +0 -75
  227. package/dist/web/browser/index.js.map +0 -1
  228. package/dist/web/browser/native-bridge.js +0 -78
  229. package/dist/web/browser/native-bridge.js.map +0 -1
  230. package/dist/web/cancellable-promise.js +0 -78
  231. package/dist/web/cancellable-promise.js.map +0 -1
  232. package/dist/web/clean-url-search-params.js +0 -31
  233. package/dist/web/clean-url-search-params.js.map +0 -1
  234. package/dist/web/collections/cache-dictionary.js +0 -99
  235. package/dist/web/collections/cache-dictionary.js.map +0 -1
  236. package/dist/web/collections/default-map.js +0 -42
  237. package/dist/web/collections/default-map.js.map +0 -1
  238. package/dist/web/collections/default-weak-map.js +0 -43
  239. package/dist/web/collections/default-weak-map.js.map +0 -1
  240. package/dist/web/collections/from.js +0 -770
  241. package/dist/web/collections/from.js.map +0 -1
  242. package/dist/web/collections/index.js +0 -5
  243. package/dist/web/collections/index.js.map +0 -1
  244. package/dist/web/debouncer.js +0 -118
  245. package/dist/web/debouncer.js.map +0 -1
  246. package/dist/web/draft.js +0 -222
  247. package/dist/web/draft.js.map +0 -1
  248. package/dist/web/event-bus.js +0 -66
  249. package/dist/web/event-bus.js.map +0 -1
  250. package/dist/web/functions.js +0 -251
  251. package/dist/web/functions.js.map +0 -1
  252. package/dist/web/index.js +0 -40
  253. package/dist/web/index.js.map +0 -1
  254. package/dist/web/key-value-pair.js +0 -19
  255. package/dist/web/key-value-pair.js.map +0 -1
  256. package/dist/web/keyed-debouncer.js +0 -109
  257. package/dist/web/keyed-debouncer.js.map +0 -1
  258. package/dist/web/lazy.js +0 -26
  259. package/dist/web/lazy.js.map +0 -1
  260. package/dist/web/math.js +0 -33
  261. package/dist/web/math.js.map +0 -1
  262. package/dist/web/order.js +0 -7
  263. package/dist/web/order.js.map +0 -1
  264. package/dist/web/parse.js +0 -169
  265. package/dist/web/parse.js.map +0 -1
  266. package/dist/web/patch.js +0 -48
  267. package/dist/web/patch.js.map +0 -1
  268. package/dist/web/range.js +0 -151
  269. package/dist/web/range.js.map +0 -1
  270. package/dist/web/result.js +0 -2
  271. package/dist/web/result.js.map +0 -1
  272. package/dist/web/stopwatch.js +0 -40
  273. package/dist/web/stopwatch.js.map +0 -1
  274. package/dist/web/string.js +0 -142
  275. package/dist/web/string.js.map +0 -1
  276. package/dist/web/timer.js +0 -54
  277. package/dist/web/timer.js.map +0 -1
  278. package/dist/web/timespan.js +0 -365
  279. package/dist/web/timespan.js.map +0 -1
  280. package/dist/web/triggers.js +0 -99
  281. package/dist/web/triggers.js.map +0 -1
  282. package/dist/web/type-code.js +0 -16
  283. package/dist/web/type-code.js.map +0 -1
  284. package/dist/web/type.js +0 -292
  285. package/dist/web/type.js.map +0 -1
  286. package/dist/web/types.js +0 -2
  287. package/dist/web/types.js.map +0 -1
  288. package/dist/web/utilities.js +0 -590
  289. package/dist/web/utilities.js.map +0 -1
  290. /package/dist/{types/array.d.ts → array.d.ts} +0 -0
  291. /package/dist/{esm/array.js → array.js} +0 -0
  292. /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
  293. /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
  294. /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
  295. /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
  296. /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
  297. /package/dist/{esm/browser → browser}/geo-location.js +0 -0
  298. /package/dist/{types/browser → browser}/index.d.ts +0 -0
  299. /package/dist/{esm/browser → browser}/index.js +0 -0
  300. /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
  301. /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
  302. /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
  303. /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
  304. /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
  305. /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
  306. /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
  307. /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
  308. /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
  309. /package/dist/{esm/collections → collections}/default-map.js +0 -0
  310. /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
  311. /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
  312. /package/dist/{types/collections → collections}/from.d.ts +0 -0
  313. /package/dist/{esm/collections → collections}/from.js +0 -0
  314. /package/dist/{types/collections → collections}/index.d.ts +0 -0
  315. /package/dist/{esm/collections → collections}/index.js +0 -0
  316. /package/dist/{types/debouncer.d.ts → debouncer.d.ts} +0 -0
  317. /package/dist/{esm/debouncer.js → debouncer.js} +0 -0
  318. /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
  319. /package/dist/{esm/draft.js → draft.js} +0 -0
  320. /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
  321. /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
  322. /package/dist/{types/functions.d.ts → functions.d.ts} +0 -0
  323. /package/dist/{esm/functions.js → functions.js} +0 -0
  324. /package/dist/{types/index.d.ts → index.d.ts} +0 -0
  325. /package/dist/{esm/index.js → index.js} +0 -0
  326. /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
  327. /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
  328. /package/dist/{types/keyed-debouncer.d.ts → keyed-debouncer.d.ts} +0 -0
  329. /package/dist/{esm/keyed-debouncer.js → keyed-debouncer.js} +0 -0
  330. /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
  331. /package/dist/{esm/lazy.js → lazy.js} +0 -0
  332. /package/dist/{types/math.d.ts → math.d.ts} +0 -0
  333. /package/dist/{esm/math.js → math.js} +0 -0
  334. /package/dist/{types/order.d.ts → order.d.ts} +0 -0
  335. /package/dist/{esm/order.js → order.js} +0 -0
  336. /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
  337. /package/dist/{esm/parse.js → parse.js} +0 -0
  338. /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
  339. /package/dist/{esm/patch.js → patch.js} +0 -0
  340. /package/dist/{types/range.d.ts → range.d.ts} +0 -0
  341. /package/dist/{esm/range.js → range.js} +0 -0
  342. /package/dist/{types/result.d.ts → result.d.ts} +0 -0
  343. /package/dist/{esm/result.js → result.js} +0 -0
  344. /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
  345. /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
  346. /package/dist/{types/string.d.ts → string.d.ts} +0 -0
  347. /package/dist/{esm/string.js → string.js} +0 -0
  348. /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
  349. /package/dist/{esm/timer.js → timer.js} +0 -0
  350. /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
  351. /package/dist/{esm/timespan.js → timespan.js} +0 -0
  352. /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
  353. /package/dist/{esm/triggers.js → triggers.js} +0 -0
  354. /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
  355. /package/dist/{esm/type-code.js → type-code.js} +0 -0
  356. /package/dist/{types/type.d.ts → type.d.ts} +0 -0
  357. /package/dist/{esm/type.js → type.js} +0 -0
  358. /package/dist/{types/types.d.ts → types.d.ts} +0 -0
  359. /package/dist/{esm/types.js → types.js} +0 -0
  360. /package/dist/{types/utilities.d.ts → utilities.d.ts} +0 -0
  361. /package/dist/{esm/utilities.js → utilities.js} +0 -0
package/dist/web/parse.js DELETED
@@ -1,169 +0,0 @@
1
- // ============================================
2
- // HELPERS
3
- // ============================================
4
- function stripThousands(value, separator) {
5
- if (!separator)
6
- return value;
7
- return value.split(separator).join("");
8
- }
9
- function isValidInteger(value, radix) {
10
- if (!Number.isInteger(radix) || radix < 2 || radix > 36)
11
- return false;
12
- const signless = value.replace(/^[+-]/, "");
13
- if (signless === "")
14
- return false;
15
- const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, radix);
16
- return [...signless.toLowerCase()].every((char) => digits.includes(char));
17
- }
18
- // ============================================
19
- // parseInteger
20
- // ============================================
21
- /**
22
- * Safely parses a value into an integer.
23
- * Returns `null` if the value cannot be parsed.
24
- *
25
- * - `null` or `undefined` → `null`
26
- * - `number` → returned as-is (floats are truncated)
27
- * - `string` → parsed with the given options
28
- *
29
- * @param value - The value to parse.
30
- * @param options - Optional parsing configuration.
31
- * @returns The parsed integer, or `null` on failure.
32
- *
33
- * @example
34
- * ```ts
35
- * parseInteger(42) // 42
36
- * parseInteger(3.7) // 3
37
- * parseInteger(null) // null
38
- * parseInteger(undefined) // null
39
- * parseInteger("42") // 42
40
- * parseInteger("1.234.567", { thousandsSeparator: "." }) // 1234567
41
- * parseInteger("FF", { radix: 16 }) // 255
42
- * parseInteger("abc") // null
43
- * ```
44
- */
45
- export function parseInteger(value, options = {}) {
46
- if (value === null || value === undefined)
47
- return null;
48
- if (typeof value === "number") {
49
- return Number.isFinite(value) ? Math.trunc(value) : null;
50
- }
51
- const { radix = 10, thousandsSeparator } = options;
52
- const cleaned = stripThousands(value.trim(), thousandsSeparator);
53
- if (cleaned === "")
54
- return null;
55
- if (!isValidInteger(cleaned, radix))
56
- return null;
57
- const parsed = Number.parseInt(cleaned, radix);
58
- return Number.isNaN(parsed) ? null : parsed;
59
- }
60
- // ============================================
61
- // parseDecimal
62
- // ============================================
63
- /**
64
- * Safely parses a value into a floating-point number.
65
- * Returns `null` if the value cannot be parsed.
66
- *
67
- * - `null` or `undefined` → `null`
68
- * - `number` → returned as-is (if finite)
69
- * - `string` → parsed with the given options
70
- *
71
- * Supports custom decimal and thousands separators, making it suitable
72
- * for both US (`1,234.56`) and EU (`1.234,56`) number formats.
73
- *
74
- * @param value - The value to parse.
75
- * @param options - Optional parsing configuration.
76
- * @returns The parsed float, or `null` on failure.
77
- *
78
- * @example
79
- * ```ts
80
- * parseDecimal(3.14) // 3.14
81
- * parseDecimal(null) // null
82
- * parseDecimal(undefined) // null
83
- * parseDecimal("3.14") // 3.14
84
- * parseDecimal("3,14", { decimalSeparator: "," }) // 3.14
85
- * parseDecimal("1.234,56", { decimalSeparator: ",", thousandsSeparator: "." }) // 1234.56
86
- * parseDecimal("abc") // null
87
- * ```
88
- */
89
- export function parseDecimal(value, options = {}) {
90
- if (value === null || value === undefined)
91
- return null;
92
- if (typeof value === "number") {
93
- return Number.isFinite(value) ? value : null;
94
- }
95
- const { decimalSeparator = ".", thousandsSeparator } = options;
96
- let cleaned = stripThousands(value.trim(), thousandsSeparator);
97
- if (cleaned === "")
98
- return null;
99
- if (decimalSeparator === ",") {
100
- const commaCount = (cleaned.match(/,/g) || []).length;
101
- if (commaCount > 1)
102
- return null;
103
- cleaned = cleaned.replace(",", ".");
104
- }
105
- if (!/^[+-]?\d+(\.\d+)?$/.test(cleaned))
106
- return null;
107
- const parsed = Number.parseFloat(cleaned);
108
- return Number.isNaN(parsed) || !Number.isFinite(parsed) ? null : parsed;
109
- }
110
- // ============================================
111
- // parseBoolean
112
- // ============================================
113
- const DEFAULT_TRUTHY = ["true", "1", "yes", "si", "sí", "on"];
114
- const DEFAULT_FALSY = ["false", "0", "no", "off"];
115
- /**
116
- * Safely parses a value into a boolean.
117
- * Returns `null` if the value cannot be interpreted as boolean.
118
- *
119
- * - `null` or `undefined` → `null`
120
- * - `boolean` → returned as-is
121
- * - `number` → `0` is `false`, any other finite number is `true`
122
- * - `string` → matched case-insensitively against known truthy/falsy values
123
- *
124
- * Default truthy: `"true"`, `"1"`, `"yes"`, `"si"`, `"sí"`, `"on"`
125
- * Default falsy: `"false"`, `"0"`, `"no"`, `"off"`
126
- *
127
- * @param value - The value to parse.
128
- * @param options - Optional parsing configuration.
129
- * @returns The parsed boolean, or `null` on failure.
130
- *
131
- * @example
132
- * ```ts
133
- * parseBoolean(true) // true
134
- * parseBoolean(false) // false
135
- * parseBoolean(1) // true
136
- * parseBoolean(0) // false
137
- * parseBoolean(null) // null
138
- * parseBoolean(undefined) // null
139
- * parseBoolean("yes") // true
140
- * parseBoolean("no") // false
141
- * parseBoolean("sí") // true
142
- * parseBoolean("TRUE") // true
143
- * parseBoolean("oui") // null
144
- * parseBoolean("oui", { extraTruthy: ["oui"] }) // true
145
- * parseBoolean("nein", { extraFalsy: ["nein"] }) // false
146
- * parseBoolean("whatever") // null
147
- * ```
148
- */
149
- export function parseBoolean(value, options = {}) {
150
- if (value === null || value === undefined)
151
- return null;
152
- if (typeof value === "boolean")
153
- return value;
154
- if (typeof value === "number") {
155
- return Number.isFinite(value) ? value !== 0 : null;
156
- }
157
- const { extraTruthy = [], extraFalsy = [] } = options;
158
- const normalized = value.trim().toLowerCase();
159
- if (normalized === "")
160
- return null;
161
- const truthy = [...DEFAULT_TRUTHY, ...extraTruthy.map((s) => s.toLowerCase())];
162
- const falsy = [...DEFAULT_FALSY, ...extraFalsy.map((s) => s.toLowerCase())];
163
- if (truthy.includes(normalized))
164
- return true;
165
- if (falsy.includes(normalized))
166
- return false;
167
- return null;
168
- }
169
- //# sourceMappingURL=parse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":"AAwDA,+CAA+C;AAC/C,UAAU;AACV,+CAA+C;AAE/C,SAAS,cAAc,CAAC,KAAa,EAAE,SAAkB;IACrD,IAAI,CAAC,SAAS;QAAE,OAAO,KAAK,CAAC;IAC7B,OAAO,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,cAAc,CAAC,KAAa,EAAE,KAAa;IAChD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,IAAI,KAAK,GAAG,EAAE;QAAE,OAAO,KAAK,CAAC;IAEtE,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5C,IAAI,QAAQ,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC;IAElC,MAAM,MAAM,GAAG,sCAAsC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;IAEtE,OAAO,CAAC,GAAG,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,+CAA+C;AAC/C,eAAe;AACf,+CAA+C;AAE/C;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,YAAY,CACxB,KAAyC,EACzC,UAA+B,EAAE;IAEjC,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS;QAAE,OAAO,IAAI,CAAC;IAEvD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,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C,IAAI,CAAC;IACvD,CAAC;IAED,MAAM,EAAE,WAAW,GAAG,EAAE,EAAE,UAAU,GAAG,EAAE,EAAE,GAAG,OAAO,CAAC;IAEtD,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC;IAE9C,IAAI,UAAU,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IAEnC,MAAM,MAAM,GAAG,CAAC,GAAG,cAAc,EAAE,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAC/E,MAAM,KAAK,GAAG,CAAC,GAAG,aAAa,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IAE5E,IAAI,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,IAAI,CAAC;IAC7C,IAAI,KAAK,CAAC,QAAQ,CAAC,UAAU,CAAC;QAAE,OAAO,KAAK,CAAC;IAE7C,OAAO,IAAI,CAAC;AAChB,CAAC","sourcesContent":["// parse.ts\n/**\n * Options for {@link parseBoolean}.\n */\nexport interface ParseBooleanOptions {\n /**\n * Additional strings to consider as `true`.\n * These are matched case-insensitively.\n * @example [\"oui\", \"ja\"]\n */\n extraTruthy?: string[];\n\n /**\n * Additional strings to consider as `false`.\n * These are matched case-insensitively.\n * @example [\"non\", \"nein\"]\n */\n extraFalsy?: string[];\n}\n\n/**\n * Options for {@link parseInteger}.\n */\nexport interface ParseIntegerOptions {\n /**\n * Numeric base for conversion.\n * @default 10\n */\n radix?: number;\n\n /**\n * Thousands separator to strip before parsing.\n * @example \".\" for \"1.234.567\" → 1234567\n * @example \",\" for \"1,234,567\" → 1234567\n */\n thousandsSeparator?: string;\n}\n\n/**\n * Options for {@link parseDecimal}.\n */\nexport interface ParseDecimalOptions {\n /**\n * Character used as decimal point.\n * @default \".\"\n */\n decimalSeparator?: \".\" | \",\";\n\n /**\n * Thousands separator to strip before parsing.\n * @example \".\" for \"1.234,56\" (EU format)\n * @example \",\" for \"1,234.56\" (US format)\n */\n thousandsSeparator?: string;\n}\n\n// ============================================\n// HELPERS\n// ============================================\n\nfunction stripThousands(value: string, separator?: string): string {\n if (!separator) return value;\n return value.split(separator).join(\"\");\n}\n\nfunction isValidInteger(value: string, radix: number): boolean {\n if (!Number.isInteger(radix) || radix < 2 || radix > 36) return false;\n\n const signless = value.replace(/^[+-]/, \"\");\n if (signless === \"\") return false;\n\n const digits = \"0123456789abcdefghijklmnopqrstuvwxyz\".slice(0, radix);\n\n return [...signless.toLowerCase()].every((char) => digits.includes(char));\n}\n\n// ============================================\n// parseInteger\n// ============================================\n\n/**\n * Safely parses a value into an integer.\n * Returns `null` if the value cannot be parsed.\n *\n * - `null` or `undefined` → `null`\n * - `number` → returned as-is (floats are truncated)\n * - `string` → parsed with the given options\n *\n * @param value - The value to parse.\n * @param options - Optional parsing configuration.\n * @returns The parsed integer, or `null` on failure.\n *\n * @example\n * ```ts\n * parseInteger(42) // 42\n * parseInteger(3.7) // 3\n * parseInteger(null) // null\n * parseInteger(undefined) // null\n * parseInteger(\"42\") // 42\n * parseInteger(\"1.234.567\", { thousandsSeparator: \".\" }) // 1234567\n * parseInteger(\"FF\", { radix: 16 }) // 255\n * parseInteger(\"abc\") // null\n * ```\n */\nexport function parseInteger(\n value: string | number | null | undefined,\n options: ParseIntegerOptions = {}\n): number | null {\n if (value === null || value === undefined) return null;\n\n if (typeof value === \"number\") {\n return Number.isFinite(value) ? Math.trunc(value) : null;\n }\n\n const { radix = 10, thousandsSeparator } = options;\n\n const cleaned = stripThousands(value.trim(), thousandsSeparator);\n\n if (cleaned === \"\") return null;\n if (!isValidInteger(cleaned, radix)) return null;\n\n const parsed = Number.parseInt(cleaned, radix);\n\n return Number.isNaN(parsed) ? null : parsed;\n}\n\n// ============================================\n// parseDecimal\n// ============================================\n\n/**\n * Safely parses a value into a floating-point number.\n * Returns `null` if the value cannot be parsed.\n *\n * - `null` or `undefined` → `null`\n * - `number` → returned as-is (if finite)\n * - `string` → parsed with the given options\n *\n * Supports custom decimal and thousands separators, making it suitable\n * for both US (`1,234.56`) and EU (`1.234,56`) number formats.\n *\n * @param value - The value to parse.\n * @param options - Optional parsing configuration.\n * @returns The parsed float, or `null` on failure.\n *\n * @example\n * ```ts\n * parseDecimal(3.14) // 3.14\n * parseDecimal(null) // null\n * parseDecimal(undefined) // null\n * parseDecimal(\"3.14\") // 3.14\n * parseDecimal(\"3,14\", { decimalSeparator: \",\" }) // 3.14\n * parseDecimal(\"1.234,56\", { decimalSeparator: \",\", thousandsSeparator: \".\" }) // 1234.56\n * parseDecimal(\"abc\") // null\n * ```\n */\nexport function parseDecimal(\n value: string | number | null | undefined,\n options: ParseDecimalOptions = {}\n): number | null {\n if (value === null || value === undefined) return null;\n\n if (typeof value === \"number\") {\n return Number.isFinite(value) ? value : null;\n }\n\n const { decimalSeparator = \".\", thousandsSeparator } = options;\n\n let cleaned = stripThousands(value.trim(), thousandsSeparator);\n\n if (cleaned === \"\") return null;\n\n if (decimalSeparator === \",\") {\n const commaCount = (cleaned.match(/,/g) || []).length;\n if (commaCount > 1) return null;\n cleaned = cleaned.replace(\",\", \".\");\n }\n\n if (!/^[+-]?\\d+(\\.\\d+)?$/.test(cleaned)) return null;\n\n const parsed = Number.parseFloat(cleaned);\n\n return Number.isNaN(parsed) || !Number.isFinite(parsed) ? null : parsed;\n}\n\n// ============================================\n// parseBoolean\n// ============================================\n\nconst DEFAULT_TRUTHY = [\"true\", \"1\", \"yes\", \"si\", \"sí\", \"on\"];\nconst DEFAULT_FALSY = [\"false\", \"0\", \"no\", \"off\"];\n\n/**\n * Safely parses a value into a boolean.\n * Returns `null` if the value cannot be interpreted as boolean.\n *\n * - `null` or `undefined` → `null`\n * - `boolean` → returned as-is\n * - `number` → `0` is `false`, any other finite number is `true`\n * - `string` → matched case-insensitively against known truthy/falsy values\n *\n * Default truthy: `\"true\"`, `\"1\"`, `\"yes\"`, `\"si\"`, `\"sí\"`, `\"on\"`\n * Default falsy: `\"false\"`, `\"0\"`, `\"no\"`, `\"off\"`\n *\n * @param value - The value to parse.\n * @param options - Optional parsing configuration.\n * @returns The parsed boolean, or `null` on failure.\n *\n * @example\n * ```ts\n * parseBoolean(true) // true\n * parseBoolean(false) // false\n * parseBoolean(1) // true\n * parseBoolean(0) // false\n * parseBoolean(null) // null\n * parseBoolean(undefined) // null\n * parseBoolean(\"yes\") // true\n * parseBoolean(\"no\") // false\n * parseBoolean(\"sí\") // true\n * parseBoolean(\"TRUE\") // true\n * parseBoolean(\"oui\") // null\n * parseBoolean(\"oui\", { extraTruthy: [\"oui\"] }) // true\n * parseBoolean(\"nein\", { extraFalsy: [\"nein\"] }) // false\n * parseBoolean(\"whatever\") // null\n * ```\n */\nexport function parseBoolean(\n value: string | number | boolean | null | undefined,\n options: ParseBooleanOptions = {}\n): boolean | null {\n if (value === null || value === undefined) return null;\n\n if (typeof value === \"boolean\") return value;\n\n if (typeof value === \"number\") {\n return Number.isFinite(value) ? value !== 0 : null;\n }\n\n const { extraTruthy = [], extraFalsy = [] } = options;\n\n const normalized = value.trim().toLowerCase();\n\n if (normalized === \"\") return null;\n\n const truthy = [...DEFAULT_TRUTHY, ...extraTruthy.map((s) => s.toLowerCase())];\n const falsy = [...DEFAULT_FALSY, ...extraFalsy.map((s) => s.toLowerCase())];\n\n if (truthy.includes(normalized)) return true;\n if (falsy.includes(normalized)) return false;\n\n return null;\n}"]}
package/dist/web/patch.js DELETED
@@ -1,48 +0,0 @@
1
- /**
2
- * Devuelve un Map donde:
3
- * - clave -> null (método añadido nuevo)
4
- * - clave -> descriptorOriginal (método sustituido)
5
- */
6
- export function patch(targetOrCtor, fns) {
7
- const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
8
- const result = new Map();
9
- const entries = fns instanceof Map ? [...fns.entries()] : Object.entries(fns);
10
- for (const [key, fn] of entries) {
11
- const prev = Object.getOwnPropertyDescriptor(target, key);
12
- const method = function (...args) {
13
- return fn(this, ...args);
14
- };
15
- try {
16
- Object.defineProperty(target, key, {
17
- value: method,
18
- writable: true,
19
- configurable: true,
20
- enumerable: false,
21
- });
22
- result.set(key, prev ?? null);
23
- }
24
- catch { /* ignorar */
25
- }
26
- }
27
- return result;
28
- }
29
- /**
30
- * Revierte un patch a partir del mapa devuelto por `patch`.
31
- */
32
- export function unpatch(targetOrCtor, changes) {
33
- const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
34
- for (const [key, prev] of changes) {
35
- try {
36
- if (prev === null) {
37
- if (Object.prototype.hasOwnProperty.call(target, key))
38
- delete target[key];
39
- }
40
- else {
41
- Object.defineProperty(target, key, prev);
42
- }
43
- }
44
- catch { /* ignorar */
45
- }
46
- }
47
- }
48
- //# sourceMappingURL=patch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,MAAM,UAAU,KAAK,CACjB,YAAiB,EACjB,GAAmB;IAEnB,MAAM,MAAM,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAE1F,MAAM,MAAM,GAAG,IAAI,GAAG,EAA0C,CAAC;IACjE,MAAM,OAAO,GACT,GAAG,YAAY,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAQ,CAAC;IAEzE,KAAK,MAAM,CAAC,GAAG,EAAE,EAAE,CAAC,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,IAAI,GAAG,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1D,MAAM,MAAM,GAAG,UAAyB,GAAG,IAAe;YACtD,OAAQ,EAAU,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;QACtC,CAAC,CAAC;QACF,IAAI,CAAC;YACD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE;gBAC/B,KAAK,EAAE,MAAM;gBACb,QAAQ,EAAE,IAAI;gBACd,YAAY,EAAE,IAAI;gBAClB,UAAU,EAAE,KAAK;aACpB,CAAC,CAAC;YACH,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,IAAI,IAAI,CAAC,CAAC;QAClC,CAAC;QAAC,MAAM,CAAC,CAAC,aAAa;QACvB,CAAC;IACL,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC;AAYD;;GAEG;AACH,MAAM,UAAU,OAAO,CAAC,YAAiB,EAAE,OAAoD;IAC3F,MAAM,MAAM,GAAG,OAAO,YAAY,KAAK,UAAU,CAAC,CAAC,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC;IAC1F,KAAK,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,IAAI,OAAO,EAAE,CAAC;QAChC,IAAI,CAAC;YACD,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;gBAChB,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC;oBAAE,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC;YAC9E,CAAC;iBAAM,CAAC;gBACJ,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC7C,CAAC;QACL,CAAC;QAAC,MAAM,CAAC,CAAC,aAAa;QACvB,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type {Constructor} from \"./types.js\";\n\nexport type PureMethod<T extends object, A extends any[] = any[], R = any> =\n (obj: T, ...args: A) => R;\n\nexport type PatchSpec<T extends object> =\n | Record<string, PureMethod<T, any[], any>>\n | Map<PropertyKey, PureMethod<T, any[], any>>;\n\n\nexport function patch<C extends Constructor<any>>(\n targetOrCtor: C,\n fns: PatchSpec<InstanceType<C>>\n): Map<PropertyKey, PropertyDescriptor | null>;\n\nexport function patch<T extends object>(\n targetOrCtor: T,\n fns: PatchSpec<T>\n): Map<PropertyKey, PropertyDescriptor | null>;\n\n/**\n * Devuelve un Map donde:\n * - clave -> null (método añadido nuevo)\n * - clave -> descriptorOriginal (método sustituido)\n */\nexport function patch(\n targetOrCtor: any,\n fns: PatchSpec<any>\n): Map<PropertyKey, PropertyDescriptor | null> {\n const target = typeof targetOrCtor === \"function\" ? targetOrCtor.prototype : targetOrCtor;\n\n const result = new Map<PropertyKey, PropertyDescriptor | null>();\n const entries: Array<[PropertyKey, PureMethod<any>]> =\n fns instanceof Map ? [...fns.entries()] : Object.entries(fns) as any;\n\n for (const [key, fn] of entries) {\n const prev = Object.getOwnPropertyDescriptor(target, key);\n const method = function (this: unknown, ...args: unknown[]) {\n return (fn as any)(this, ...args);\n };\n try {\n Object.defineProperty(target, key, {\n value: method,\n writable: true,\n configurable: true,\n enumerable: false,\n });\n result.set(key, prev ?? null);\n } catch { /* ignorar */\n }\n }\n return result;\n}\n\n// Overloads unpatch\nexport function unpatch<C extends Constructor<any>>(\n targetOrCtor: C,\n changes: Map<PropertyKey, PropertyDescriptor | null>\n): void;\nexport function unpatch<T extends object>(\n targetOrCtor: T,\n changes: Map<PropertyKey, PropertyDescriptor | null>\n): void;\n\n/**\n * Revierte un patch a partir del mapa devuelto por `patch`.\n */\nexport function unpatch(targetOrCtor: any, changes: Map<PropertyKey, PropertyDescriptor | null>): void {\n const target = typeof targetOrCtor === \"function\" ? targetOrCtor.prototype : targetOrCtor;\n for (const [key, prev] of changes) {\n try {\n if (prev === null) {\n if (Object.prototype.hasOwnProperty.call(target, key)) delete target[key];\n } else {\n Object.defineProperty(target, key, prev);\n }\n } catch { /* ignorar */\n }\n }\n}"]}
package/dist/web/range.js DELETED
@@ -1,151 +0,0 @@
1
- export default class Range {
2
- /**
3
- * Range constructor.
4
- * @param start
5
- * @param end
6
- */
7
- constructor(start, end) {
8
- this.start = start;
9
- this.end = end;
10
- }
11
- /**
12
- * Finds the intersection between two ranges.
13
- *
14
- * @param other The Range object to intersect with.
15
- * @returns The intersected Range object, or null if there is no intersection.
16
- */
17
- intersect(other) {
18
- const start = (this.start > other.start) ? this.start : other.start;
19
- const end = (this.end < other.end) ? this.end : other.end;
20
- if (start < end) {
21
- return new Range(start, end);
22
- }
23
- else {
24
- return null;
25
- }
26
- }
27
- /**
28
- * Subtract the given range from this range.
29
- *
30
- * @param other The range to subtract from this range.
31
- * @returns An array of Range objects representing the result of the subtraction.
32
- */
33
- subtract(other) {
34
- const result = [];
35
- if (this.start >= other.end || this.end <= other.start) {
36
- result.push(new Range(this.start, this.end));
37
- }
38
- else if (other.start <= this.start && other.end >= this.end) {
39
- return result;
40
- }
41
- else {
42
- if (this.start < other.start) {
43
- result.push(new Range(this.start, other.start));
44
- }
45
- if (this.end > other.end) {
46
- result.push(new Range(other.end, this.end));
47
- }
48
- }
49
- return result;
50
- }
51
- /**
52
- * Determines if the given range overlaps with the current range.
53
- *
54
- * @param other The range to be checked for overlap.
55
- * @returns Returns true if there is an overlap between the ranges, false otherwise.
56
- */
57
- overlaps(other) {
58
- const s1 = this.start;
59
- const e1 = this.end;
60
- const s2 = other.start;
61
- const e2 = other.end;
62
- return (s2 > s1 && s2 < e1 || e2 > s1 && e2 < e1) ||
63
- (s1 > s2 && s1 < e2 || e1 > s2 && e1 < e2) ||
64
- (s1 === s2 && e1 === e2);
65
- }
66
- /**
67
- * Determines whether the specified value is within the range defined by the start and end values.
68
- *
69
- * @param obj The value to check if it is within the range.
70
- * @param inclusive Optional. If set to true, the range boundaries are considered inclusive.
71
- * @returns Returns true if the specified value is within the range, false otherwise.
72
- */
73
- contains(obj, inclusive = true) {
74
- return inclusive ?
75
- (this.start <= obj && this.end >= obj) :
76
- (this.start < obj && this.end > obj);
77
- }
78
- /**
79
- * @returns T
80
- */
81
- getStart() {
82
- return this.start;
83
- }
84
- /**
85
- * @returns T
86
- */
87
- getEnd() {
88
- return this.end;
89
- }
90
- /**
91
- * Finds the intersection between two sets of ranges.
92
- *
93
- * @param ranges1
94
- * @param ranges2
95
- * @returns
96
- */
97
- static intersectRanges(ranges1, ranges2) {
98
- const result = [];
99
- for (const r1 of ranges1) {
100
- for (const r2 of ranges2) {
101
- const intersection = r1.intersect(r2);
102
- if (intersection !== null) {
103
- result.push(intersection);
104
- }
105
- }
106
- }
107
- return result;
108
- }
109
- /**
110
- * Determines if any range in the first set overlaps with any range in the second set.
111
- *
112
- * @param ranges1
113
- * @param ranges2
114
- * @returns
115
- */
116
- static overlapsAny(ranges1, ranges2) {
117
- for (const r1 of ranges1) {
118
- for (const r2 of ranges2) {
119
- if (r1.overlaps(r2)) {
120
- return true;
121
- }
122
- }
123
- }
124
- return false;
125
- }
126
- /**
127
- * Subtracts the second set of ranges from the first set of ranges.
128
- *
129
- * @param ranges1
130
- * @param ranges2
131
- * @returns
132
- */
133
- static subtractRanges(ranges1, ranges2) {
134
- let currentRanges = ranges1;
135
- for (const r2 of ranges2) {
136
- const nextRanges = [];
137
- for (const r1 of currentRanges) {
138
- const subtracted = r1.subtract(r2);
139
- for (const s of subtracted) {
140
- nextRanges.push(s);
141
- }
142
- }
143
- currentRanges = nextRanges;
144
- if (currentRanges.length === 0) {
145
- break;
146
- }
147
- }
148
- return currentRanges;
149
- }
150
- }
151
- //# sourceMappingURL=range.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,OAAO,OAAO,KAAK;IAKtB;;;;OAIG;IACH,YAAY,KAAQ,EAAE,GAAM;QACxB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACnB,CAAC;IAED;;;;;OAKG;IACI,SAAS,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C;CACJ","sourcesContent":["export default class Range<T> {\n\n private readonly start: T;\n private readonly end: T;\n\n /**\n * Range constructor.\n * @param start\n * @param end\n */\n constructor(start: T, end: T) {\n this.start = start;\n this.end = end;\n }\n\n /**\n * Finds the intersection between two ranges.\n *\n * @param other The Range object to intersect with.\n * @returns The intersected Range object, or null if there is no intersection.\n */\n public intersect(other: Range<T>): Range<T> | null {\n const start = (this.start > other.start) ? this.start : other.start;\n const end = (this.end < other.end) ? this.end : other.end;\n\n if (start < end) {\n return new Range(start, end);\n } else {\n return null;\n }\n }\n\n /**\n * Subtract the given range from this range.\n *\n * @param other The range to subtract from this range.\n * @returns An array of Range objects representing the result of the subtraction.\n */\n public subtract(other: Range<T>): Range<T>[] {\n const result: Range<T>[] = [];\n\n if (this.start >= other.end || this.end <= other.start) {\n result.push(new Range(this.start, this.end));\n } else if (other.start <= this.start && other.end >= this.end) {\n return result;\n } else {\n if (this.start < other.start) {\n result.push(new Range(this.start, other.start));\n }\n\n if (this.end > other.end) {\n result.push(new Range(other.end, this.end));\n }\n }\n\n return result;\n }\n\n /**\n * Determines if the given range overlaps with the current range.\n *\n * @param other The range to be checked for overlap.\n * @returns Returns true if there is an overlap between the ranges, false otherwise.\n */\n public overlaps(other: Range<T>): boolean {\n const s1 = this.start;\n const e1 = this.end;\n const s2 = other.start;\n const e2 = other.end;\n\n return (s2 > s1 && s2 < e1 || e2 > s1 && e2 < e1) ||\n (s1 > s2 && s1 < e2 || e1 > s2 && e1 < e2) ||\n (s1 === s2 && e1 === e2);\n }\n\n /**\n * Determines whether the specified value is within the range defined by the start and end values.\n *\n * @param obj The value to check if it is within the range.\n * @param inclusive Optional. If set to true, the range boundaries are considered inclusive.\n * @returns Returns true if the specified value is within the range, false otherwise.\n */\n public contains(obj: T, inclusive: boolean = true): boolean {\n return inclusive ?\n (this.start <= obj && this.end >= obj) :\n (this.start < obj && this.end > obj);\n }\n\n /**\n * @returns T\n */\n public getStart(): T {\n return this.start;\n }\n\n /**\n * @returns T\n */\n public getEnd(): T {\n return this.end;\n }\n\n /**\n * Finds the intersection between two sets of ranges.\n *\n * @param ranges1\n * @param ranges2\n * @returns\n */\n public static intersectRanges<T>(ranges1: Range<T>[], ranges2: Range<T>[]): Range<T>[] {\n const result: Range<T>[] = [];\n for (const r1 of ranges1) {\n for (const r2 of ranges2) {\n const intersection = r1.intersect(r2);\n if (intersection !== null) {\n result.push(intersection);\n }\n }\n }\n return result;\n }\n\n /**\n * Determines if any range in the first set overlaps with any range in the second set.\n *\n * @param ranges1\n * @param ranges2\n * @returns\n */\n public static overlapsAny<T>(ranges1: Range<T>[], ranges2: Range<T>[]): boolean {\n for (const r1 of ranges1) {\n for (const r2 of ranges2) {\n if (r1.overlaps(r2)) {\n return true;\n }\n }\n }\n return false;\n }\n\n /**\n * Subtracts the second set of ranges from the first set of ranges.\n *\n * @param ranges1\n * @param ranges2\n * @returns\n */\n public static subtractRanges<T>(ranges1: Range<T>[], ranges2: Range<T>[]): Range<T>[] {\n let currentRanges = ranges1;\n for (const r2 of ranges2) {\n const nextRanges: Range<T>[] = [];\n for (const r1 of currentRanges) {\n const subtracted = r1.subtract(r2);\n for (const s of subtracted) {\n nextRanges.push(s);\n }\n }\n currentRanges = nextRanges;\n if (currentRanges.length === 0) {\n break;\n }\n }\n return currentRanges;\n }\n}\n"]}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=result.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"result.js","sourceRoot":"","sources":["../../src/result.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * Represents success and failure outputs narrowed by `success`.\n */\nexport type Result<TSuccessOutput, TFailureOutput = undefined> =\n | {readonly success: true; readonly output: TSuccessOutput}\n | {readonly success: false; readonly output?: TFailureOutput};\n"]}
@@ -1,40 +0,0 @@
1
- import TimeSpan from "./timespan.js";
2
- export default class Stopwatch {
3
- constructor() {
4
- this.startTime = null;
5
- this.elapsedTime = null;
6
- }
7
- /*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {
8
- const stopwatch = new Stopwatch();
9
- stopwatch.start();
10
- try {
11
- return callback();
12
- } finally {
13
- stopwatch.stop();
14
- measure.value = stopwatch.getElapsedTime();
15
- }
16
- }*/
17
- start() {
18
- this.startTime = performance.now();
19
- this.elapsedTime = null;
20
- }
21
- stop() {
22
- if (this.startTime !== null) {
23
- this.elapsedTime = performance.now() - this.startTime;
24
- this.startTime = null;
25
- }
26
- }
27
- resume() {
28
- if (this.elapsedTime !== null) {
29
- this.startTime = performance.now() - this.elapsedTime;
30
- this.elapsedTime = null;
31
- }
32
- }
33
- getElapsedTime() {
34
- if (this.startTime !== null) {
35
- return TimeSpan.fromMilliseconds(performance.now() - this.startTime);
36
- }
37
- return TimeSpan.fromMilliseconds(this.elapsedTime ?? 0.0);
38
- }
39
- }
40
- //# sourceMappingURL=stopwatch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stopwatch.js","sourceRoot":"","sources":["../../src/stopwatch.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,eAAe,CAAC;AAErC,MAAM,CAAC,OAAO,OAAO,SAAS;IAA9B;QACY,cAAS,GAAkB,IAAI,CAAC;QAChC,gBAAW,GAAkB,IAAI,CAAC;IAsC9C,CAAC;IApCG;;;;;;;;;OASG;IAEH,KAAK;QACD,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,CAAC;QACnC,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,IAAI;QACA,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC1B,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC;YACtD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAC1B,CAAC;IACL,CAAC;IAED,MAAM;QACF,IAAI,IAAI,CAAC,WAAW,KAAK,IAAI,EAAE,CAAC;YAC5B,IAAI,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC;YACtD,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;QAC5B,CAAC;IACL,CAAC;IAED,cAAc;QACV,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,QAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,QAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC;IAC9D,CAAC;CACJ","sourcesContent":["import TimeSpan from \"./timespan.js\";\n\nexport default class Stopwatch {\n private startTime: number | null = null;\n private elapsedTime: number | null = null;\n\n /*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {\n const stopwatch = new Stopwatch();\n stopwatch.start();\n try {\n return callback();\n } finally {\n stopwatch.stop();\n measure.value = stopwatch.getElapsedTime();\n }\n }*/\n\n start(): void {\n this.startTime = performance.now();\n this.elapsedTime = null;\n }\n\n stop(): void {\n if (this.startTime !== null) {\n this.elapsedTime = performance.now() - this.startTime;\n this.startTime = null;\n }\n }\n\n resume(): void {\n if (this.elapsedTime !== null) {\n this.startTime = performance.now() - this.elapsedTime;\n this.elapsedTime = null;\n }\n }\n\n getElapsedTime(): TimeSpan {\n if (this.startTime !== null) {\n return TimeSpan.fromMilliseconds(performance.now() - this.startTime);\n }\n return TimeSpan.fromMilliseconds(this.elapsedTime ?? 0.0);\n }\n}\n"]}
@@ -1,142 +0,0 @@
1
- /**
2
- * Ensures that a given string has a specific prefix.
3
- *
4
- * @param {string} str - The string to ensure the prefix on.
5
- * @param {string} prefix - The prefix to ensure on the string.
6
- * @return {string} - The resulting string with the ensured prefix.
7
- */
8
- export function ensurePrefix(str, prefix) {
9
- if (!str.startsWith(prefix))
10
- return prefix + str;
11
- return str;
12
- }
13
- /**
14
- * Ensures that a string ends with a specified suffix.
15
- *
16
- * @param {string} str - The original string.
17
- * @param {string} suffix - The suffix to ensure.
18
- * @return {string} - The modified string with the suffix added if it was not already present.
19
- */
20
- export function ensureSuffix(str, suffix) {
21
- if (!str.endsWith(suffix))
22
- return str + suffix;
23
- return str;
24
- }
25
- /**
26
- * Normalizes Unicode whitespaces into single ASCII spaces and removes leading
27
- * and trailing whitespace.
28
- */
29
- export function normalizeWhitespaces(str) {
30
- return str.normalize('NFKC')
31
- .replace(/[\s\u200B\uFEFF]+/gu, ' ')
32
- .trim();
33
- }
34
- /**
35
- * Removes Unicode diacritics while preserving the original letter casing.
36
- *
37
- * @example removeDiacritics('áÁñÑ') // 'aAnN'
38
- */
39
- export function removeDiacritics(str) {
40
- return str
41
- .normalize('NFD')
42
- .replace(/\p{M}+/gu, '');
43
- }
44
- /**
45
- * Formats a string using a template and provided arguments.
46
- *
47
- * @param {string} template - The template string containing placeholders.
48
- * @param {any[]} args - Optional arguments to replace the placeholders in the template.
49
- * @return {string} The formatted string.
50
- */
51
- export function format(template, ...args) {
52
- let regex;
53
- const hasNamedPlaceholders = /{(?!\d+})[^{}]+}/.test(template);
54
- if (args.length === 1 && args[0] !== null && typeof args[0] === 'object' && hasNamedPlaceholders) {
55
- args = args[0];
56
- regex = /{(.+?)}/g;
57
- }
58
- else {
59
- regex = /{(\d+?)}/g;
60
- }
61
- return template.replace(regex, (match, key) => {
62
- return Object.prototype.hasOwnProperty.call(args, key) && typeof args[key] !== 'undefined'
63
- ? args[key]
64
- : "";
65
- });
66
- }
67
- /**
68
- * Splits a string into its constituent words, regardless of the original case
69
- * style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
70
- * space-separated, etc.).
71
- *
72
- * @param {string} str - The string to split into words.
73
- * @return {string[]} - The list of lowercase words extracted from the input.
74
- */
75
- function toWords(str) {
76
- if (!str)
77
- return [];
78
- return str
79
- // Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
80
- .replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, '$1 $2')
81
- // Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
82
- .replace(/(\p{Lu}+)(\p{Lu}\p{Ll})/gu, '$1 $2')
83
- // Replace any non-alphanumeric character with a space
84
- .replace(/[^\p{L}\p{N}]+/gu, ' ')
85
- .trim()
86
- .toLowerCase()
87
- .split(/\s+/)
88
- .filter(Boolean);
89
- }
90
- /**
91
- * Converts a string to snake_case.
92
- *
93
- * @param {string} str - The string to convert.
94
- * @return {string} - The string converted to snake_case.
95
- */
96
- export function toSnakeCase(str) {
97
- return toWords(str).join('_');
98
- }
99
- /**
100
- * Converts a string to kebab-case.
101
- *
102
- * @param {string} str - The string to convert.
103
- * @return {string} - The string converted to kebab-case.
104
- */
105
- export function toKebabCase(str) {
106
- return toWords(str).join('-');
107
- }
108
- /**
109
- * Converts a string to camelCase.
110
- *
111
- * @param {string} str - The string to convert.
112
- * @return {string} - The string converted to camelCase.
113
- */
114
- export function toCamelCase(str) {
115
- const words = toWords(str);
116
- if (words.length === 0)
117
- return '';
118
- return words
119
- .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
120
- .join('');
121
- }
122
- /**
123
- * Converts a string to PascalCase.
124
- *
125
- * @param {string} str - The string to convert.
126
- * @return {string} - The string converted to PascalCase.
127
- */
128
- export function toPascalCase(str) {
129
- return toWords(str)
130
- .map(word => word.charAt(0).toUpperCase() + word.slice(1))
131
- .join('');
132
- }
133
- /**
134
- * Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
135
- *
136
- * @param {string} str - The string to convert.
137
- * @return {string} - The string converted to CONSTANT_CASE.
138
- */
139
- export function toConstantCase(str) {
140
- return toWords(str).join('_').toUpperCase();
141
- }
142
- //# sourceMappingURL=string.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"string.js","sourceRoot":"","sources":["../../src/string.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AACH,MAAM,UAAU,YA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,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SAC/E,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,GAAW;IACpC,OAAO,OAAO,CAAC,GAAG,CAAC;SACd,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;SACzD,IAAI,CAAC,EAAE,CAAC,CAAC;AAClB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,GAAW;IACtC,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;AAChD,CAAC","sourcesContent":["\n/**\n * Ensures that a given string has a specific prefix.\n *\n * @param {string} str - The string to ensure the prefix on.\n * @param {string} prefix - The prefix to ensure on the string.\n * @return {string} - The resulting string with the ensured prefix.\n */\nexport function ensurePrefix(str: string, prefix: string): string {\n if (!str.startsWith(prefix))\n return prefix + str\n return str\n}\n\n\n/**\n * Ensures that a string ends with a specified suffix.\n *\n * @param {string} str - The original string.\n * @param {string} suffix - The suffix to ensure.\n * @return {string} - The modified string with the suffix added if it was not already present.\n */\nexport function ensureSuffix(str: string, suffix: string): string {\n if (!str.endsWith(suffix))\n return str + suffix\n return str\n}\n\n/**\n * Normalizes Unicode whitespaces into single ASCII spaces and removes leading\n * and trailing whitespace.\n */\nexport function normalizeWhitespaces(str: string): string {\n return str.normalize('NFKC')\n .replace(/[\\s\\u200B\\uFEFF]+/gu, ' ')\n .trim()\n}\n\n/**\n * Removes Unicode diacritics while preserving the original letter casing.\n *\n * @example removeDiacritics('áÁñÑ') // 'aAnN'\n */\nexport function removeDiacritics(str: string): string {\n return str\n .normalize('NFD')\n .replace(/\\p{M}+/gu, '')\n}\n\n/**\n * Formats a string using a template and provided arguments.\n *\n * @param {string} template - The template string containing placeholders.\n * @param {any[]} args - Optional arguments to replace the placeholders in the template.\n * @return {string} The formatted string.\n */\nexport function format(template: string, ...args: any[]): string {\n\n let regex: RegExp;\n const hasNamedPlaceholders = /{(?!\\d+})[^{}]+}/.test(template);\n if (args.length === 1 && args[0] !== null && typeof args[0] === 'object' && hasNamedPlaceholders) {\n args = args[0];\n regex = /{(.+?)}/g;\n } else {\n regex = /{(\\d+?)}/g;\n }\n\n return template.replace(regex, (match, key) => {\n return Object.prototype.hasOwnProperty.call(args, key) && typeof args[key] !== 'undefined'\n ? args[key]\n : \"\";\n });\n}\n\n/**\n * Splits a string into its constituent words, regardless of the original case\n * style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,\n * space-separated, etc.).\n *\n * @param {string} str - The string to split into words.\n * @return {string[]} - The list of lowercase words extracted from the input.\n */\nfunction toWords(str: string): string[] {\n if (!str) return [];\n\n return str\n // Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)\n .replace(/([\\p{Ll}\\p{N}])(\\p{Lu})/gu, '$1 $2')\n // Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)\n .replace(/(\\p{Lu}+)(\\p{Lu}\\p{Ll})/gu, '$1 $2')\n // Replace any non-alphanumeric character with a space\n .replace(/[^\\p{L}\\p{N}]+/gu, ' ')\n .trim()\n .toLowerCase()\n .split(/\\s+/)\n .filter(Boolean);\n}\n\n/**\n * Converts a string to snake_case.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to snake_case.\n */\nexport function toSnakeCase(str: string): string {\n return toWords(str).join('_');\n}\n\n/**\n * Converts a string to kebab-case.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to kebab-case.\n */\nexport function toKebabCase(str: string): string {\n return toWords(str).join('-');\n}\n\n/**\n * Converts a string to camelCase.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to camelCase.\n */\nexport function toCamelCase(str: string): string {\n const words = toWords(str);\n if (words.length === 0) return '';\n return words\n .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\n/**\n * Converts a string to PascalCase.\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to PascalCase.\n */\nexport function toPascalCase(str: string): string {\n return toWords(str)\n .map(word => word.charAt(0).toUpperCase() + word.slice(1))\n .join('');\n}\n\n/**\n * Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).\n *\n * @param {string} str - The string to convert.\n * @return {string} - The string converted to CONSTANT_CASE.\n */\nexport function toConstantCase(str: string): string {\n return toWords(str).join('_').toUpperCase();\n}\n"]}