@kdtlabs/utils 0.0.4 → 0.0.6

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 (454) hide show
  1. package/SKILL.md +12 -9
  2. package/dist/arrays/comparators.d.ts +8 -0
  3. package/dist/arrays/comparators.d.ts.map +1 -0
  4. package/{arrays → dist/arrays}/index.d.ts +1 -0
  5. package/dist/arrays/index.d.ts.map +1 -0
  6. package/{common → dist/common}/assertions.d.ts +1 -1
  7. package/{common → dist/common}/assertions.d.ts.map +1 -1
  8. package/{common → dist/common}/types.d.ts +1 -1
  9. package/{common → dist/common}/types.d.ts.map +1 -1
  10. package/{functions → dist/functions}/executions.d.ts +1 -1
  11. package/{functions → dist/functions}/executions.d.ts.map +1 -1
  12. package/dist/index.js +14 -0
  13. package/dist/index.js.map +101 -0
  14. package/{objects → dist/objects}/transformations.d.ts +1 -1
  15. package/{objects → dist/objects}/transformations.d.ts.map +1 -1
  16. package/{objects → dist/objects}/types.d.ts +1 -1
  17. package/{objects → dist/objects}/types.d.ts.map +1 -1
  18. package/{promises → dist/promises}/deferred.d.ts +1 -1
  19. package/{promises → dist/promises}/deferred.d.ts.map +1 -1
  20. package/{promises → dist/promises}/timers.d.ts +1 -1
  21. package/{promises → dist/promises}/timers.d.ts.map +1 -1
  22. package/{serializer → dist/serializer}/context.d.ts +1 -1
  23. package/{serializer → dist/serializer}/context.d.ts.map +1 -1
  24. package/{serializer → dist/serializer}/serialize.d.ts +1 -1
  25. package/{serializer → dist/serializer}/serialize.d.ts.map +1 -1
  26. package/{serializer → dist/serializer}/serializers/array.d.ts +1 -1
  27. package/{serializer → dist/serializer}/serializers/array.d.ts.map +1 -1
  28. package/{serializer → dist/serializer}/serializers/binary.d.ts +1 -1
  29. package/dist/serializer/serializers/binary.d.ts.map +1 -0
  30. package/{serializer → dist/serializer}/serializers/blob.d.ts +1 -1
  31. package/dist/serializer/serializers/blob.d.ts.map +1 -0
  32. package/{serializer → dist/serializer}/serializers/collection.d.ts +1 -1
  33. package/{serializer → dist/serializer}/serializers/collection.d.ts.map +1 -1
  34. package/{serializer → dist/serializer}/serializers/compound.d.ts +1 -1
  35. package/{serializer → dist/serializer}/serializers/compound.d.ts.map +1 -1
  36. package/{serializer → dist/serializer}/serializers/error.d.ts +1 -1
  37. package/{serializer → dist/serializer}/serializers/error.d.ts.map +1 -1
  38. package/{serializer → dist/serializer}/serializers/function.d.ts +1 -1
  39. package/{serializer → dist/serializer}/serializers/function.d.ts.map +1 -1
  40. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts +1 -1
  41. package/{serializer → dist/serializer}/serializers/leaf-object.d.ts.map +1 -1
  42. package/{serializer → dist/serializer}/serializers/number.d.ts +1 -1
  43. package/dist/serializer/serializers/number.d.ts.map +1 -0
  44. package/{serializer → dist/serializer}/serializers/object.d.ts +1 -1
  45. package/{serializer → dist/serializer}/serializers/object.d.ts.map +1 -1
  46. package/{serializer → dist/serializer}/serializers/opaque.d.ts +1 -1
  47. package/dist/serializer/serializers/opaque.d.ts.map +1 -0
  48. package/{serializer → dist/serializer}/serializers/primitive.d.ts +1 -1
  49. package/{serializer → dist/serializer}/serializers/primitive.d.ts.map +1 -1
  50. package/{serializer → dist/serializer}/types.d.ts +1 -1
  51. package/{serializer → dist/serializer}/types.d.ts.map +1 -1
  52. package/{serializer → dist/serializer}/utils.d.ts +1 -1
  53. package/{serializer → dist/serializer}/utils.d.ts.map +1 -1
  54. package/{strings → dist/strings}/index.d.ts +1 -0
  55. package/{strings → dist/strings}/index.d.ts.map +1 -1
  56. package/{strings → dist/strings}/manipulations.d.ts +2 -0
  57. package/{strings → dist/strings}/manipulations.d.ts.map +1 -1
  58. package/dist/strings/strip-ansi.d.ts +2 -0
  59. package/dist/strings/strip-ansi.d.ts.map +1 -0
  60. package/{system → dist/system}/fetch.d.ts +2 -2
  61. package/{system → dist/system}/fetch.d.ts.map +1 -1
  62. package/dist/system/types.d.ts +3 -0
  63. package/{system → dist/system}/types.d.ts.map +1 -1
  64. package/{times → dist/times}/conversions.d.ts +1 -1
  65. package/{times → dist/times}/conversions.d.ts.map +1 -1
  66. package/package.json +11 -73
  67. package/src/arrays/accessors.ts +25 -0
  68. package/src/arrays/comparators.ts +53 -0
  69. package/src/arrays/conversions.ts +16 -0
  70. package/src/arrays/factories.ts +13 -0
  71. package/src/arrays/guards.ts +7 -0
  72. package/src/arrays/index.ts +9 -0
  73. package/src/arrays/operations.ts +103 -0
  74. package/src/arrays/set-operations.ts +11 -0
  75. package/src/arrays/types.ts +21 -0
  76. package/src/buffers/conversions.ts +26 -0
  77. package/src/buffers/guards.ts +13 -0
  78. package/src/buffers/index.ts +5 -0
  79. package/src/buffers/operations.ts +44 -0
  80. package/src/buffers/types.ts +1 -0
  81. package/src/collections/fifo-map.ts +33 -0
  82. package/src/collections/fifo-set.ts +29 -0
  83. package/src/collections/guards.ts +11 -0
  84. package/src/collections/index.ts +10 -0
  85. package/src/collections/linked-base.ts +117 -0
  86. package/src/collections/linked-map.ts +82 -0
  87. package/src/collections/linked-set.ts +69 -0
  88. package/src/collections/lru-map.ts +36 -0
  89. package/src/collections/lru-set.ts +25 -0
  90. package/src/collections/types.ts +12 -0
  91. package/src/common/assertions.ts +11 -0
  92. package/src/common/guards.ts +58 -0
  93. package/src/common/index.ts +5 -0
  94. package/src/common/transformations.ts +20 -0
  95. package/src/common/types.ts +3 -0
  96. package/src/core/constants.ts +1 -0
  97. package/src/core/conversions.ts +9 -0
  98. package/src/core/guards.ts +57 -0
  99. package/src/core/index.ts +5 -0
  100. package/src/core/types.ts +15 -0
  101. package/src/errors/base-error.ts +48 -0
  102. package/src/errors/factories.ts +74 -0
  103. package/src/errors/guards.ts +12 -0
  104. package/src/errors/index.ts +7 -0
  105. package/src/errors/operations.ts +15 -0
  106. package/src/errors/stringify.ts +131 -0
  107. package/src/errors/types.ts +11 -0
  108. package/src/events/emitter.ts +117 -0
  109. package/src/events/index.ts +2 -0
  110. package/src/events/types.ts +11 -0
  111. package/src/functions/compositions.ts +17 -0
  112. package/src/functions/debounce.ts +34 -0
  113. package/src/functions/executions.ts +12 -0
  114. package/src/functions/guards.ts +5 -0
  115. package/src/functions/index.ts +11 -0
  116. package/src/functions/memoize.ts +33 -0
  117. package/src/functions/once.ts +33 -0
  118. package/src/functions/pipe.ts +39 -0
  119. package/src/functions/throttle.ts +59 -0
  120. package/src/functions/timer-state.ts +33 -0
  121. package/src/functions/types.ts +8 -0
  122. package/src/index.ts +16 -0
  123. package/src/json-rpc/constants.ts +15 -0
  124. package/src/json-rpc/factories.ts +22 -0
  125. package/src/json-rpc/guards.ts +58 -0
  126. package/src/json-rpc/index.ts +5 -0
  127. package/src/json-rpc/types.ts +48 -0
  128. package/src/numbers/bigint-math.ts +163 -0
  129. package/src/numbers/constants.ts +14 -0
  130. package/src/numbers/conversions.ts +83 -0
  131. package/src/numbers/factories.ts +6 -0
  132. package/src/numbers/formats.ts +52 -0
  133. package/src/numbers/guards.ts +22 -0
  134. package/src/numbers/index.ts +10 -0
  135. package/src/numbers/maths.ts +28 -0
  136. package/src/numbers/ranges.ts +17 -0
  137. package/src/numbers/types.ts +7 -0
  138. package/src/objects/deep-merge.ts +76 -0
  139. package/src/objects/guards.ts +21 -0
  140. package/src/objects/index.ts +5 -0
  141. package/src/objects/transformations.ts +34 -0
  142. package/src/objects/types.ts +33 -0
  143. package/src/promises/abortable.ts +37 -0
  144. package/src/promises/compositions.ts +18 -0
  145. package/src/promises/deferred.ts +131 -0
  146. package/src/promises/guards.ts +8 -0
  147. package/src/promises/index.ts +10 -0
  148. package/src/promises/pipe.ts +39 -0
  149. package/src/promises/poll.ts +92 -0
  150. package/src/promises/retry.ts +138 -0
  151. package/src/promises/timers.ts +16 -0
  152. package/src/promises/types.ts +1 -0
  153. package/src/serializer/constants.ts +5 -0
  154. package/src/serializer/context.ts +24 -0
  155. package/src/serializer/index.ts +8 -0
  156. package/src/serializer/serialize.ts +51 -0
  157. package/src/serializer/serializers/array.ts +17 -0
  158. package/src/serializer/serializers/binary.ts +24 -0
  159. package/src/serializer/serializers/blob.ts +18 -0
  160. package/src/serializer/serializers/collection.ts +25 -0
  161. package/src/serializer/serializers/compound.ts +79 -0
  162. package/src/serializer/serializers/error.ts +75 -0
  163. package/src/serializer/serializers/function.ts +13 -0
  164. package/src/serializer/serializers/index.ts +12 -0
  165. package/src/serializer/serializers/leaf-object.ts +18 -0
  166. package/src/serializer/serializers/number.ts +14 -0
  167. package/src/serializer/serializers/object.ts +62 -0
  168. package/src/serializer/serializers/opaque.ts +36 -0
  169. package/src/serializer/serializers/primitive.ts +32 -0
  170. package/src/serializer/symbol-registry.ts +28 -0
  171. package/src/serializer/types.ts +42 -0
  172. package/src/serializer/utils.ts +15 -0
  173. package/src/strings/constants.ts +1 -0
  174. package/src/strings/factories.ts +9 -0
  175. package/src/strings/guards.ts +51 -0
  176. package/src/strings/index.ts +7 -0
  177. package/src/strings/manipulations.ts +145 -0
  178. package/src/strings/strip-ansi.ts +14 -0
  179. package/src/strings/types.ts +3 -0
  180. package/src/system/env.ts +32 -0
  181. package/src/system/fetch.ts +23 -0
  182. package/src/system/graceful-exit.ts +46 -0
  183. package/src/system/index.ts +6 -0
  184. package/src/system/path.ts +12 -0
  185. package/src/system/types.ts +3 -0
  186. package/src/times/constants.ts +6 -0
  187. package/src/times/conversions.ts +85 -0
  188. package/src/times/factories.ts +3 -0
  189. package/src/times/guards.ts +3 -0
  190. package/src/times/index.ts +5 -0
  191. package/src/times/operations.ts +9 -0
  192. package/CHANGELOG.md +0 -57
  193. package/arrays/index.d.ts.map +0 -1
  194. package/arrays/index.js +0 -4
  195. package/arrays/index.js.map +0 -9
  196. package/buffers/index.js +0 -4
  197. package/buffers/index.js.map +0 -9
  198. package/chunk-25ja9350.js +0 -4
  199. package/chunk-25ja9350.js.map +0 -13
  200. package/chunk-3w6nt7kb.js +0 -4
  201. package/chunk-3w6nt7kb.js.map +0 -12
  202. package/chunk-5txwcr6j.js +0 -4
  203. package/chunk-5txwcr6j.js.map +0 -17
  204. package/chunk-6dxad51h.js +0 -4
  205. package/chunk-6dxad51h.js.map +0 -12
  206. package/chunk-6kdnnxe0.js +0 -4
  207. package/chunk-6kdnnxe0.js.map +0 -17
  208. package/chunk-7cndek91.js +0 -4
  209. package/chunk-7cndek91.js.map +0 -15
  210. package/chunk-bee0nxse.js +0 -6
  211. package/chunk-bee0nxse.js.map +0 -14
  212. package/chunk-bjmntg2y.js +0 -4
  213. package/chunk-bjmntg2y.js.map +0 -18
  214. package/chunk-d0d0d285.js +0 -4
  215. package/chunk-d0d0d285.js.map +0 -26
  216. package/chunk-jny2gdyy.js +0 -4
  217. package/chunk-jny2gdyy.js.map +0 -12
  218. package/chunk-kbzgn0z4.js +0 -4
  219. package/chunk-kbzgn0z4.js.map +0 -10
  220. package/chunk-qmbgp0vr.js +0 -4
  221. package/chunk-qmbgp0vr.js.map +0 -12
  222. package/chunk-qn6n0ff5.js +0 -4
  223. package/chunk-qn6n0ff5.js.map +0 -17
  224. package/chunk-r3maskdb.js +0 -5
  225. package/chunk-r3maskdb.js.map +0 -13
  226. package/chunk-st3dxvqt.js +0 -4
  227. package/chunk-st3dxvqt.js.map +0 -14
  228. package/chunk-xp18wdk6.js +0 -4
  229. package/chunk-xp18wdk6.js.map +0 -12
  230. package/collections/index.js +0 -4
  231. package/collections/index.js.map +0 -9
  232. package/common/index.js +0 -4
  233. package/common/index.js.map +0 -9
  234. package/core/index.js +0 -4
  235. package/core/index.js.map +0 -9
  236. package/errors/index.js +0 -4
  237. package/errors/index.js.map +0 -9
  238. package/events/index.js +0 -4
  239. package/events/index.js.map +0 -9
  240. package/functions/index.js +0 -4
  241. package/functions/index.js.map +0 -9
  242. package/index.js +0 -4
  243. package/index.js.map +0 -9
  244. package/json-rpc/index.js +0 -4
  245. package/json-rpc/index.js.map +0 -9
  246. package/meta.json +0 -2998
  247. package/meta.md +0 -1816
  248. package/numbers/index.js +0 -4
  249. package/numbers/index.js.map +0 -9
  250. package/objects/index.js +0 -4
  251. package/objects/index.js.map +0 -9
  252. package/promises/index.js +0 -4
  253. package/promises/index.js.map +0 -9
  254. package/serializer/index.js +0 -4
  255. package/serializer/index.js.map +0 -9
  256. package/serializer/serializers/binary.d.ts.map +0 -1
  257. package/serializer/serializers/blob.d.ts.map +0 -1
  258. package/serializer/serializers/number.d.ts.map +0 -1
  259. package/serializer/serializers/opaque.d.ts.map +0 -1
  260. package/strings/index.js +0 -4
  261. package/strings/index.js.map +0 -9
  262. package/system/index.js +0 -4
  263. package/system/index.js.map +0 -9
  264. package/system/types.d.ts +0 -3
  265. package/times/index.js +0 -4
  266. package/times/index.js.map +0 -9
  267. /package/{arrays → dist/arrays}/accessors.d.ts +0 -0
  268. /package/{arrays → dist/arrays}/accessors.d.ts.map +0 -0
  269. /package/{arrays → dist/arrays}/conversions.d.ts +0 -0
  270. /package/{arrays → dist/arrays}/conversions.d.ts.map +0 -0
  271. /package/{arrays → dist/arrays}/factories.d.ts +0 -0
  272. /package/{arrays → dist/arrays}/factories.d.ts.map +0 -0
  273. /package/{arrays → dist/arrays}/guards.d.ts +0 -0
  274. /package/{arrays → dist/arrays}/guards.d.ts.map +0 -0
  275. /package/{arrays → dist/arrays}/operations.d.ts +0 -0
  276. /package/{arrays → dist/arrays}/operations.d.ts.map +0 -0
  277. /package/{arrays → dist/arrays}/set-operations.d.ts +0 -0
  278. /package/{arrays → dist/arrays}/set-operations.d.ts.map +0 -0
  279. /package/{arrays → dist/arrays}/types.d.ts +0 -0
  280. /package/{arrays → dist/arrays}/types.d.ts.map +0 -0
  281. /package/{buffers → dist/buffers}/conversions.d.ts +0 -0
  282. /package/{buffers → dist/buffers}/conversions.d.ts.map +0 -0
  283. /package/{buffers → dist/buffers}/guards.d.ts +0 -0
  284. /package/{buffers → dist/buffers}/guards.d.ts.map +0 -0
  285. /package/{buffers → dist/buffers}/index.d.ts +0 -0
  286. /package/{buffers → dist/buffers}/index.d.ts.map +0 -0
  287. /package/{buffers → dist/buffers}/operations.d.ts +0 -0
  288. /package/{buffers → dist/buffers}/operations.d.ts.map +0 -0
  289. /package/{buffers → dist/buffers}/types.d.ts +0 -0
  290. /package/{buffers → dist/buffers}/types.d.ts.map +0 -0
  291. /package/{collections → dist/collections}/fifo-map.d.ts +0 -0
  292. /package/{collections → dist/collections}/fifo-map.d.ts.map +0 -0
  293. /package/{collections → dist/collections}/fifo-set.d.ts +0 -0
  294. /package/{collections → dist/collections}/fifo-set.d.ts.map +0 -0
  295. /package/{collections → dist/collections}/guards.d.ts +0 -0
  296. /package/{collections → dist/collections}/guards.d.ts.map +0 -0
  297. /package/{collections → dist/collections}/index.d.ts +0 -0
  298. /package/{collections → dist/collections}/index.d.ts.map +0 -0
  299. /package/{collections → dist/collections}/linked-base.d.ts +0 -0
  300. /package/{collections → dist/collections}/linked-base.d.ts.map +0 -0
  301. /package/{collections → dist/collections}/linked-map.d.ts +0 -0
  302. /package/{collections → dist/collections}/linked-map.d.ts.map +0 -0
  303. /package/{collections → dist/collections}/linked-set.d.ts +0 -0
  304. /package/{collections → dist/collections}/linked-set.d.ts.map +0 -0
  305. /package/{collections → dist/collections}/lru-map.d.ts +0 -0
  306. /package/{collections → dist/collections}/lru-map.d.ts.map +0 -0
  307. /package/{collections → dist/collections}/lru-set.d.ts +0 -0
  308. /package/{collections → dist/collections}/lru-set.d.ts.map +0 -0
  309. /package/{collections → dist/collections}/types.d.ts +0 -0
  310. /package/{collections → dist/collections}/types.d.ts.map +0 -0
  311. /package/{common → dist/common}/guards.d.ts +0 -0
  312. /package/{common → dist/common}/guards.d.ts.map +0 -0
  313. /package/{common → dist/common}/index.d.ts +0 -0
  314. /package/{common → dist/common}/index.d.ts.map +0 -0
  315. /package/{common → dist/common}/transformations.d.ts +0 -0
  316. /package/{common → dist/common}/transformations.d.ts.map +0 -0
  317. /package/{core → dist/core}/constants.d.ts +0 -0
  318. /package/{core → dist/core}/constants.d.ts.map +0 -0
  319. /package/{core → dist/core}/conversions.d.ts +0 -0
  320. /package/{core → dist/core}/conversions.d.ts.map +0 -0
  321. /package/{core → dist/core}/guards.d.ts +0 -0
  322. /package/{core → dist/core}/guards.d.ts.map +0 -0
  323. /package/{core → dist/core}/index.d.ts +0 -0
  324. /package/{core → dist/core}/index.d.ts.map +0 -0
  325. /package/{core → dist/core}/types.d.ts +0 -0
  326. /package/{core → dist/core}/types.d.ts.map +0 -0
  327. /package/{errors → dist/errors}/base-error.d.ts +0 -0
  328. /package/{errors → dist/errors}/base-error.d.ts.map +0 -0
  329. /package/{errors → dist/errors}/factories.d.ts +0 -0
  330. /package/{errors → dist/errors}/factories.d.ts.map +0 -0
  331. /package/{errors → dist/errors}/guards.d.ts +0 -0
  332. /package/{errors → dist/errors}/guards.d.ts.map +0 -0
  333. /package/{errors → dist/errors}/index.d.ts +0 -0
  334. /package/{errors → dist/errors}/index.d.ts.map +0 -0
  335. /package/{errors → dist/errors}/operations.d.ts +0 -0
  336. /package/{errors → dist/errors}/operations.d.ts.map +0 -0
  337. /package/{errors → dist/errors}/stringify.d.ts +0 -0
  338. /package/{errors → dist/errors}/stringify.d.ts.map +0 -0
  339. /package/{errors → dist/errors}/types.d.ts +0 -0
  340. /package/{errors → dist/errors}/types.d.ts.map +0 -0
  341. /package/{events → dist/events}/emitter.d.ts +0 -0
  342. /package/{events → dist/events}/emitter.d.ts.map +0 -0
  343. /package/{events → dist/events}/index.d.ts +0 -0
  344. /package/{events → dist/events}/index.d.ts.map +0 -0
  345. /package/{events → dist/events}/types.d.ts +0 -0
  346. /package/{events → dist/events}/types.d.ts.map +0 -0
  347. /package/{functions → dist/functions}/compositions.d.ts +0 -0
  348. /package/{functions → dist/functions}/compositions.d.ts.map +0 -0
  349. /package/{functions → dist/functions}/debounce.d.ts +0 -0
  350. /package/{functions → dist/functions}/debounce.d.ts.map +0 -0
  351. /package/{functions → dist/functions}/guards.d.ts +0 -0
  352. /package/{functions → dist/functions}/guards.d.ts.map +0 -0
  353. /package/{functions → dist/functions}/index.d.ts +0 -0
  354. /package/{functions → dist/functions}/index.d.ts.map +0 -0
  355. /package/{functions → dist/functions}/memoize.d.ts +0 -0
  356. /package/{functions → dist/functions}/memoize.d.ts.map +0 -0
  357. /package/{functions → dist/functions}/once.d.ts +0 -0
  358. /package/{functions → dist/functions}/once.d.ts.map +0 -0
  359. /package/{functions → dist/functions}/pipe.d.ts +0 -0
  360. /package/{functions → dist/functions}/pipe.d.ts.map +0 -0
  361. /package/{functions → dist/functions}/throttle.d.ts +0 -0
  362. /package/{functions → dist/functions}/throttle.d.ts.map +0 -0
  363. /package/{functions → dist/functions}/timer-state.d.ts +0 -0
  364. /package/{functions → dist/functions}/timer-state.d.ts.map +0 -0
  365. /package/{functions → dist/functions}/types.d.ts +0 -0
  366. /package/{functions → dist/functions}/types.d.ts.map +0 -0
  367. /package/{index.d.ts → dist/index.d.ts} +0 -0
  368. /package/{index.d.ts.map → dist/index.d.ts.map} +0 -0
  369. /package/{json-rpc → dist/json-rpc}/constants.d.ts +0 -0
  370. /package/{json-rpc → dist/json-rpc}/constants.d.ts.map +0 -0
  371. /package/{json-rpc → dist/json-rpc}/factories.d.ts +0 -0
  372. /package/{json-rpc → dist/json-rpc}/factories.d.ts.map +0 -0
  373. /package/{json-rpc → dist/json-rpc}/guards.d.ts +0 -0
  374. /package/{json-rpc → dist/json-rpc}/guards.d.ts.map +0 -0
  375. /package/{json-rpc → dist/json-rpc}/index.d.ts +0 -0
  376. /package/{json-rpc → dist/json-rpc}/index.d.ts.map +0 -0
  377. /package/{json-rpc → dist/json-rpc}/types.d.ts +0 -0
  378. /package/{json-rpc → dist/json-rpc}/types.d.ts.map +0 -0
  379. /package/{numbers → dist/numbers}/bigint-math.d.ts +0 -0
  380. /package/{numbers → dist/numbers}/bigint-math.d.ts.map +0 -0
  381. /package/{numbers → dist/numbers}/constants.d.ts +0 -0
  382. /package/{numbers → dist/numbers}/constants.d.ts.map +0 -0
  383. /package/{numbers → dist/numbers}/conversions.d.ts +0 -0
  384. /package/{numbers → dist/numbers}/conversions.d.ts.map +0 -0
  385. /package/{numbers → dist/numbers}/factories.d.ts +0 -0
  386. /package/{numbers → dist/numbers}/factories.d.ts.map +0 -0
  387. /package/{numbers → dist/numbers}/formats.d.ts +0 -0
  388. /package/{numbers → dist/numbers}/formats.d.ts.map +0 -0
  389. /package/{numbers → dist/numbers}/guards.d.ts +0 -0
  390. /package/{numbers → dist/numbers}/guards.d.ts.map +0 -0
  391. /package/{numbers → dist/numbers}/index.d.ts +0 -0
  392. /package/{numbers → dist/numbers}/index.d.ts.map +0 -0
  393. /package/{numbers → dist/numbers}/maths.d.ts +0 -0
  394. /package/{numbers → dist/numbers}/maths.d.ts.map +0 -0
  395. /package/{numbers → dist/numbers}/ranges.d.ts +0 -0
  396. /package/{numbers → dist/numbers}/ranges.d.ts.map +0 -0
  397. /package/{numbers → dist/numbers}/types.d.ts +0 -0
  398. /package/{numbers → dist/numbers}/types.d.ts.map +0 -0
  399. /package/{objects → dist/objects}/deep-merge.d.ts +0 -0
  400. /package/{objects → dist/objects}/deep-merge.d.ts.map +0 -0
  401. /package/{objects → dist/objects}/guards.d.ts +0 -0
  402. /package/{objects → dist/objects}/guards.d.ts.map +0 -0
  403. /package/{objects → dist/objects}/index.d.ts +0 -0
  404. /package/{objects → dist/objects}/index.d.ts.map +0 -0
  405. /package/{promises → dist/promises}/abortable.d.ts +0 -0
  406. /package/{promises → dist/promises}/abortable.d.ts.map +0 -0
  407. /package/{promises → dist/promises}/compositions.d.ts +0 -0
  408. /package/{promises → dist/promises}/compositions.d.ts.map +0 -0
  409. /package/{promises → dist/promises}/guards.d.ts +0 -0
  410. /package/{promises → dist/promises}/guards.d.ts.map +0 -0
  411. /package/{promises → dist/promises}/index.d.ts +0 -0
  412. /package/{promises → dist/promises}/index.d.ts.map +0 -0
  413. /package/{promises → dist/promises}/pipe.d.ts +0 -0
  414. /package/{promises → dist/promises}/pipe.d.ts.map +0 -0
  415. /package/{promises → dist/promises}/poll.d.ts +0 -0
  416. /package/{promises → dist/promises}/poll.d.ts.map +0 -0
  417. /package/{promises → dist/promises}/retry.d.ts +0 -0
  418. /package/{promises → dist/promises}/retry.d.ts.map +0 -0
  419. /package/{promises → dist/promises}/types.d.ts +0 -0
  420. /package/{promises → dist/promises}/types.d.ts.map +0 -0
  421. /package/{serializer → dist/serializer}/constants.d.ts +0 -0
  422. /package/{serializer → dist/serializer}/constants.d.ts.map +0 -0
  423. /package/{serializer → dist/serializer}/index.d.ts +0 -0
  424. /package/{serializer → dist/serializer}/index.d.ts.map +0 -0
  425. /package/{serializer → dist/serializer}/serializers/index.d.ts +0 -0
  426. /package/{serializer → dist/serializer}/serializers/index.d.ts.map +0 -0
  427. /package/{serializer → dist/serializer}/symbol-registry.d.ts +0 -0
  428. /package/{serializer → dist/serializer}/symbol-registry.d.ts.map +0 -0
  429. /package/{strings → dist/strings}/constants.d.ts +0 -0
  430. /package/{strings → dist/strings}/constants.d.ts.map +0 -0
  431. /package/{strings → dist/strings}/factories.d.ts +0 -0
  432. /package/{strings → dist/strings}/factories.d.ts.map +0 -0
  433. /package/{strings → dist/strings}/guards.d.ts +0 -0
  434. /package/{strings → dist/strings}/guards.d.ts.map +0 -0
  435. /package/{strings → dist/strings}/types.d.ts +0 -0
  436. /package/{strings → dist/strings}/types.d.ts.map +0 -0
  437. /package/{system → dist/system}/env.d.ts +0 -0
  438. /package/{system → dist/system}/env.d.ts.map +0 -0
  439. /package/{system → dist/system}/graceful-exit.d.ts +0 -0
  440. /package/{system → dist/system}/graceful-exit.d.ts.map +0 -0
  441. /package/{system → dist/system}/index.d.ts +0 -0
  442. /package/{system → dist/system}/index.d.ts.map +0 -0
  443. /package/{system → dist/system}/path.d.ts +0 -0
  444. /package/{system → dist/system}/path.d.ts.map +0 -0
  445. /package/{times → dist/times}/constants.d.ts +0 -0
  446. /package/{times → dist/times}/constants.d.ts.map +0 -0
  447. /package/{times → dist/times}/factories.d.ts +0 -0
  448. /package/{times → dist/times}/factories.d.ts.map +0 -0
  449. /package/{times → dist/times}/guards.d.ts +0 -0
  450. /package/{times → dist/times}/guards.d.ts.map +0 -0
  451. /package/{times → dist/times}/index.d.ts +0 -0
  452. /package/{times → dist/times}/index.d.ts.map +0 -0
  453. /package/{times → dist/times}/operations.d.ts +0 -0
  454. /package/{times → dist/times}/operations.d.ts.map +0 -0
@@ -0,0 +1,18 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeLeafObject(value: unknown, ctx: SerializeContext): Jsonable | undefined {
5
+ if (value instanceof Date) {
6
+ return ctx.replacer({ type: 'date', value: value.toISOString() })
7
+ }
8
+
9
+ if (value instanceof RegExp) {
10
+ return ctx.replacer({ type: 'regexp', value: value.toString() })
11
+ }
12
+
13
+ if (value instanceof URL) {
14
+ return ctx.replacer({ type: 'url', value: value.href })
15
+ }
16
+
17
+ return undefined
18
+ }
@@ -0,0 +1,14 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+
4
+ export function serializeNumber(value: number, ctx: SerializeContext): Jsonable {
5
+ if (Number.isNaN(value)) {
6
+ return ctx.replacer({ type: 'number', value: 'NaN' })
7
+ }
8
+
9
+ if (!Number.isFinite(value)) {
10
+ return ctx.replacer({ type: 'number', value: value > 0 ? 'Infinity' : '-Infinity' })
11
+ }
12
+
13
+ return value
14
+ }
@@ -0,0 +1,62 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext, SerializeValueFn } from '../types'
3
+ import { OMIT_SENTINEL } from '../constants'
4
+
5
+ export function handlePropertyAccessError(error: unknown, strategy: SerializeContext['onPropertyAccess'], key: string | symbol, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
6
+ if (strategy === 'throw') {
7
+ throw error
8
+ }
9
+
10
+ if (strategy === 'omit') {
11
+ return OMIT_SENTINEL
12
+ }
13
+
14
+ return ctx.replacer({ type: 'property-access-error', value: `[Property Access Error: ${String(key)}]` })
15
+ }
16
+
17
+ export function safeAccess(obj: object, key: string | symbol, strategy: SerializeContext['onPropertyAccess'], ctx: SerializeContext): unknown {
18
+ try {
19
+ return (obj as Record<string | symbol, unknown>)[key]
20
+ } catch (error) {
21
+ return handlePropertyAccessError(error, strategy, key, ctx)
22
+ }
23
+ }
24
+
25
+ export function serializeObject(obj: object, ctx: SerializeContext, serializeValue: SerializeValueFn): Record<string, Jsonable> {
26
+ const result: Record<string, Jsonable> = {}
27
+ const { onPropertyAccess, symbolRegistry } = ctx
28
+
29
+ for (const key of Object.keys(obj)) {
30
+ const value = safeAccess(obj, key, onPropertyAccess, ctx)
31
+
32
+ if (value === OMIT_SENTINEL) {
33
+ continue
34
+ }
35
+
36
+ const serializedValue = serializeValue(value, ctx)
37
+
38
+ if (serializedValue === OMIT_SENTINEL) {
39
+ continue
40
+ }
41
+
42
+ result[key] = serializedValue
43
+ }
44
+
45
+ for (const sym of Object.getOwnPropertySymbols(obj)) {
46
+ const value = safeAccess(obj, sym, onPropertyAccess, ctx)
47
+
48
+ if (value === OMIT_SENTINEL) {
49
+ continue
50
+ }
51
+
52
+ const serializedValue = serializeValue(value, ctx)
53
+
54
+ if (serializedValue === OMIT_SENTINEL) {
55
+ continue
56
+ }
57
+
58
+ result[symbolRegistry(sym)] = serializedValue
59
+ }
60
+
61
+ return result
62
+ }
@@ -0,0 +1,36 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+ import { isGenerator } from '../../core'
4
+ import { serializeFunction } from './function'
5
+
6
+ export function serializeOpaque(value: unknown, ctx: SerializeContext): Jsonable | undefined {
7
+ if (typeof value === 'function') {
8
+ return serializeFunction(value as (...args: unknown[]) => unknown, ctx)
9
+ }
10
+
11
+ if (value instanceof Promise) {
12
+ return ctx.replacer({ type: 'promise', value: '[Promise]' })
13
+ }
14
+
15
+ if (value instanceof WeakMap) {
16
+ return ctx.replacer({ type: 'weakmap', value: '[WeakMap]' })
17
+ }
18
+
19
+ if (value instanceof WeakSet) {
20
+ return ctx.replacer({ type: 'weakset', value: '[WeakSet]' })
21
+ }
22
+
23
+ if (typeof WeakRef !== 'undefined' && value instanceof WeakRef) {
24
+ return ctx.replacer({ type: 'weakref', value: '[WeakRef]' })
25
+ }
26
+
27
+ if (typeof ReadableStream !== 'undefined' && value instanceof ReadableStream) {
28
+ return ctx.replacer({ type: 'readablestream', value: '[ReadableStream]' })
29
+ }
30
+
31
+ if (isGenerator(value)) {
32
+ return ctx.replacer({ type: 'generator', value: '[Generator]' })
33
+ }
34
+
35
+ return undefined
36
+ }
@@ -0,0 +1,32 @@
1
+ import type { Jsonable } from '../../core'
2
+ import type { SerializeContext } from '../types'
3
+ import { isBigInt, isJsonablePrimitive, isNumber, isSymbol } from '../../core'
4
+ import { serializeNumber } from './number'
5
+
6
+ export function serializePrimitive(value: unknown, ctx: SerializeContext): Jsonable | undefined {
7
+ if (value === null) {
8
+ return null
9
+ }
10
+
11
+ if (value === undefined) {
12
+ return ctx.replacer({ type: 'undefined', value: null })
13
+ }
14
+
15
+ if (isNumber(value)) {
16
+ return serializeNumber(value, ctx)
17
+ }
18
+
19
+ if (isJsonablePrimitive(value)) {
20
+ return value
21
+ }
22
+
23
+ if (isBigInt(value)) {
24
+ return ctx.replacer({ type: 'bigint', value: value.toString() })
25
+ }
26
+
27
+ if (isSymbol(value)) {
28
+ return ctx.replacer({ type: 'symbol', value: ctx.symbolRegistry(value) })
29
+ }
30
+
31
+ return undefined
32
+ }
@@ -0,0 +1,28 @@
1
+ export function createSymbolKeySerializer() {
2
+ const cache = new Map<symbol, string>()
3
+ const usedKeys = new Set<string>()
4
+
5
+ let counter = 0
6
+
7
+ return (symbol: symbol): string => {
8
+ const cached = cache.get(symbol)
9
+
10
+ if (cached !== undefined) {
11
+ return cached
12
+ }
13
+
14
+ const desc = symbol.description
15
+ const base = desc?.length ? desc : `@@${++counter}`
16
+
17
+ let key = `[Symbol(${base})]`
18
+
19
+ while (usedKeys.has(key)) {
20
+ key = `[Symbol(${base}@@${++counter})]`
21
+ }
22
+
23
+ usedKeys.add(key)
24
+ cache.set(symbol, key)
25
+
26
+ return key
27
+ }
28
+ }
@@ -0,0 +1,42 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { OMIT_SENTINEL } from './constants'
3
+
4
+ export interface SerializedValue {
5
+ __serialized__: true
6
+ metadata?: Record<string, Jsonable>
7
+ type: string
8
+ value: Jsonable
9
+ }
10
+
11
+ export type SerializeReplacer = (value: Omit<SerializedValue, '__serialized__'>) => Jsonable
12
+
13
+ export type SerializeErrorStrategy = 'omit' | 'placeholder' | 'throw'
14
+
15
+ export interface SerializeErrorHandlers {
16
+ circularRef?: SerializeErrorStrategy
17
+ maxDepth?: SerializeErrorStrategy
18
+ propertyAccess?: SerializeErrorStrategy
19
+ }
20
+
21
+ export interface SerializeOptions {
22
+ maxDepth?: number
23
+ onError?: SerializeErrorHandlers | SerializeErrorStrategy
24
+ onUnserializable?: ((value: unknown) => Jsonable) | false
25
+ replacer?: SerializeReplacer
26
+ }
27
+
28
+ export interface SerializeContext {
29
+ depth: number
30
+ readonly maxDepth: number
31
+ readonly onCircularRef: SerializeErrorStrategy
32
+ readonly onMaxDepth: SerializeErrorStrategy
33
+ readonly onPropertyAccess: SerializeErrorStrategy
34
+ readonly onUnserializable: ((value: unknown) => Jsonable) | false
35
+ readonly replacer: SerializeReplacer
36
+ readonly symbolRegistry: (symbol: symbol) => string
37
+ readonly visited: Set<object>
38
+ }
39
+
40
+ export type SerializeValueFn = (value: unknown, ctx: SerializeContext) => Jsonable | typeof OMIT_SENTINEL
41
+
42
+ export type ErrorPropertyValue = Jsonable | typeof OMIT_SENTINEL | undefined
@@ -0,0 +1,15 @@
1
+ import type { Jsonable } from '../core'
2
+ import type { SerializeContext, SerializeErrorStrategy } from './types'
3
+ import { OMIT_SENTINEL } from './constants'
4
+
5
+ export function handleError(strategy: SerializeErrorStrategy, type: string, placeholder: string, ctx: SerializeContext): Jsonable | typeof OMIT_SENTINEL {
6
+ if (strategy === 'throw') {
7
+ throw new Error(placeholder)
8
+ }
9
+
10
+ if (strategy === 'omit') {
11
+ return OMIT_SENTINEL
12
+ }
13
+
14
+ return ctx.replacer({ type, value: placeholder })
15
+ }
@@ -0,0 +1 @@
1
+ export const WHITESPACE_CHARACTERS = new Set([' ', '\n', '\r', '\t', '\v', '\f'])
@@ -0,0 +1,9 @@
1
+ export function randomStr(length = 16, characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789') {
2
+ let result = ''
3
+
4
+ for (let i = 0; i < length; i++) {
5
+ result += characters.charAt(Math.floor(Math.random() * characters.length))
6
+ }
7
+
8
+ return result
9
+ }
@@ -0,0 +1,51 @@
1
+ import type { Nullish } from '../core'
2
+ import type { HexString, UrlLike } from './types'
3
+ import { wrap } from '../arrays'
4
+ import { transform, tryCatch } from '../functions'
5
+
6
+ export const isEmptyString = (value: string) => value.length === 0
7
+
8
+ export function isValidProtocol({ protocol }: URL, protocols?: Nullish<string[]>) {
9
+ if (!protocols?.length) {
10
+ return true
11
+ }
12
+
13
+ return protocols.some((x) => `${x.toLowerCase()}:` === protocol)
14
+ }
15
+
16
+ export function isValidUrl(url: UrlLike, protocols?: Nullish<string[]>) {
17
+ if (url instanceof URL) {
18
+ return isValidProtocol(url, protocols)
19
+ }
20
+
21
+ return tryCatch(() => isValidProtocol(new URL(url), protocols), false)
22
+ }
23
+
24
+ export const isWebSocketUrl = (url: UrlLike, wsProtocols = ['ws', 'wss']) => isValidUrl(url, wsProtocols)
25
+
26
+ export const isHttpUrl = (url: UrlLike, httpProtocols = ['http', 'https']) => isValidUrl(url, httpProtocols)
27
+
28
+ export const isStringEquals = (str: string, ...others: string[]) => others.length > 0 && others.every((other) => str === other)
29
+
30
+ export const isStringEqualsIgnoreCase = (str: string, ...others: string[]) => (
31
+ others.length > 0 && transform(str.toLowerCase(), (x) => others.every((other) => x === other.toLowerCase()))
32
+ )
33
+
34
+ export const isIncludesAll = (str: string, search: string[]) => search.every((s) => str.includes(s))
35
+
36
+ export const isIncludesAny = (str: string, search: string[]) => search.some((s) => str.includes(s))
37
+
38
+ export const isIncludes = (str: string, search: string[] | string, type: 'all' | 'any' = 'all') => (
39
+ type === 'all' ? isIncludesAll(str, wrap(search)) : isIncludesAny(str, wrap(search))
40
+ )
41
+
42
+ export function isHexString(value: string, length?: number) {
43
+ const len = length ? `{${length * 2}}` : '+'
44
+ const regex = new RegExp(`^(?:0x)?[0-9a-f]${len}$`, 'iu')
45
+
46
+ return regex.test(value)
47
+ }
48
+
49
+ export const isStrictHexString = (value: string, length?: number): value is HexString => (
50
+ value.startsWith('0x') && isHexString(value, length)
51
+ )
@@ -0,0 +1,7 @@
1
+ export * from './constants'
2
+ export * from './factories'
3
+ export * from './guards'
4
+ export * from './manipulations'
5
+ export * from './strip-ansi'
6
+
7
+ export type * from './types'
@@ -0,0 +1,145 @@
1
+ import type { Numberish } from '../numbers'
2
+ import { WHITESPACE_CHARACTERS } from './constants'
3
+
4
+ export const ensurePrefix = (str: string, prefix: string) => (str.startsWith(prefix) ? str : prefix + str)
5
+
6
+ export const ensureSuffix = (str: string, suffix: string) => (str.endsWith(suffix) ? str : str + suffix)
7
+
8
+ export const stripPrefix = (str: string, prefix: string) => (str.startsWith(prefix) ? str.slice(prefix.length) : str)
9
+
10
+ export const stripSuffix = (str: string, suffix: string) => (suffix.length > 0 && str.endsWith(suffix) ? str.slice(0, -suffix.length) : str)
11
+
12
+ export const capitalize = (str: string) => str.charAt(0).toUpperCase() + str.slice(1)
13
+
14
+ export const escapeRegExp = (input: string) => (
15
+ input.replaceAll(/[$()*+.?[\\\]^{|}]/gu, String.raw`\$&`).replaceAll('-', String.raw`\x2d`)
16
+ )
17
+
18
+ export function * chunkStr(str: string, size: number) {
19
+ if (size <= 0) {
20
+ throw new RangeError(`chunk size must be a positive number, got ${size}`)
21
+ }
22
+
23
+ const len = str.length
24
+
25
+ for (let i = 0; i < len; i += size) {
26
+ yield str.slice(i, i + size)
27
+ }
28
+ }
29
+
30
+ export const padStart = (str: string, targetLength: number, padString = ' ') => (
31
+ str.padStart(targetLength, padString)
32
+ )
33
+
34
+ export const padZeroStart = (num: Numberish | string, targetLength: number) => padStart(num.toString(), targetLength, '0')
35
+
36
+ export function truncate(str: string, maxLength: number, omission = '...') {
37
+ if (str.length <= maxLength) {
38
+ return str
39
+ }
40
+
41
+ if (omission.length >= maxLength) {
42
+ return omission.slice(0, maxLength)
43
+ }
44
+
45
+ return str.slice(0, maxLength - omission.length) + omission
46
+ }
47
+
48
+ export function truncateMiddle(str: string, maxLength: number, omission = '...') {
49
+ if (str.length <= maxLength) {
50
+ return str
51
+ }
52
+
53
+ if (omission.length >= maxLength) {
54
+ return omission.slice(0, maxLength)
55
+ }
56
+
57
+ const left = Math.floor((maxLength - omission.length) / 2)
58
+ const right = maxLength - omission.length - left
59
+
60
+ return str.slice(0, left) + omission + str.slice(-right)
61
+ }
62
+
63
+ export function ltrim(str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) {
64
+ if (typeof characters === 'string') {
65
+ characters = new Set(characters)
66
+ }
67
+
68
+ const end = str.length
69
+
70
+ let start = 0
71
+
72
+ while (start < end && characters.has(str[start]!)) {
73
+ start++
74
+ }
75
+
76
+ return start > 0 ? str.slice(start, end) : str
77
+ }
78
+
79
+ export function rtrim(str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) {
80
+ if (typeof characters === 'string') {
81
+ characters = new Set(characters)
82
+ }
83
+
84
+ let end = str.length
85
+
86
+ while (end > 0 && characters.has(str[end - 1]!)) {
87
+ end--
88
+ }
89
+
90
+ return end < str.length ? str.slice(0, end) : str
91
+ }
92
+
93
+ export const trim = (str: string, characters: Set<string> | string = WHITESPACE_CHARACTERS) => (
94
+ ltrim(rtrim(str, characters), characters)
95
+ )
96
+
97
+ export const trimRepeated = (input: string, target: string) => (
98
+ input.replaceAll(new RegExp(`(?:${escapeRegExp(target)}){2,}`, 'g'), target)
99
+ )
100
+
101
+ export function indent(str: string, count: number, trim = false) {
102
+ const pad = ' '.repeat(count)
103
+
104
+ if (trim) {
105
+ return str.split('\n').map((line) => pad + ltrim(line)).join('\n')
106
+ }
107
+
108
+ return pad + str.replaceAll('\n', `\n${pad}`)
109
+ }
110
+
111
+ export function unindent(str: TemplateStringsArray | string, ...values: unknown[]) {
112
+ const raw = typeof str === 'string' ? str : String.raw({ raw: str }, ...values)
113
+ const lines = raw.split('\n')
114
+
115
+ // Trim leading/trailing empty lines via slice (immutable)
116
+ let head = 0
117
+ let tail = lines.length
118
+
119
+ while (head < tail && lines[head]!.trim() === '') {
120
+ head++
121
+ }
122
+
123
+ while (tail > head && lines[tail - 1]!.trim() === '') {
124
+ tail--
125
+ }
126
+
127
+ const trimmed = lines.slice(head, tail)
128
+
129
+ // Find minimum indent across non-empty lines
130
+ let minIndent = Infinity
131
+
132
+ for (const line of trimmed) {
133
+ if (line.trim() === '') {
134
+ continue
135
+ }
136
+
137
+ minIndent = Math.min(minIndent, /^[ \t]*/u.exec(line)![0].length)
138
+ }
139
+
140
+ if (minIndent === 0 || minIndent === Infinity) {
141
+ return trimmed.join('\n')
142
+ }
143
+
144
+ return trimmed.map((line) => line.slice(minIndent)).join('\n')
145
+ }
@@ -0,0 +1,14 @@
1
+ // eslint-disable-next-line no-control-regex, regexp/no-control-character, sonarjs/no-control-regex -- ANSI stripping requires matching control characters
2
+ const ANSI_REGEX = /\u001B(?:\[[\d;]*[A-Za-z]|\].*?(?:\u0007|\u001B\\)|\([A-Za-z]|[A-Z])/gu
3
+
4
+ export function stripAnsi(str: string) {
5
+ ANSI_REGEX.lastIndex = 0
6
+
7
+ if (!ANSI_REGEX.test(str)) {
8
+ return str
9
+ }
10
+
11
+ ANSI_REGEX.lastIndex = 0
12
+
13
+ return str.replace(ANSI_REGEX, '')
14
+ }
@@ -0,0 +1,3 @@
1
+ export type UrlLike = URL | string
2
+
3
+ export type HexString = `0x${string}`
@@ -0,0 +1,32 @@
1
+ import { isUndefined } from '../core'
2
+
3
+ export const isInMode = (key: string) => process.env.NODE_ENV === key
4
+
5
+ export const isInDevelopment = () => isInMode('development') || isInMode('dev')
6
+ export const isInDev = isInDevelopment
7
+
8
+ export const isInProduction = () => isInMode('production') || isInMode('prod')
9
+ export const isInProd = isInProduction
10
+
11
+ export const isInStaging = () => isInMode('staging') || isInMode('stage')
12
+ export const isInStage = isInStaging
13
+
14
+ export interface GetEnvOptions {
15
+ env?: NodeJS.ProcessEnv
16
+ includeNonePrefix?: boolean
17
+ prefix?: string
18
+ }
19
+
20
+ export function getEnv<T extends string>(key: T[], { env = process.env, includeNonePrefix = false, prefix }: GetEnvOptions = {}) {
21
+ const result: Record<string, string | undefined> = {}
22
+
23
+ for (const k of key) {
24
+ result[k] = env[prefix ? `${prefix}${k}` : k]
25
+
26
+ if (includeNonePrefix && isUndefined(result[k])) {
27
+ result[k] = env[k]
28
+ }
29
+ }
30
+
31
+ return result as Record<T, string | undefined>
32
+ }
@@ -0,0 +1,23 @@
1
+ import type { UrlLike } from '../strings'
2
+ import { combineSignals, createAbortController } from '../errors'
3
+ import { resolveOptions } from '../objects'
4
+ import { withRetry, type WithRetryOptions } from '../promises'
5
+
6
+ export interface FetchOptions extends Omit<RequestInit, 'signal'> {
7
+ retry?: Omit<WithRetryOptions<Response>, 'signal'> & { enabled?: boolean } | boolean
8
+ signal?: AbortSignal
9
+ timeout?: number
10
+ }
11
+
12
+ export async function fetch(request: RequestInfo | UrlLike, { retry = true, signal, timeout = 10_000, ...options }: FetchOptions = {}) {
13
+ const retryOptions = { enabled: true, ...(resolveOptions(retry, {}) || { enabled: false }) }
14
+
15
+ const execute = async (retrySignal?: AbortSignal) => {
16
+ const controller = createAbortController(timeout)
17
+ const fetchSignal = combineSignals(controller.signal, signal, retrySignal)
18
+
19
+ return globalThis.fetch(request, { ...options, signal: fetchSignal }).finally(() => controller.abort())
20
+ }
21
+
22
+ return retryOptions.enabled ? await withRetry(execute, { ...retryOptions, signal }) : await execute()
23
+ }
@@ -0,0 +1,46 @@
1
+ export type ExitHandler = (exitCode?: number) => Promise<void>
2
+
3
+ const exitTasks = new Map<ExitHandler, number>()
4
+
5
+ export function addExitHandler(handler: ExitHandler, maxWaitTime = 3000) {
6
+ exitTasks.set(handler, maxWaitTime)
7
+
8
+ return () => {
9
+ exitTasks.delete(handler)
10
+ }
11
+ }
12
+
13
+ let _isExiting = false
14
+ let _exitPromise: Promise<never> | undefined
15
+
16
+ export const isExiting = () => {
17
+ return _isExiting
18
+ }
19
+
20
+ export function gracefulExit(exitCode = 0, maxWaitTime = 3000): Promise<never> {
21
+ if (_exitPromise) {
22
+ return _exitPromise
23
+ }
24
+
25
+ _isExiting = true
26
+
27
+ if (exitTasks.size === 0) {
28
+ process.exit(exitCode)
29
+ }
30
+
31
+ const promises: Array<Promise<void>> = []
32
+
33
+ for (const [handler, wait] of exitTasks) {
34
+ promises.push(Promise.resolve().then(() => handler(exitCode)))
35
+ maxWaitTime = Math.max(maxWaitTime, wait)
36
+ }
37
+
38
+ const timer = setTimeout(() => process.exit(exitCode), maxWaitTime)
39
+
40
+ function finish(): never {
41
+ clearTimeout(timer)
42
+ process.exit(exitCode)
43
+ }
44
+
45
+ return _exitPromise = Promise.allSettled(promises).then(finish)
46
+ }
@@ -0,0 +1,6 @@
1
+ export * from './env'
2
+ export * from './fetch'
3
+ export * from './graceful-exit'
4
+ export * from './path'
5
+
6
+ export type * from './types'
@@ -0,0 +1,12 @@
1
+ import type { PathLike } from './types'
2
+ import { dirname, join } from 'node:path'
3
+ import { fileURLToPath } from 'node:url'
4
+ import { bufferToString, isBufferLike } from '../buffers'
5
+
6
+ export const pathToString = (path: PathLike) => (
7
+ isBufferLike(path) ? bufferToString(path) : path.toString()
8
+ )
9
+
10
+ export const pwd = (importMeta: ImportMeta, ...path: PathLike[]) => (
11
+ join(dirname(fileURLToPath(importMeta.url)), ...path.map(pathToString))
12
+ )
@@ -0,0 +1,3 @@
1
+ import type { BufferLike } from '../buffers'
2
+
3
+ export type PathLike = BufferLike | URL | string
@@ -0,0 +1,6 @@
1
+ export const MS_PER_SECOND = 1000
2
+ export const MS_PER_MINUTE = 60_000
3
+ export const MS_PER_HOUR = 3_600_000
4
+ export const MS_PER_DAY = 86_400_000
5
+ export const MS_PER_MONTH = MS_PER_DAY * 30
6
+ export const MS_PER_YEAR = MS_PER_DAY * 365