@develia/commons 0.4.23 → 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 (354) 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 +60 -0
  28. package/dist/debouncer.d.ts.map +1 -0
  29. package/dist/debouncer.js +118 -0
  30. package/dist/debouncer.js.map +1 -0
  31. package/dist/draft.d.ts.map +1 -0
  32. package/dist/draft.js.map +1 -0
  33. package/dist/event-bus.d.ts.map +1 -0
  34. package/dist/event-bus.js.map +1 -0
  35. package/dist/{types/functions.d.ts → functions.d.ts} +5 -35
  36. package/dist/functions.d.ts.map +1 -0
  37. package/dist/{esm/functions.js → functions.js} +0 -85
  38. package/dist/functions.js.map +1 -0
  39. package/dist/{types/index.d.ts → index.d.ts} +4 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/{web/index.js → index.js} +2 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/key-value-pair.d.ts.map +1 -0
  44. package/dist/key-value-pair.js.map +1 -0
  45. package/dist/keyed-debouncer.d.ts +56 -0
  46. package/dist/keyed-debouncer.d.ts.map +1 -0
  47. package/dist/keyed-debouncer.js +109 -0
  48. package/dist/keyed-debouncer.js.map +1 -0
  49. package/dist/lazy.d.ts.map +1 -0
  50. package/dist/lazy.js.map +1 -0
  51. package/dist/math.d.ts.map +1 -0
  52. package/dist/math.js.map +1 -0
  53. package/dist/order.d.ts.map +1 -0
  54. package/dist/order.js.map +1 -0
  55. package/dist/parse.d.ts.map +1 -0
  56. package/dist/parse.js.map +1 -0
  57. package/dist/patch.d.ts.map +1 -0
  58. package/dist/patch.js.map +1 -0
  59. package/dist/range.d.ts.map +1 -0
  60. package/dist/range.js.map +1 -0
  61. package/dist/result.d.ts.map +1 -0
  62. package/dist/result.js.map +1 -0
  63. package/dist/stopwatch.d.ts.map +1 -0
  64. package/dist/stopwatch.js.map +1 -0
  65. package/dist/string.d.ts.map +1 -0
  66. package/dist/string.js.map +1 -0
  67. package/dist/timer.d.ts.map +1 -0
  68. package/dist/timer.js.map +1 -0
  69. package/dist/timespan.d.ts.map +1 -0
  70. package/dist/timespan.js.map +1 -0
  71. package/dist/triggers.d.ts.map +1 -0
  72. package/dist/triggers.js.map +1 -0
  73. package/dist/type-code.d.ts.map +1 -0
  74. package/dist/type-code.js.map +1 -0
  75. package/dist/type.d.ts.map +1 -0
  76. package/dist/type.js.map +1 -0
  77. package/dist/types.d.ts.map +1 -0
  78. package/dist/types.js.map +1 -0
  79. package/dist/{types/utilities.d.ts → utilities.d.ts} +8 -3
  80. package/dist/utilities.d.ts.map +1 -0
  81. package/dist/{web/utilities.js → utilities.js} +27 -4
  82. package/dist/utilities.js.map +1 -0
  83. package/package.json +13 -62
  84. package/src/debouncer.ts +135 -0
  85. package/src/functions.ts +5 -114
  86. package/src/index.ts +4 -0
  87. package/src/keyed-debouncer.ts +121 -0
  88. package/src/utilities.ts +30 -4
  89. package/dist/cjs/array.js +0 -106
  90. package/dist/cjs/array.js.map +0 -1
  91. package/dist/cjs/async-pool-executor.js +0 -79
  92. package/dist/cjs/async-pool-executor.js.map +0 -1
  93. package/dist/cjs/browser/form-utilities.js +0 -162
  94. package/dist/cjs/browser/form-utilities.js.map +0 -1
  95. package/dist/cjs/browser/geo-location.js +0 -78
  96. package/dist/cjs/browser/geo-location.js.map +0 -1
  97. package/dist/cjs/browser/index.js +0 -99
  98. package/dist/cjs/browser/index.js.map +0 -1
  99. package/dist/cjs/browser/native-bridge.js +0 -81
  100. package/dist/cjs/browser/native-bridge.js.map +0 -1
  101. package/dist/cjs/cancellable-promise.js +0 -81
  102. package/dist/cjs/cancellable-promise.js.map +0 -1
  103. package/dist/cjs/clean-url-search-params.js +0 -34
  104. package/dist/cjs/clean-url-search-params.js.map +0 -1
  105. package/dist/cjs/collections/cache-dictionary.js +0 -102
  106. package/dist/cjs/collections/cache-dictionary.js.map +0 -1
  107. package/dist/cjs/collections/default-map.js +0 -45
  108. package/dist/cjs/collections/default-map.js.map +0 -1
  109. package/dist/cjs/collections/default-weak-map.js +0 -46
  110. package/dist/cjs/collections/default-weak-map.js.map +0 -1
  111. package/dist/cjs/collections/from.js +0 -778
  112. package/dist/cjs/collections/from.js.map +0 -1
  113. package/dist/cjs/collections/index.js +0 -15
  114. package/dist/cjs/collections/index.js.map +0 -1
  115. package/dist/cjs/draft.js +0 -225
  116. package/dist/cjs/draft.js.map +0 -1
  117. package/dist/cjs/event-bus.js +0 -71
  118. package/dist/cjs/event-bus.js.map +0 -1
  119. package/dist/cjs/functions.js +0 -348
  120. package/dist/cjs/functions.js.map +0 -1
  121. package/dist/cjs/index.js +0 -80
  122. package/dist/cjs/index.js.map +0 -1
  123. package/dist/cjs/key-value-pair.js +0 -22
  124. package/dist/cjs/key-value-pair.js.map +0 -1
  125. package/dist/cjs/lazy.js +0 -29
  126. package/dist/cjs/lazy.js.map +0 -1
  127. package/dist/cjs/math.js +0 -37
  128. package/dist/cjs/math.js.map +0 -1
  129. package/dist/cjs/order.js +0 -9
  130. package/dist/cjs/order.js.map +0 -1
  131. package/dist/cjs/parse.js +0 -174
  132. package/dist/cjs/parse.js.map +0 -1
  133. package/dist/cjs/patch.js +0 -52
  134. package/dist/cjs/patch.js.map +0 -1
  135. package/dist/cjs/range.js +0 -154
  136. package/dist/cjs/range.js.map +0 -1
  137. package/dist/cjs/result.js +0 -3
  138. package/dist/cjs/result.js.map +0 -1
  139. package/dist/cjs/stopwatch.js +0 -46
  140. package/dist/cjs/stopwatch.js.map +0 -1
  141. package/dist/cjs/string.js +0 -154
  142. package/dist/cjs/string.js.map +0 -1
  143. package/dist/cjs/timer.js +0 -57
  144. package/dist/cjs/timer.js.map +0 -1
  145. package/dist/cjs/timespan.js +0 -367
  146. package/dist/cjs/timespan.js.map +0 -1
  147. package/dist/cjs/triggers.js +0 -103
  148. package/dist/cjs/triggers.js.map +0 -1
  149. package/dist/cjs/type-code.js +0 -18
  150. package/dist/cjs/type-code.js.map +0 -1
  151. package/dist/cjs/type.js +0 -296
  152. package/dist/cjs/type.js.map +0 -1
  153. package/dist/cjs/types.js +0 -3
  154. package/dist/cjs/types.js.map +0 -1
  155. package/dist/cjs/utilities.js +0 -598
  156. package/dist/cjs/utilities.js.map +0 -1
  157. package/dist/esm/array.js.map +0 -1
  158. package/dist/esm/async-pool-executor.js.map +0 -1
  159. package/dist/esm/browser/form-utilities.js.map +0 -1
  160. package/dist/esm/browser/geo-location.js.map +0 -1
  161. package/dist/esm/browser/index.js.map +0 -1
  162. package/dist/esm/browser/native-bridge.js.map +0 -1
  163. package/dist/esm/cancellable-promise.js.map +0 -1
  164. package/dist/esm/clean-url-search-params.js.map +0 -1
  165. package/dist/esm/collections/cache-dictionary.js.map +0 -1
  166. package/dist/esm/collections/default-map.js.map +0 -1
  167. package/dist/esm/collections/default-weak-map.js.map +0 -1
  168. package/dist/esm/collections/from.js.map +0 -1
  169. package/dist/esm/collections/index.js.map +0 -1
  170. package/dist/esm/draft.js.map +0 -1
  171. package/dist/esm/event-bus.js.map +0 -1
  172. package/dist/esm/functions.js.map +0 -1
  173. package/dist/esm/index.js +0 -38
  174. package/dist/esm/index.js.map +0 -1
  175. package/dist/esm/key-value-pair.js.map +0 -1
  176. package/dist/esm/lazy.js.map +0 -1
  177. package/dist/esm/math.js.map +0 -1
  178. package/dist/esm/order.js.map +0 -1
  179. package/dist/esm/parse.js.map +0 -1
  180. package/dist/esm/patch.js.map +0 -1
  181. package/dist/esm/range.js.map +0 -1
  182. package/dist/esm/result.js.map +0 -1
  183. package/dist/esm/stopwatch.js.map +0 -1
  184. package/dist/esm/string.js.map +0 -1
  185. package/dist/esm/timer.js.map +0 -1
  186. package/dist/esm/timespan.js.map +0 -1
  187. package/dist/esm/triggers.js.map +0 -1
  188. package/dist/esm/type-code.js.map +0 -1
  189. package/dist/esm/type.js.map +0 -1
  190. package/dist/esm/types.js.map +0 -1
  191. package/dist/esm/utilities.js +0 -567
  192. package/dist/esm/utilities.js.map +0 -1
  193. package/dist/types/array.d.ts.map +0 -1
  194. package/dist/types/async-pool-executor.d.ts.map +0 -1
  195. package/dist/types/browser/form-utilities.d.ts.map +0 -1
  196. package/dist/types/browser/geo-location.d.ts.map +0 -1
  197. package/dist/types/browser/index.d.ts.map +0 -1
  198. package/dist/types/browser/native-bridge.d.ts.map +0 -1
  199. package/dist/types/cancellable-promise.d.ts.map +0 -1
  200. package/dist/types/clean-url-search-params.d.ts.map +0 -1
  201. package/dist/types/collections/cache-dictionary.d.ts.map +0 -1
  202. package/dist/types/collections/default-map.d.ts.map +0 -1
  203. package/dist/types/collections/default-weak-map.d.ts.map +0 -1
  204. package/dist/types/collections/from.d.ts.map +0 -1
  205. package/dist/types/collections/index.d.ts.map +0 -1
  206. package/dist/types/draft.d.ts.map +0 -1
  207. package/dist/types/event-bus.d.ts.map +0 -1
  208. package/dist/types/functions.d.ts.map +0 -1
  209. package/dist/types/index.d.ts.map +0 -1
  210. package/dist/types/key-value-pair.d.ts.map +0 -1
  211. package/dist/types/lazy.d.ts.map +0 -1
  212. package/dist/types/math.d.ts.map +0 -1
  213. package/dist/types/order.d.ts.map +0 -1
  214. package/dist/types/parse.d.ts.map +0 -1
  215. package/dist/types/patch.d.ts.map +0 -1
  216. package/dist/types/range.d.ts.map +0 -1
  217. package/dist/types/result.d.ts.map +0 -1
  218. package/dist/types/stopwatch.d.ts.map +0 -1
  219. package/dist/types/string.d.ts.map +0 -1
  220. package/dist/types/timer.d.ts.map +0 -1
  221. package/dist/types/timespan.d.ts.map +0 -1
  222. package/dist/types/triggers.d.ts.map +0 -1
  223. package/dist/types/type-code.d.ts.map +0 -1
  224. package/dist/types/type.d.ts.map +0 -1
  225. package/dist/types/types.d.ts.map +0 -1
  226. package/dist/types/utilities.d.ts.map +0 -1
  227. package/dist/web/array.js +0 -98
  228. package/dist/web/array.js.map +0 -1
  229. package/dist/web/async-pool-executor.js +0 -76
  230. package/dist/web/async-pool-executor.js.map +0 -1
  231. package/dist/web/browser/form-utilities.js +0 -155
  232. package/dist/web/browser/form-utilities.js.map +0 -1
  233. package/dist/web/browser/geo-location.js +0 -75
  234. package/dist/web/browser/geo-location.js.map +0 -1
  235. package/dist/web/browser/index.js +0 -75
  236. package/dist/web/browser/index.js.map +0 -1
  237. package/dist/web/browser/native-bridge.js +0 -78
  238. package/dist/web/browser/native-bridge.js.map +0 -1
  239. package/dist/web/cancellable-promise.js +0 -78
  240. package/dist/web/cancellable-promise.js.map +0 -1
  241. package/dist/web/clean-url-search-params.js +0 -31
  242. package/dist/web/clean-url-search-params.js.map +0 -1
  243. package/dist/web/collections/cache-dictionary.js +0 -99
  244. package/dist/web/collections/cache-dictionary.js.map +0 -1
  245. package/dist/web/collections/default-map.js +0 -42
  246. package/dist/web/collections/default-map.js.map +0 -1
  247. package/dist/web/collections/default-weak-map.js +0 -43
  248. package/dist/web/collections/default-weak-map.js.map +0 -1
  249. package/dist/web/collections/from.js +0 -770
  250. package/dist/web/collections/from.js.map +0 -1
  251. package/dist/web/collections/index.js +0 -5
  252. package/dist/web/collections/index.js.map +0 -1
  253. package/dist/web/draft.js +0 -222
  254. package/dist/web/draft.js.map +0 -1
  255. package/dist/web/event-bus.js +0 -66
  256. package/dist/web/event-bus.js.map +0 -1
  257. package/dist/web/functions.js +0 -336
  258. package/dist/web/functions.js.map +0 -1
  259. package/dist/web/index.js.map +0 -1
  260. package/dist/web/key-value-pair.js +0 -19
  261. package/dist/web/key-value-pair.js.map +0 -1
  262. package/dist/web/lazy.js +0 -26
  263. package/dist/web/lazy.js.map +0 -1
  264. package/dist/web/math.js +0 -33
  265. package/dist/web/math.js.map +0 -1
  266. package/dist/web/order.js +0 -7
  267. package/dist/web/order.js.map +0 -1
  268. package/dist/web/parse.js +0 -169
  269. package/dist/web/parse.js.map +0 -1
  270. package/dist/web/patch.js +0 -48
  271. package/dist/web/patch.js.map +0 -1
  272. package/dist/web/range.js +0 -151
  273. package/dist/web/range.js.map +0 -1
  274. package/dist/web/result.js +0 -2
  275. package/dist/web/result.js.map +0 -1
  276. package/dist/web/stopwatch.js +0 -40
  277. package/dist/web/stopwatch.js.map +0 -1
  278. package/dist/web/string.js +0 -142
  279. package/dist/web/string.js.map +0 -1
  280. package/dist/web/timer.js +0 -54
  281. package/dist/web/timer.js.map +0 -1
  282. package/dist/web/timespan.js +0 -365
  283. package/dist/web/timespan.js.map +0 -1
  284. package/dist/web/triggers.js +0 -99
  285. package/dist/web/triggers.js.map +0 -1
  286. package/dist/web/type-code.js +0 -16
  287. package/dist/web/type-code.js.map +0 -1
  288. package/dist/web/type.js +0 -292
  289. package/dist/web/type.js.map +0 -1
  290. package/dist/web/types.js +0 -2
  291. package/dist/web/types.js.map +0 -1
  292. package/dist/web/utilities.js.map +0 -1
  293. /package/dist/{types/array.d.ts → array.d.ts} +0 -0
  294. /package/dist/{esm/array.js → array.js} +0 -0
  295. /package/dist/{types/async-pool-executor.d.ts → async-pool-executor.d.ts} +0 -0
  296. /package/dist/{esm/async-pool-executor.js → async-pool-executor.js} +0 -0
  297. /package/dist/{types/browser → browser}/form-utilities.d.ts +0 -0
  298. /package/dist/{esm/browser → browser}/form-utilities.js +0 -0
  299. /package/dist/{types/browser → browser}/geo-location.d.ts +0 -0
  300. /package/dist/{esm/browser → browser}/geo-location.js +0 -0
  301. /package/dist/{types/browser → browser}/index.d.ts +0 -0
  302. /package/dist/{esm/browser → browser}/index.js +0 -0
  303. /package/dist/{types/browser → browser}/native-bridge.d.ts +0 -0
  304. /package/dist/{esm/browser → browser}/native-bridge.js +0 -0
  305. /package/dist/{types/cancellable-promise.d.ts → cancellable-promise.d.ts} +0 -0
  306. /package/dist/{esm/cancellable-promise.js → cancellable-promise.js} +0 -0
  307. /package/dist/{types/clean-url-search-params.d.ts → clean-url-search-params.d.ts} +0 -0
  308. /package/dist/{esm/clean-url-search-params.js → clean-url-search-params.js} +0 -0
  309. /package/dist/{types/collections → collections}/cache-dictionary.d.ts +0 -0
  310. /package/dist/{esm/collections → collections}/cache-dictionary.js +0 -0
  311. /package/dist/{types/collections → collections}/default-map.d.ts +0 -0
  312. /package/dist/{esm/collections → collections}/default-map.js +0 -0
  313. /package/dist/{types/collections → collections}/default-weak-map.d.ts +0 -0
  314. /package/dist/{esm/collections → collections}/default-weak-map.js +0 -0
  315. /package/dist/{types/collections → collections}/from.d.ts +0 -0
  316. /package/dist/{esm/collections → collections}/from.js +0 -0
  317. /package/dist/{types/collections → collections}/index.d.ts +0 -0
  318. /package/dist/{esm/collections → collections}/index.js +0 -0
  319. /package/dist/{types/draft.d.ts → draft.d.ts} +0 -0
  320. /package/dist/{esm/draft.js → draft.js} +0 -0
  321. /package/dist/{types/event-bus.d.ts → event-bus.d.ts} +0 -0
  322. /package/dist/{esm/event-bus.js → event-bus.js} +0 -0
  323. /package/dist/{types/key-value-pair.d.ts → key-value-pair.d.ts} +0 -0
  324. /package/dist/{esm/key-value-pair.js → key-value-pair.js} +0 -0
  325. /package/dist/{types/lazy.d.ts → lazy.d.ts} +0 -0
  326. /package/dist/{esm/lazy.js → lazy.js} +0 -0
  327. /package/dist/{types/math.d.ts → math.d.ts} +0 -0
  328. /package/dist/{esm/math.js → math.js} +0 -0
  329. /package/dist/{types/order.d.ts → order.d.ts} +0 -0
  330. /package/dist/{esm/order.js → order.js} +0 -0
  331. /package/dist/{types/parse.d.ts → parse.d.ts} +0 -0
  332. /package/dist/{esm/parse.js → parse.js} +0 -0
  333. /package/dist/{types/patch.d.ts → patch.d.ts} +0 -0
  334. /package/dist/{esm/patch.js → patch.js} +0 -0
  335. /package/dist/{types/range.d.ts → range.d.ts} +0 -0
  336. /package/dist/{esm/range.js → range.js} +0 -0
  337. /package/dist/{types/result.d.ts → result.d.ts} +0 -0
  338. /package/dist/{esm/result.js → result.js} +0 -0
  339. /package/dist/{types/stopwatch.d.ts → stopwatch.d.ts} +0 -0
  340. /package/dist/{esm/stopwatch.js → stopwatch.js} +0 -0
  341. /package/dist/{types/string.d.ts → string.d.ts} +0 -0
  342. /package/dist/{esm/string.js → string.js} +0 -0
  343. /package/dist/{types/timer.d.ts → timer.d.ts} +0 -0
  344. /package/dist/{esm/timer.js → timer.js} +0 -0
  345. /package/dist/{types/timespan.d.ts → timespan.d.ts} +0 -0
  346. /package/dist/{esm/timespan.js → timespan.js} +0 -0
  347. /package/dist/{types/triggers.d.ts → triggers.d.ts} +0 -0
  348. /package/dist/{esm/triggers.js → triggers.js} +0 -0
  349. /package/dist/{types/type-code.d.ts → type-code.d.ts} +0 -0
  350. /package/dist/{esm/type-code.js → type-code.js} +0 -0
  351. /package/dist/{types/type.d.ts → type.d.ts} +0 -0
  352. /package/dist/{esm/type.js → type.js} +0 -0
  353. /package/dist/{types/types.d.ts → types.d.ts} +0 -0
  354. /package/dist/{esm/types.js → types.js} +0 -0
package/dist/cjs/parse.js DELETED
@@ -1,174 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseInteger = parseInteger;
4
- exports.parseDecimal = parseDecimal;
5
- exports.parseBoolean = parseBoolean;
6
- // ============================================
7
- // HELPERS
8
- // ============================================
9
- function stripThousands(value, separator) {
10
- if (!separator)
11
- return value;
12
- return value.split(separator).join("");
13
- }
14
- function isValidInteger(value, radix) {
15
- if (!Number.isInteger(radix) || radix < 2 || radix > 36)
16
- return false;
17
- const signless = value.replace(/^[+-]/, "");
18
- if (signless === "")
19
- return false;
20
- const digits = "0123456789abcdefghijklmnopqrstuvwxyz".slice(0, radix);
21
- return [...signless.toLowerCase()].every((char) => digits.includes(char));
22
- }
23
- // ============================================
24
- // parseInteger
25
- // ============================================
26
- /**
27
- * Safely parses a value into an integer.
28
- * Returns `null` if the value cannot be parsed.
29
- *
30
- * - `null` or `undefined` → `null`
31
- * - `number` → returned as-is (floats are truncated)
32
- * - `string` → parsed with the given options
33
- *
34
- * @param value - The value to parse.
35
- * @param options - Optional parsing configuration.
36
- * @returns The parsed integer, or `null` on failure.
37
- *
38
- * @example
39
- * ```ts
40
- * parseInteger(42) // 42
41
- * parseInteger(3.7) // 3
42
- * parseInteger(null) // null
43
- * parseInteger(undefined) // null
44
- * parseInteger("42") // 42
45
- * parseInteger("1.234.567", { thousandsSeparator: "." }) // 1234567
46
- * parseInteger("FF", { radix: 16 }) // 255
47
- * parseInteger("abc") // null
48
- * ```
49
- */
50
- function parseInteger(value, options = {}) {
51
- if (value === null || value === undefined)
52
- return null;
53
- if (typeof value === "number") {
54
- return Number.isFinite(value) ? Math.trunc(value) : null;
55
- }
56
- const { radix = 10, thousandsSeparator } = options;
57
- const cleaned = stripThousands(value.trim(), thousandsSeparator);
58
- if (cleaned === "")
59
- return null;
60
- if (!isValidInteger(cleaned, radix))
61
- return null;
62
- const parsed = Number.parseInt(cleaned, radix);
63
- return Number.isNaN(parsed) ? null : parsed;
64
- }
65
- // ============================================
66
- // parseDecimal
67
- // ============================================
68
- /**
69
- * Safely parses a value into a floating-point number.
70
- * Returns `null` if the value cannot be parsed.
71
- *
72
- * - `null` or `undefined` → `null`
73
- * - `number` → returned as-is (if finite)
74
- * - `string` → parsed with the given options
75
- *
76
- * Supports custom decimal and thousands separators, making it suitable
77
- * for both US (`1,234.56`) and EU (`1.234,56`) number formats.
78
- *
79
- * @param value - The value to parse.
80
- * @param options - Optional parsing configuration.
81
- * @returns The parsed float, or `null` on failure.
82
- *
83
- * @example
84
- * ```ts
85
- * parseDecimal(3.14) // 3.14
86
- * parseDecimal(null) // null
87
- * parseDecimal(undefined) // null
88
- * parseDecimal("3.14") // 3.14
89
- * parseDecimal("3,14", { decimalSeparator: "," }) // 3.14
90
- * parseDecimal("1.234,56", { decimalSeparator: ",", thousandsSeparator: "." }) // 1234.56
91
- * parseDecimal("abc") // null
92
- * ```
93
- */
94
- function parseDecimal(value, options = {}) {
95
- if (value === null || value === undefined)
96
- return null;
97
- if (typeof value === "number") {
98
- return Number.isFinite(value) ? value : null;
99
- }
100
- const { decimalSeparator = ".", thousandsSeparator } = options;
101
- let cleaned = stripThousands(value.trim(), thousandsSeparator);
102
- if (cleaned === "")
103
- return null;
104
- if (decimalSeparator === ",") {
105
- const commaCount = (cleaned.match(/,/g) || []).length;
106
- if (commaCount > 1)
107
- return null;
108
- cleaned = cleaned.replace(",", ".");
109
- }
110
- if (!/^[+-]?\d+(\.\d+)?$/.test(cleaned))
111
- return null;
112
- const parsed = Number.parseFloat(cleaned);
113
- return Number.isNaN(parsed) || !Number.isFinite(parsed) ? null : parsed;
114
- }
115
- // ============================================
116
- // parseBoolean
117
- // ============================================
118
- const DEFAULT_TRUTHY = ["true", "1", "yes", "si", "sí", "on"];
119
- const DEFAULT_FALSY = ["false", "0", "no", "off"];
120
- /**
121
- * Safely parses a value into a boolean.
122
- * Returns `null` if the value cannot be interpreted as boolean.
123
- *
124
- * - `null` or `undefined` → `null`
125
- * - `boolean` → returned as-is
126
- * - `number` → `0` is `false`, any other finite number is `true`
127
- * - `string` → matched case-insensitively against known truthy/falsy values
128
- *
129
- * Default truthy: `"true"`, `"1"`, `"yes"`, `"si"`, `"sí"`, `"on"`
130
- * Default falsy: `"false"`, `"0"`, `"no"`, `"off"`
131
- *
132
- * @param value - The value to parse.
133
- * @param options - Optional parsing configuration.
134
- * @returns The parsed boolean, or `null` on failure.
135
- *
136
- * @example
137
- * ```ts
138
- * parseBoolean(true) // true
139
- * parseBoolean(false) // false
140
- * parseBoolean(1) // true
141
- * parseBoolean(0) // false
142
- * parseBoolean(null) // null
143
- * parseBoolean(undefined) // null
144
- * parseBoolean("yes") // true
145
- * parseBoolean("no") // false
146
- * parseBoolean("sí") // true
147
- * parseBoolean("TRUE") // true
148
- * parseBoolean("oui") // null
149
- * parseBoolean("oui", { extraTruthy: ["oui"] }) // true
150
- * parseBoolean("nein", { extraFalsy: ["nein"] }) // false
151
- * parseBoolean("whatever") // null
152
- * ```
153
- */
154
- function parseBoolean(value, options = {}) {
155
- if (value === null || value === undefined)
156
- return null;
157
- if (typeof value === "boolean")
158
- return value;
159
- if (typeof value === "number") {
160
- return Number.isFinite(value) ? value !== 0 : null;
161
- }
162
- const { extraTruthy = [], extraFalsy = [] } = options;
163
- const normalized = value.trim().toLowerCase();
164
- if (normalized === "")
165
- return null;
166
- const truthy = [...DEFAULT_TRUTHY, ...extraTruthy.map((s) => s.toLowerCase())];
167
- const falsy = [...DEFAULT_FALSY, ...extraFalsy.map((s) => s.toLowerCase())];
168
- if (truthy.includes(normalized))
169
- return true;
170
- if (falsy.includes(normalized))
171
- return false;
172
- return null;
173
- }
174
- //# sourceMappingURL=parse.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parse.ts"],"names":[],"mappings":";;AAwGA,oCAoBC;AAgCD,oCA2BC;AA2CD,oCAyBC;AAnMD,+CAA+C;AAC/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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/cjs/patch.js DELETED
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.patch = patch;
4
- exports.unpatch = unpatch;
5
- /**
6
- * Devuelve un Map donde:
7
- * - clave -> null (método añadido nuevo)
8
- * - clave -> descriptorOriginal (método sustituido)
9
- */
10
- function patch(targetOrCtor, fns) {
11
- const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
12
- const result = new Map();
13
- const entries = fns instanceof Map ? [...fns.entries()] : Object.entries(fns);
14
- for (const [key, fn] of entries) {
15
- const prev = Object.getOwnPropertyDescriptor(target, key);
16
- const method = function (...args) {
17
- return fn(this, ...args);
18
- };
19
- try {
20
- Object.defineProperty(target, key, {
21
- value: method,
22
- writable: true,
23
- configurable: true,
24
- enumerable: false,
25
- });
26
- result.set(key, prev ?? null);
27
- }
28
- catch { /* ignorar */
29
- }
30
- }
31
- return result;
32
- }
33
- /**
34
- * Revierte un patch a partir del mapa devuelto por `patch`.
35
- */
36
- function unpatch(targetOrCtor, changes) {
37
- const target = typeof targetOrCtor === "function" ? targetOrCtor.prototype : targetOrCtor;
38
- for (const [key, prev] of changes) {
39
- try {
40
- if (prev === null) {
41
- if (Object.prototype.hasOwnProperty.call(target, key))
42
- delete target[key];
43
- }
44
- else {
45
- Object.defineProperty(target, key, prev);
46
- }
47
- }
48
- catch { /* ignorar */
49
- }
50
- }
51
- }
52
- //# sourceMappingURL=patch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"patch.js","sourceRoot":"","sources":["../../src/patch.ts"],"names":[],"mappings":";;AAyBA,sBA2BC;AAeD,0BAYC;AA3DD;;;;GAIG;AACH,SAAgB,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,SAAgB,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/cjs/range.js DELETED
@@ -1,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class Range {
4
- /**
5
- * Range constructor.
6
- * @param start
7
- * @param end
8
- */
9
- constructor(start, end) {
10
- this.start = start;
11
- this.end = end;
12
- }
13
- /**
14
- * Finds the intersection between two ranges.
15
- *
16
- * @param other The Range object to intersect with.
17
- * @returns The intersected Range object, or null if there is no intersection.
18
- */
19
- intersect(other) {
20
- const start = (this.start > other.start) ? this.start : other.start;
21
- const end = (this.end < other.end) ? this.end : other.end;
22
- if (start < end) {
23
- return new Range(start, end);
24
- }
25
- else {
26
- return null;
27
- }
28
- }
29
- /**
30
- * Subtract the given range from this range.
31
- *
32
- * @param other The range to subtract from this range.
33
- * @returns An array of Range objects representing the result of the subtraction.
34
- */
35
- subtract(other) {
36
- const result = [];
37
- if (this.start >= other.end || this.end <= other.start) {
38
- result.push(new Range(this.start, this.end));
39
- }
40
- else if (other.start <= this.start && other.end >= this.end) {
41
- return result;
42
- }
43
- else {
44
- if (this.start < other.start) {
45
- result.push(new Range(this.start, other.start));
46
- }
47
- if (this.end > other.end) {
48
- result.push(new Range(other.end, this.end));
49
- }
50
- }
51
- return result;
52
- }
53
- /**
54
- * Determines if the given range overlaps with the current range.
55
- *
56
- * @param other The range to be checked for overlap.
57
- * @returns Returns true if there is an overlap between the ranges, false otherwise.
58
- */
59
- overlaps(other) {
60
- const s1 = this.start;
61
- const e1 = this.end;
62
- const s2 = other.start;
63
- const e2 = other.end;
64
- return (s2 > s1 && s2 < e1 || e2 > s1 && e2 < e1) ||
65
- (s1 > s2 && s1 < e2 || e1 > s2 && e1 < e2) ||
66
- (s1 === s2 && e1 === e2);
67
- }
68
- /**
69
- * Determines whether the specified value is within the range defined by the start and end values.
70
- *
71
- * @param obj The value to check if it is within the range.
72
- * @param inclusive Optional. If set to true, the range boundaries are considered inclusive.
73
- * @returns Returns true if the specified value is within the range, false otherwise.
74
- */
75
- contains(obj, inclusive = true) {
76
- return inclusive ?
77
- (this.start <= obj && this.end >= obj) :
78
- (this.start < obj && this.end > obj);
79
- }
80
- /**
81
- * @returns T
82
- */
83
- getStart() {
84
- return this.start;
85
- }
86
- /**
87
- * @returns T
88
- */
89
- getEnd() {
90
- return this.end;
91
- }
92
- /**
93
- * Finds the intersection between two sets of ranges.
94
- *
95
- * @param ranges1
96
- * @param ranges2
97
- * @returns
98
- */
99
- static intersectRanges(ranges1, ranges2) {
100
- const result = [];
101
- for (const r1 of ranges1) {
102
- for (const r2 of ranges2) {
103
- const intersection = r1.intersect(r2);
104
- if (intersection !== null) {
105
- result.push(intersection);
106
- }
107
- }
108
- }
109
- return result;
110
- }
111
- /**
112
- * Determines if any range in the first set overlaps with any range in the second set.
113
- *
114
- * @param ranges1
115
- * @param ranges2
116
- * @returns
117
- */
118
- static overlapsAny(ranges1, ranges2) {
119
- for (const r1 of ranges1) {
120
- for (const r2 of ranges2) {
121
- if (r1.overlaps(r2)) {
122
- return true;
123
- }
124
- }
125
- }
126
- return false;
127
- }
128
- /**
129
- * Subtracts the second set of ranges from the first set of ranges.
130
- *
131
- * @param ranges1
132
- * @param ranges2
133
- * @returns
134
- */
135
- static subtractRanges(ranges1, ranges2) {
136
- let currentRanges = ranges1;
137
- for (const r2 of ranges2) {
138
- const nextRanges = [];
139
- for (const r1 of currentRanges) {
140
- const subtracted = r1.subtract(r2);
141
- for (const s of subtracted) {
142
- nextRanges.push(s);
143
- }
144
- }
145
- currentRanges = nextRanges;
146
- if (currentRanges.length === 0) {
147
- break;
148
- }
149
- }
150
- return currentRanges;
151
- }
152
- }
153
- exports.default = Range;
154
- //# sourceMappingURL=range.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"range.js","sourceRoot":"","sources":["../../src/range.ts"],"names":[],"mappings":";;AAAA,MAAqB,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,CAAC,KAAe;QAC5B,MAAM,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK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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,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# 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,46 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const timespan_js_1 = __importDefault(require("./timespan.js"));
7
- class Stopwatch {
8
- constructor() {
9
- this.startTime = null;
10
- this.elapsedTime = null;
11
- }
12
- /*static measure<T>(callback: () => T, measure: { value: TimeSpan | null }): T {
13
- const stopwatch = new Stopwatch();
14
- stopwatch.start();
15
- try {
16
- return callback();
17
- } finally {
18
- stopwatch.stop();
19
- measure.value = stopwatch.getElapsedTime();
20
- }
21
- }*/
22
- start() {
23
- this.startTime = performance.now();
24
- this.elapsedTime = null;
25
- }
26
- stop() {
27
- if (this.startTime !== null) {
28
- this.elapsedTime = performance.now() - this.startTime;
29
- this.startTime = null;
30
- }
31
- }
32
- resume() {
33
- if (this.elapsedTime !== null) {
34
- this.startTime = performance.now() - this.elapsedTime;
35
- this.elapsedTime = null;
36
- }
37
- }
38
- getElapsedTime() {
39
- if (this.startTime !== null) {
40
- return timespan_js_1.default.fromMilliseconds(performance.now() - this.startTime);
41
- }
42
- return timespan_js_1.default.fromMilliseconds(this.elapsedTime ?? 0.0);
43
- }
44
- }
45
- exports.default = Stopwatch;
46
- //# sourceMappingURL=stopwatch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"stopwatch.js","sourceRoot":"","sources":["../../src/stopwatch.ts"],"names":[],"mappings":";;;;;AAAA,gEAAqC;AAErC,MAAqB,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,qBAAQ,CAAC,gBAAgB,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,qBAAQ,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,IAAI,GAAG,CAAC,CAAC;IAC9D,CAAC;CACJ;AAxCD,4BAwCC","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,154 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ensurePrefix = ensurePrefix;
4
- exports.ensureSuffix = ensureSuffix;
5
- exports.normalizeWhitespaces = normalizeWhitespaces;
6
- exports.removeDiacritics = removeDiacritics;
7
- exports.format = format;
8
- exports.toSnakeCase = toSnakeCase;
9
- exports.toKebabCase = toKebabCase;
10
- exports.toCamelCase = toCamelCase;
11
- exports.toPascalCase = toPascalCase;
12
- exports.toConstantCase = toConstantCase;
13
- /**
14
- * Ensures that a given string has a specific prefix.
15
- *
16
- * @param {string} str - The string to ensure the prefix on.
17
- * @param {string} prefix - The prefix to ensure on the string.
18
- * @return {string} - The resulting string with the ensured prefix.
19
- */
20
- function ensurePrefix(str, prefix) {
21
- if (!str.startsWith(prefix))
22
- return prefix + str;
23
- return str;
24
- }
25
- /**
26
- * Ensures that a string ends with a specified suffix.
27
- *
28
- * @param {string} str - The original string.
29
- * @param {string} suffix - The suffix to ensure.
30
- * @return {string} - The modified string with the suffix added if it was not already present.
31
- */
32
- function ensureSuffix(str, suffix) {
33
- if (!str.endsWith(suffix))
34
- return str + suffix;
35
- return str;
36
- }
37
- /**
38
- * Normalizes Unicode whitespaces into single ASCII spaces and removes leading
39
- * and trailing whitespace.
40
- */
41
- function normalizeWhitespaces(str) {
42
- return str.normalize('NFKC')
43
- .replace(/[\s\u200B\uFEFF]+/gu, ' ')
44
- .trim();
45
- }
46
- /**
47
- * Removes Unicode diacritics while preserving the original letter casing.
48
- *
49
- * @example removeDiacritics('áÁñÑ') // 'aAnN'
50
- */
51
- function removeDiacritics(str) {
52
- return str
53
- .normalize('NFD')
54
- .replace(/\p{M}+/gu, '');
55
- }
56
- /**
57
- * Formats a string using a template and provided arguments.
58
- *
59
- * @param {string} template - The template string containing placeholders.
60
- * @param {any[]} args - Optional arguments to replace the placeholders in the template.
61
- * @return {string} The formatted string.
62
- */
63
- function format(template, ...args) {
64
- let regex;
65
- const hasNamedPlaceholders = /{(?!\d+})[^{}]+}/.test(template);
66
- if (args.length === 1 && args[0] !== null && typeof args[0] === 'object' && hasNamedPlaceholders) {
67
- args = args[0];
68
- regex = /{(.+?)}/g;
69
- }
70
- else {
71
- regex = /{(\d+?)}/g;
72
- }
73
- return template.replace(regex, (match, key) => {
74
- return Object.prototype.hasOwnProperty.call(args, key) && typeof args[key] !== 'undefined'
75
- ? args[key]
76
- : "";
77
- });
78
- }
79
- /**
80
- * Splits a string into its constituent words, regardless of the original case
81
- * style (camelCase, PascalCase, snake_case, kebab-case, CONSTANT_CASE,
82
- * space-separated, etc.).
83
- *
84
- * @param {string} str - The string to split into words.
85
- * @return {string[]} - The list of lowercase words extracted from the input.
86
- */
87
- function toWords(str) {
88
- if (!str)
89
- return [];
90
- return str
91
- // Insert a space between a lowercase/digit and an uppercase letter (camelCase -> camel Case)
92
- .replace(/([\p{Ll}\p{N}])(\p{Lu})/gu, '$1 $2')
93
- // Insert a space between consecutive uppercase letters followed by a lowercase letter (XMLParser -> XML Parser)
94
- .replace(/(\p{Lu}+)(\p{Lu}\p{Ll})/gu, '$1 $2')
95
- // Replace any non-alphanumeric character with a space
96
- .replace(/[^\p{L}\p{N}]+/gu, ' ')
97
- .trim()
98
- .toLowerCase()
99
- .split(/\s+/)
100
- .filter(Boolean);
101
- }
102
- /**
103
- * Converts a string to snake_case.
104
- *
105
- * @param {string} str - The string to convert.
106
- * @return {string} - The string converted to snake_case.
107
- */
108
- function toSnakeCase(str) {
109
- return toWords(str).join('_');
110
- }
111
- /**
112
- * Converts a string to kebab-case.
113
- *
114
- * @param {string} str - The string to convert.
115
- * @return {string} - The string converted to kebab-case.
116
- */
117
- function toKebabCase(str) {
118
- return toWords(str).join('-');
119
- }
120
- /**
121
- * Converts a string to camelCase.
122
- *
123
- * @param {string} str - The string to convert.
124
- * @return {string} - The string converted to camelCase.
125
- */
126
- function toCamelCase(str) {
127
- const words = toWords(str);
128
- if (words.length === 0)
129
- return '';
130
- return words
131
- .map((word, i) => i === 0 ? word : word.charAt(0).toUpperCase() + word.slice(1))
132
- .join('');
133
- }
134
- /**
135
- * Converts a string to PascalCase.
136
- *
137
- * @param {string} str - The string to convert.
138
- * @return {string} - The string converted to PascalCase.
139
- */
140
- function toPascalCase(str) {
141
- return toWords(str)
142
- .map(word => word.charAt(0).toUpperCase() + word.slice(1))
143
- .join('');
144
- }
145
- /**
146
- * Converts a string to CONSTANT_CASE (a.k.a. SCREAMING_SNAKE_CASE).
147
- *
148
- * @param {string} str - The string to convert.
149
- * @return {string} - The string converted to CONSTANT_CASE.
150
- */
151
- function toConstantCase(str) {
152
- return toWords(str).join('_').toUpperCase();
153
- }
154
- //# sourceMappingURL=string.js.map