zeed 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (575) hide show
  1. package/AGENTS.md +50 -211
  2. package/README.md +16 -0
  3. package/dist/_experiments/bitcask.cjs +243 -1
  4. package/dist/_experiments/bitcask.cjs.map +1 -1
  5. package/dist/_experiments/bitcask.mjs +230 -1
  6. package/dist/_experiments/bitcask.mjs.map +1 -1
  7. package/dist/bin-BAoS4qtm.mjs +593 -0
  8. package/dist/{bin-SPdenYkw.mjs.map → bin-BAoS4qtm.mjs.map} +1 -1
  9. package/dist/bin-Ddaz2lxM.cjs +862 -0
  10. package/dist/{bin-Ce3i6ABn.cjs.map → bin-Ddaz2lxM.cjs.map} +1 -1
  11. package/dist/browser/base64.cjs +14 -1
  12. package/dist/browser/base64.cjs.map +1 -1
  13. package/dist/browser/base64.mjs +12 -1
  14. package/dist/browser/base64.mjs.map +1 -1
  15. package/dist/browser/gravatar.cjs +186 -1
  16. package/dist/browser/gravatar.cjs.map +1 -1
  17. package/dist/browser/gravatar.mjs +184 -1
  18. package/dist/browser/gravatar.mjs.map +1 -1
  19. package/dist/browser/index.cjs +14 -1
  20. package/dist/browser/index.mjs +8 -1
  21. package/dist/browser/localstorage.cjs +46 -1
  22. package/dist/browser/localstorage.cjs.map +1 -1
  23. package/dist/browser/localstorage.mjs +45 -1
  24. package/dist/browser/localstorage.mjs.map +1 -1
  25. package/dist/browser/log/index.cjs +8 -1
  26. package/dist/browser/log/index.mjs +5 -1
  27. package/dist/browser/log/log-browser-factory.cjs +65 -1
  28. package/dist/browser/log/log-browser-factory.cjs.map +1 -1
  29. package/dist/browser/log/log-browser-factory.mjs +64 -1
  30. package/dist/browser/log/log-browser-factory.mjs.map +1 -1
  31. package/dist/browser/log/log-browser.cjs +72 -1
  32. package/dist/browser/log/log-browser.cjs.map +1 -1
  33. package/dist/browser/log/log-browser.mjs +71 -1
  34. package/dist/browser/log/log-browser.mjs.map +1 -1
  35. package/dist/browser/log/log-colors.cjs +11 -1
  36. package/dist/browser/log/log-colors.cjs.map +1 -1
  37. package/dist/browser/log/log-colors.mjs +9 -1
  38. package/dist/browser/log/log-colors.mjs.map +1 -1
  39. package/dist/browser/log/log-context-browser.cjs +25 -1
  40. package/dist/browser/log/log-context-browser.cjs.map +1 -1
  41. package/dist/browser/log/log-context-browser.mjs +23 -1
  42. package/dist/browser/log/log-context-browser.mjs.map +1 -1
  43. package/dist/chunk-DQk6qfdC.mjs +18 -0
  44. package/dist/chunk-uaV2rQ02.cjs +53 -0
  45. package/dist/common/assert.cjs +22 -1
  46. package/dist/common/assert.cjs.map +1 -1
  47. package/dist/common/assert.mjs +19 -1
  48. package/dist/common/assert.mjs.map +1 -1
  49. package/dist/common/bin/index.cjs +106 -1
  50. package/dist/common/bin/index.cjs.map +1 -1
  51. package/dist/common/bin/index.mjs +98 -1
  52. package/dist/common/bin/index.mjs.map +1 -1
  53. package/dist/common/bin/lib0/binary.cjs +146 -1
  54. package/dist/common/bin/lib0/binary.cjs.map +1 -1
  55. package/dist/common/bin/lib0/binary.mjs +80 -1
  56. package/dist/common/bin/lib0/binary.mjs.map +1 -1
  57. package/dist/common/bin/lib0/buffer.cjs +42 -1
  58. package/dist/common/bin/lib0/buffer.cjs.map +1 -1
  59. package/dist/common/bin/lib0/buffer.mjs +38 -1
  60. package/dist/common/bin/lib0/buffer.mjs.map +1 -1
  61. package/dist/common/bin/lib0/create.cjs +24 -1
  62. package/dist/common/bin/lib0/create.cjs.map +1 -1
  63. package/dist/common/bin/lib0/create.mjs +21 -1
  64. package/dist/common/bin/lib0/create.mjs.map +1 -1
  65. package/dist/common/bin/lib0/decoding.cjs +325 -1
  66. package/dist/common/bin/lib0/decoding.cjs.map +1 -1
  67. package/dist/common/bin/lib0/decoding.mjs +298 -1
  68. package/dist/common/bin/lib0/decoding.mjs.map +1 -1
  69. package/dist/common/bin/lib0/encoding.cjs +404 -1
  70. package/dist/common/bin/lib0/encoding.cjs.map +1 -1
  71. package/dist/common/bin/lib0/encoding.mjs +377 -1
  72. package/dist/common/bin/lib0/encoding.mjs.map +1 -1
  73. package/dist/common/bin/lib0/string.cjs +81 -1
  74. package/dist/common/bin/lib0/string.cjs.map +1 -1
  75. package/dist/common/bin/lib0/string.mjs +71 -1
  76. package/dist/common/bin/lib0/string.mjs.map +1 -1
  77. package/dist/common/crypto/aes-sealed.cjs +34 -1
  78. package/dist/common/crypto/aes-sealed.cjs.map +1 -1
  79. package/dist/common/crypto/aes-sealed.mjs +32 -1
  80. package/dist/common/crypto/aes-sealed.mjs.map +1 -1
  81. package/dist/common/crypto/crypto.cjs +91 -1
  82. package/dist/common/crypto/crypto.cjs.map +1 -1
  83. package/dist/common/crypto/crypto.mjs +80 -1
  84. package/dist/common/crypto/crypto.mjs.map +1 -1
  85. package/dist/common/crypto/index.cjs +23 -1
  86. package/dist/common/crypto/index.mjs +5 -1
  87. package/dist/common/crypto/xaes.cjs +128 -1
  88. package/dist/common/crypto/xaes.cjs.map +1 -1
  89. package/dist/common/crypto/xaes.mjs +123 -1
  90. package/dist/common/crypto/xaes.mjs.map +1 -1
  91. package/dist/common/csv.cjs +49 -4
  92. package/dist/common/csv.cjs.map +1 -1
  93. package/dist/common/csv.mjs +46 -4
  94. package/dist/common/csv.mjs.map +1 -1
  95. package/dist/common/data/array.cjs +299 -1
  96. package/dist/common/data/array.cjs.map +1 -1
  97. package/dist/common/data/array.mjs +274 -1
  98. package/dist/common/data/array.mjs.map +1 -1
  99. package/dist/common/data/basex-secure.cjs +30 -1
  100. package/dist/common/data/basex-secure.mjs +3 -1
  101. package/dist/common/data/basex.cjs +163 -1
  102. package/dist/common/data/basex.cjs.map +1 -1
  103. package/dist/common/data/basex.mjs +152 -1
  104. package/dist/common/data/basex.mjs.map +1 -1
  105. package/dist/common/data/bin-types.mjs +1 -1
  106. package/dist/common/data/bin.cjs +21 -1
  107. package/dist/common/data/bin.mjs +3 -1
  108. package/dist/common/data/camelcase.cjs +27 -1
  109. package/dist/common/data/camelcase.cjs.map +1 -1
  110. package/dist/common/data/camelcase.mjs +22 -1
  111. package/dist/common/data/camelcase.mjs.map +1 -1
  112. package/dist/common/data/convert.cjs +104 -1
  113. package/dist/common/data/convert.cjs.map +1 -1
  114. package/dist/common/data/convert.mjs +88 -1
  115. package/dist/common/data/convert.mjs.map +1 -1
  116. package/dist/common/data/datauri.cjs +32 -1
  117. package/dist/common/data/datauri.cjs.map +1 -1
  118. package/dist/common/data/datauri.mjs +27 -1
  119. package/dist/common/data/datauri.mjs.map +1 -1
  120. package/dist/common/data/day-legacy.cjs +148 -1
  121. package/dist/common/data/day-legacy.cjs.map +1 -1
  122. package/dist/common/data/day-legacy.mjs +143 -1
  123. package/dist/common/data/day-legacy.mjs.map +1 -1
  124. package/dist/common/data/day.cjs +335 -1
  125. package/dist/common/data/day.cjs.map +1 -1
  126. package/dist/common/data/day.mjs +305 -1
  127. package/dist/common/data/day.mjs.map +1 -1
  128. package/dist/common/data/decimal.cjs +28 -1
  129. package/dist/common/data/decimal.cjs.map +1 -1
  130. package/dist/common/data/decimal.mjs +23 -1
  131. package/dist/common/data/decimal.mjs.map +1 -1
  132. package/dist/common/data/deep.cjs +57 -1
  133. package/dist/common/data/deep.cjs.map +1 -1
  134. package/dist/common/data/deep.mjs +54 -1
  135. package/dist/common/data/deep.mjs.map +1 -1
  136. package/dist/common/data/diff.cjs +62 -1
  137. package/dist/common/data/diff.cjs.map +1 -1
  138. package/dist/common/data/diff.mjs +60 -1
  139. package/dist/common/data/diff.mjs.map +1 -1
  140. package/dist/common/data/distributed.cjs +24 -1
  141. package/dist/common/data/distributed.cjs.map +1 -1
  142. package/dist/common/data/distributed.mjs +22 -1
  143. package/dist/common/data/distributed.mjs.map +1 -1
  144. package/dist/common/data/format.cjs +63 -1
  145. package/dist/common/data/format.cjs.map +1 -1
  146. package/dist/common/data/format.mjs +59 -1
  147. package/dist/common/data/format.mjs.map +1 -1
  148. package/dist/common/data/html.cjs +13 -1
  149. package/dist/common/data/html.cjs.map +1 -1
  150. package/dist/common/data/html.mjs +10 -1
  151. package/dist/common/data/html.mjs.map +1 -1
  152. package/dist/common/data/index.cjs +296 -1
  153. package/dist/common/data/index.mjs +37 -1
  154. package/dist/common/data/is.cjs +106 -1
  155. package/dist/common/data/is.cjs.map +1 -1
  156. package/dist/common/data/is.mjs +85 -1
  157. package/dist/common/data/is.mjs.map +1 -1
  158. package/dist/common/data/json.cjs +70 -1
  159. package/dist/common/data/json.cjs.map +1 -1
  160. package/dist/common/data/json.mjs +65 -1
  161. package/dist/common/data/json.mjs.map +1 -1
  162. package/dist/common/data/list.cjs +32 -1
  163. package/dist/common/data/list.cjs.map +1 -1
  164. package/dist/common/data/list.mjs +27 -1
  165. package/dist/common/data/list.mjs.map +1 -1
  166. package/dist/common/data/lru.mjs +1 -1
  167. package/dist/common/data/math.cjs +79 -1
  168. package/dist/common/data/math.cjs.map +1 -1
  169. package/dist/common/data/math.mjs +65 -1
  170. package/dist/common/data/math.mjs.map +1 -1
  171. package/dist/common/data/message.cjs +30 -1
  172. package/dist/common/data/message.cjs.map +1 -1
  173. package/dist/common/data/message.mjs +28 -1
  174. package/dist/common/data/message.mjs.map +1 -1
  175. package/dist/common/data/object-changes.cjs +66 -1
  176. package/dist/common/data/object-changes.cjs.map +1 -1
  177. package/dist/common/data/object-changes.mjs +63 -1
  178. package/dist/common/data/object-changes.mjs.map +1 -1
  179. package/dist/common/data/object.cjs +112 -1
  180. package/dist/common/data/object.cjs.map +1 -1
  181. package/dist/common/data/object.mjs +104 -1
  182. package/dist/common/data/object.mjs.map +1 -1
  183. package/dist/common/data/orderby.cjs +42 -1
  184. package/dist/common/data/orderby.cjs.map +1 -1
  185. package/dist/common/data/orderby.mjs +37 -1
  186. package/dist/common/data/orderby.mjs.map +1 -1
  187. package/dist/common/data/path.cjs +26 -1
  188. package/dist/common/data/path.cjs.map +1 -1
  189. package/dist/common/data/path.mjs +25 -1
  190. package/dist/common/data/path.mjs.map +1 -1
  191. package/dist/common/data/regexp.cjs +12 -1
  192. package/dist/common/data/regexp.cjs.map +1 -1
  193. package/dist/common/data/regexp.mjs +10 -1
  194. package/dist/common/data/regexp.mjs.map +1 -1
  195. package/dist/common/data/rounding.cjs +107 -1
  196. package/dist/common/data/rounding.cjs.map +1 -1
  197. package/dist/common/data/rounding.mjs +95 -1
  198. package/dist/common/data/rounding.mjs.map +1 -1
  199. package/dist/common/data/signal.cjs +39 -1
  200. package/dist/common/data/signal.cjs.map +1 -1
  201. package/dist/common/data/signal.mjs +38 -1
  202. package/dist/common/data/signal.mjs.map +1 -1
  203. package/dist/common/data/sortable.cjs +35 -1
  204. package/dist/common/data/sortable.cjs.map +1 -1
  205. package/dist/common/data/sortable.mjs +31 -1
  206. package/dist/common/data/sortable.mjs.map +1 -1
  207. package/dist/common/data/sorted.cjs +54 -1
  208. package/dist/common/data/sorted.cjs.map +1 -1
  209. package/dist/common/data/sorted.mjs +53 -1
  210. package/dist/common/data/sorted.mjs.map +1 -1
  211. package/dist/common/data/string-deburr.cjs +240 -1
  212. package/dist/common/data/string-deburr.cjs.map +1 -1
  213. package/dist/common/data/string-deburr.mjs +238 -1
  214. package/dist/common/data/string-deburr.mjs.map +1 -1
  215. package/dist/common/data/string-hash-fnv.cjs +69 -1
  216. package/dist/common/data/string-hash-fnv.cjs.map +1 -1
  217. package/dist/common/data/string-hash-fnv.mjs +67 -1
  218. package/dist/common/data/string-hash-fnv.mjs.map +1 -1
  219. package/dist/common/data/string-hash-pool.cjs +28 -1
  220. package/dist/common/data/string-hash-pool.cjs.map +1 -1
  221. package/dist/common/data/string-hash-pool.mjs +27 -1
  222. package/dist/common/data/string-hash-pool.mjs.map +1 -1
  223. package/dist/common/data/url.cjs +98 -2
  224. package/dist/common/data/url.cjs.map +1 -1
  225. package/dist/common/data/url.mjs +91 -2
  226. package/dist/common/data/url.mjs.map +1 -1
  227. package/dist/common/data/utils.cjs +118 -1
  228. package/dist/common/data/utils.cjs.map +1 -1
  229. package/dist/common/data/utils.mjs +107 -1
  230. package/dist/common/data/utils.mjs.map +1 -1
  231. package/dist/common/data/wordlist.cjs +531 -1
  232. package/dist/common/data/wordlist.cjs.map +1 -1
  233. package/dist/common/data/wordlist.mjs +529 -1
  234. package/dist/common/data/wordlist.mjs.map +1 -1
  235. package/dist/common/data/xrx.cjs +96 -1
  236. package/dist/common/data/xrx.cjs.map +1 -1
  237. package/dist/common/data/xrx.mjs +92 -1
  238. package/dist/common/data/xrx.mjs.map +1 -1
  239. package/dist/common/dispose-defer.cjs +133 -1
  240. package/dist/common/dispose-defer.cjs.map +1 -1
  241. package/dist/common/dispose-defer.mjs +130 -1
  242. package/dist/common/dispose-defer.mjs.map +1 -1
  243. package/dist/common/dispose-types.mjs +1 -1
  244. package/dist/common/dispose-utils.cjs +113 -1
  245. package/dist/common/dispose-utils.cjs.map +1 -1
  246. package/dist/common/dispose-utils.mjs +106 -1
  247. package/dist/common/dispose-utils.mjs.map +1 -1
  248. package/dist/common/exec/index.cjs +24 -1
  249. package/dist/common/exec/index.d.cts +1 -1
  250. package/dist/common/exec/index.d.mts +1 -1
  251. package/dist/common/exec/index.mjs +8 -1
  252. package/dist/common/exec/mutex.cjs +44 -1
  253. package/dist/common/exec/mutex.cjs.map +1 -1
  254. package/dist/common/exec/mutex.mjs +42 -1
  255. package/dist/common/exec/mutex.mjs.map +1 -1
  256. package/dist/common/exec/pool.cjs +181 -1
  257. package/dist/common/exec/pool.cjs.map +1 -1
  258. package/dist/common/exec/pool.d.cts +1 -1
  259. package/dist/common/exec/pool.d.mts +1 -1
  260. package/dist/common/exec/pool.mjs +180 -1
  261. package/dist/common/exec/pool.mjs.map +1 -1
  262. package/dist/common/exec/progress.cjs +149 -1
  263. package/dist/common/exec/progress.cjs.map +1 -1
  264. package/dist/common/exec/progress.d.cts +1 -1
  265. package/dist/common/exec/progress.d.mts +1 -1
  266. package/dist/common/exec/progress.mjs +148 -1
  267. package/dist/common/exec/progress.mjs.map +1 -1
  268. package/dist/common/exec/promise.cjs +113 -1
  269. package/dist/common/exec/promise.cjs.map +1 -1
  270. package/dist/common/exec/promise.mjs +103 -1
  271. package/dist/common/exec/promise.mjs.map +1 -1
  272. package/dist/common/exec/queue.cjs +125 -1
  273. package/dist/common/exec/queue.cjs.map +1 -1
  274. package/dist/common/exec/queue.d.cts +1 -1
  275. package/dist/common/exec/queue.d.mts +1 -1
  276. package/dist/common/exec/queue.mjs +124 -1
  277. package/dist/common/exec/queue.mjs.map +1 -1
  278. package/dist/common/exec/throttle-debounce.cjs +114 -1
  279. package/dist/common/exec/throttle-debounce.cjs.map +1 -1
  280. package/dist/common/exec/throttle-debounce.mjs +112 -1
  281. package/dist/common/exec/throttle-debounce.mjs.map +1 -1
  282. package/dist/common/global.cjs +22 -1
  283. package/dist/common/global.cjs.map +1 -1
  284. package/dist/common/global.mjs +19 -1
  285. package/dist/common/global.mjs.map +1 -1
  286. package/dist/common/index.cjs +559 -1
  287. package/dist/common/index.d.cts +1 -1
  288. package/dist/common/index.d.mts +1 -1
  289. package/dist/common/index.mjs +89 -1
  290. package/dist/common/localhost.cjs +16 -1
  291. package/dist/common/localhost.cjs.map +1 -1
  292. package/dist/common/localhost.mjs +14 -1
  293. package/dist/common/localhost.mjs.map +1 -1
  294. package/dist/common/log/index.cjs +34 -1
  295. package/dist/common/log/index.mjs +11 -1
  296. package/dist/common/log/log-base.cjs +40 -1
  297. package/dist/common/log/log-base.cjs.map +1 -1
  298. package/dist/common/log/log-base.mjs +31 -1
  299. package/dist/common/log/log-base.mjs.map +1 -1
  300. package/dist/common/log/log-colors.cjs +92 -1
  301. package/dist/common/log/log-colors.cjs.map +1 -1
  302. package/dist/common/log/log-colors.mjs +90 -1
  303. package/dist/common/log/log-colors.mjs.map +1 -1
  304. package/dist/common/log/log-config.cjs +15 -1
  305. package/dist/common/log/log-config.cjs.map +1 -1
  306. package/dist/common/log/log-config.mjs +14 -1
  307. package/dist/common/log/log-config.mjs.map +1 -1
  308. package/dist/common/log/log-console-capture.cjs +33 -1
  309. package/dist/common/log/log-console-capture.cjs.map +1 -1
  310. package/dist/common/log/log-console-capture.mjs +32 -1
  311. package/dist/common/log/log-console-capture.mjs.map +1 -1
  312. package/dist/common/log/log-console-original.cjs +27 -1
  313. package/dist/common/log/log-console-original.cjs.map +1 -1
  314. package/dist/common/log/log-console-original.mjs +26 -1
  315. package/dist/common/log/log-console-original.mjs.map +1 -1
  316. package/dist/common/log/log-console.cjs +39 -1
  317. package/dist/common/log/log-console.cjs.map +1 -1
  318. package/dist/common/log/log-console.mjs +38 -1
  319. package/dist/common/log/log-console.mjs.map +1 -1
  320. package/dist/common/log/log-context.cjs +109 -1
  321. package/dist/common/log/log-context.cjs.map +1 -1
  322. package/dist/common/log/log-context.mjs +108 -1
  323. package/dist/common/log/log-context.mjs.map +1 -1
  324. package/dist/common/log/log-filter.cjs +80 -1
  325. package/dist/common/log/log-filter.cjs.map +1 -1
  326. package/dist/common/log/log-filter.mjs +75 -1
  327. package/dist/common/log/log-filter.mjs.map +1 -1
  328. package/dist/common/log/log-memory.cjs +45 -1
  329. package/dist/common/log/log-memory.cjs.map +1 -1
  330. package/dist/common/log/log-memory.mjs +43 -1
  331. package/dist/common/log/log-memory.mjs.map +1 -1
  332. package/dist/common/log/log-noop.cjs +17 -1
  333. package/dist/common/log/log-noop.cjs.map +1 -1
  334. package/dist/common/log/log-noop.mjs +15 -1
  335. package/dist/common/log/log-noop.mjs.map +1 -1
  336. package/dist/common/log/log.cjs +46 -1
  337. package/dist/common/log/log.cjs.map +1 -1
  338. package/dist/common/log/log.mjs +43 -1
  339. package/dist/common/log/log.mjs.map +1 -1
  340. package/dist/common/msg/channel-debug.cjs +17 -1
  341. package/dist/common/msg/channel-debug.cjs.map +1 -1
  342. package/dist/common/msg/channel-debug.d.cts +1 -1
  343. package/dist/common/msg/channel-debug.d.mts +1 -1
  344. package/dist/common/msg/channel-debug.mjs +16 -1
  345. package/dist/common/msg/channel-debug.mjs.map +1 -1
  346. package/dist/common/msg/channel-local.cjs +28 -1
  347. package/dist/common/msg/channel-local.cjs.map +1 -1
  348. package/dist/common/msg/channel-local.d.cts +1 -1
  349. package/dist/common/msg/channel-local.d.mts +1 -1
  350. package/dist/common/msg/channel-local.mjs +26 -1
  351. package/dist/common/msg/channel-local.mjs.map +1 -1
  352. package/dist/common/msg/channel-resilient.cjs +63 -1
  353. package/dist/common/msg/channel-resilient.cjs.map +1 -1
  354. package/dist/common/msg/channel-resilient.d.cts +1 -1
  355. package/dist/common/msg/channel-resilient.d.mts +1 -1
  356. package/dist/common/msg/channel-resilient.mjs +62 -1
  357. package/dist/common/msg/channel-resilient.mjs.map +1 -1
  358. package/dist/common/msg/channel-wkwebview.cjs +35 -1
  359. package/dist/common/msg/channel-wkwebview.cjs.map +1 -1
  360. package/dist/common/msg/channel-wkwebview.d.cts +2 -1
  361. package/dist/common/msg/channel-wkwebview.d.mts +2 -1
  362. package/dist/common/msg/channel-wkwebview.mjs +34 -1
  363. package/dist/common/msg/channel-wkwebview.mjs.map +1 -1
  364. package/dist/common/msg/channel.cjs +23 -1
  365. package/dist/common/msg/channel.cjs.map +1 -1
  366. package/dist/common/msg/channel.d.cts +1 -1
  367. package/dist/common/msg/channel.d.mts +1 -1
  368. package/dist/common/msg/channel.mjs +22 -1
  369. package/dist/common/msg/channel.mjs.map +1 -1
  370. package/dist/common/msg/emitter.cjs +141 -1
  371. package/dist/common/msg/emitter.cjs.map +1 -1
  372. package/dist/common/msg/emitter.d.cts +1 -1
  373. package/dist/common/msg/emitter.d.mts +1 -1
  374. package/dist/common/msg/emitter.mjs +139 -1
  375. package/dist/common/msg/emitter.mjs.map +1 -1
  376. package/dist/common/msg/encoder.cjs +38 -1
  377. package/dist/common/msg/encoder.cjs.map +1 -1
  378. package/dist/common/msg/encoder.mjs +35 -1
  379. package/dist/common/msg/encoder.mjs.map +1 -1
  380. package/dist/common/msg/index.cjs +28 -1
  381. package/dist/common/msg/index.d.cts +1 -1
  382. package/dist/common/msg/index.d.mts +1 -1
  383. package/dist/common/msg/index.mjs +11 -1
  384. package/dist/common/msg/messages.cjs +135 -1
  385. package/dist/common/msg/messages.cjs.map +1 -1
  386. package/dist/common/msg/messages.d.cts +1 -1
  387. package/dist/common/msg/messages.d.mts +1 -1
  388. package/dist/common/msg/messages.mjs +133 -1
  389. package/dist/common/msg/messages.mjs.map +1 -1
  390. package/dist/common/msg/pipe.mjs +1 -1
  391. package/dist/common/msg/pubsub.cjs +78 -1
  392. package/dist/common/msg/pubsub.cjs.map +1 -1
  393. package/dist/common/msg/pubsub.d.cts +1 -1
  394. package/dist/common/msg/pubsub.d.mts +1 -1
  395. package/dist/common/msg/pubsub.mjs +76 -1
  396. package/dist/common/msg/pubsub.mjs.map +1 -1
  397. package/dist/common/msg/rpc.cjs +142 -1
  398. package/dist/common/msg/rpc.cjs.map +1 -1
  399. package/dist/common/msg/rpc.mjs +139 -1
  400. package/dist/common/msg/rpc.mjs.map +1 -1
  401. package/dist/common/network.cjs +129 -1
  402. package/dist/common/network.cjs.map +1 -1
  403. package/dist/common/network.mjs +122 -1
  404. package/dist/common/network.mjs.map +1 -1
  405. package/dist/common/platform.cjs +92 -1
  406. package/dist/common/platform.cjs.map +1 -1
  407. package/dist/common/platform.mjs +84 -1
  408. package/dist/common/platform.mjs.map +1 -1
  409. package/dist/common/schema/_sandbox/sandbox-inherit.mjs +1 -1
  410. package/dist/common/schema/_sandbox/sandbox.mjs +1 -1
  411. package/dist/common/schema/_sandbox/sandbox.xspec.mjs +1 -1
  412. package/dist/common/schema/export-json-schema.cjs +54 -1
  413. package/dist/common/schema/export-json-schema.cjs.map +1 -1
  414. package/dist/common/schema/export-json-schema.mjs +52 -1
  415. package/dist/common/schema/export-json-schema.mjs.map +1 -1
  416. package/dist/common/schema/export-swift.cjs +30 -2
  417. package/dist/common/schema/export-swift.cjs.map +1 -1
  418. package/dist/common/schema/export-swift.mjs +29 -2
  419. package/dist/common/schema/export-swift.mjs.map +1 -1
  420. package/dist/common/schema/export-typescript.cjs +20 -2
  421. package/dist/common/schema/export-typescript.cjs.map +1 -1
  422. package/dist/common/schema/export-typescript.mjs +19 -2
  423. package/dist/common/schema/export-typescript.mjs.map +1 -1
  424. package/dist/common/schema/index.cjs +55 -1
  425. package/dist/common/schema/index.mjs +12 -1
  426. package/dist/common/schema/parse-args.cjs +62 -2
  427. package/dist/common/schema/parse-args.cjs.map +1 -1
  428. package/dist/common/schema/parse-args.mjs +60 -2
  429. package/dist/common/schema/parse-args.mjs.map +1 -1
  430. package/dist/common/schema/parse-env.cjs +48 -3
  431. package/dist/common/schema/parse-env.cjs.map +1 -1
  432. package/dist/common/schema/parse-env.mjs +46 -3
  433. package/dist/common/schema/parse-env.mjs.map +1 -1
  434. package/dist/common/schema/parse-object.cjs +122 -1
  435. package/dist/common/schema/parse-object.cjs.map +1 -1
  436. package/dist/common/schema/parse-object.mjs +119 -1
  437. package/dist/common/schema/parse-object.mjs.map +1 -1
  438. package/dist/common/schema/schema-standard.mjs +1 -1
  439. package/dist/common/schema/schema.cjs +423 -1
  440. package/dist/common/schema/schema.cjs.map +1 -1
  441. package/dist/common/schema/schema.mjs +404 -1
  442. package/dist/common/schema/schema.mjs.map +1 -1
  443. package/dist/common/schema/serialize.cjs +109 -1
  444. package/dist/common/schema/serialize.cjs.map +1 -1
  445. package/dist/common/schema/serialize.mjs +107 -1
  446. package/dist/common/schema/serialize.mjs.map +1 -1
  447. package/dist/common/schema/type-test.mjs +1 -1
  448. package/dist/common/schema/utils.cjs +25 -1
  449. package/dist/common/schema/utils.cjs.map +1 -1
  450. package/dist/common/schema/utils.mjs +19 -1
  451. package/dist/common/schema/utils.mjs.map +1 -1
  452. package/dist/common/schema/z-collection.cjs +51 -1
  453. package/dist/common/schema/z-collection.mjs +27 -1
  454. package/dist/common/schema/z.cjs +9 -1
  455. package/dist/common/schema/z.mjs +3 -1
  456. package/dist/common/storage/index.cjs +4 -1
  457. package/dist/common/storage/index.mjs +3 -1
  458. package/dist/common/storage/memstorage.cjs +26 -1
  459. package/dist/common/storage/memstorage.cjs.map +1 -1
  460. package/dist/common/storage/memstorage.mjs +25 -1
  461. package/dist/common/storage/memstorage.mjs.map +1 -1
  462. package/dist/common/test.cjs +14 -1
  463. package/dist/common/test.cjs.map +1 -1
  464. package/dist/common/test.mjs +13 -1
  465. package/dist/common/test.mjs.map +1 -1
  466. package/dist/common/time.cjs +220 -1
  467. package/dist/common/time.cjs.map +1 -1
  468. package/dist/common/time.mjs +194 -1
  469. package/dist/common/time.mjs.map +1 -1
  470. package/dist/common/timeout.cjs +27 -1
  471. package/dist/common/timeout.cjs.map +1 -1
  472. package/dist/common/timeout.mjs +25 -1
  473. package/dist/common/timeout.mjs.map +1 -1
  474. package/dist/common/types.mjs +1 -1
  475. package/dist/common/utils.cjs +7 -1
  476. package/dist/common/utils.cjs.map +1 -1
  477. package/dist/common/utils.mjs +5 -1
  478. package/dist/common/utils.mjs.map +1 -1
  479. package/dist/common/uuid.cjs +307 -1
  480. package/dist/common/uuid.cjs.map +1 -1
  481. package/dist/common/uuid.mjs +284 -1
  482. package/dist/common/uuid.mjs.map +1 -1
  483. package/dist/{index-DHXVOH8h.d.cts → index-CFkMqHvX.d.cts} +1 -2
  484. package/dist/{index-DMaPyx9O.d.mts → index-C_3Y_s6f.d.mts} +1 -2
  485. package/dist/index.all.cjs +641 -1
  486. package/dist/index.all.d.cts +1 -1
  487. package/dist/index.all.d.mts +1 -1
  488. package/dist/index.all.mjs +113 -1
  489. package/dist/index.browser.cjs +576 -1
  490. package/dist/index.browser.d.cts +1 -1
  491. package/dist/index.browser.d.mts +1 -1
  492. package/dist/index.browser.mjs +98 -1
  493. package/dist/index.jsr.cjs +57 -1
  494. package/dist/index.jsr.mjs +6 -1
  495. package/dist/index.node.cjs +628 -1
  496. package/dist/index.node.d.cts +1 -1
  497. package/dist/index.node.d.mts +1 -1
  498. package/dist/index.node.mjs +106 -1
  499. package/dist/node/args.cjs +56 -1
  500. package/dist/node/args.cjs.map +1 -1
  501. package/dist/node/args.mjs +53 -1
  502. package/dist/node/args.mjs.map +1 -1
  503. package/dist/node/clipboard.cjs +18 -1
  504. package/dist/node/clipboard.cjs.map +1 -1
  505. package/dist/node/clipboard.mjs +16 -1
  506. package/dist/node/clipboard.mjs.map +1 -1
  507. package/dist/node/crypto.cjs +28 -1
  508. package/dist/node/crypto.cjs.map +1 -1
  509. package/dist/node/crypto.mjs +24 -1
  510. package/dist/node/crypto.mjs.map +1 -1
  511. package/dist/node/env.cjs +100 -4
  512. package/dist/node/env.cjs.map +1 -1
  513. package/dist/node/env.mjs +90 -4
  514. package/dist/node/env.mjs.map +1 -1
  515. package/dist/node/files-async.cjs +66 -1
  516. package/dist/node/files-async.cjs.map +1 -1
  517. package/dist/node/files-async.mjs +60 -1
  518. package/dist/node/files-async.mjs.map +1 -1
  519. package/dist/node/files.cjs +52 -1
  520. package/dist/node/files.cjs.map +1 -1
  521. package/dist/node/files.mjs +46 -1
  522. package/dist/node/files.mjs.map +1 -1
  523. package/dist/node/filestorage.cjs +100 -1
  524. package/dist/node/filestorage.cjs.map +1 -1
  525. package/dist/node/filestorage.mjs +97 -1
  526. package/dist/node/filestorage.mjs.map +1 -1
  527. package/dist/node/fs.cjs +119 -1
  528. package/dist/node/fs.cjs.map +1 -1
  529. package/dist/node/fs.mjs +101 -1
  530. package/dist/node/fs.mjs.map +1 -1
  531. package/dist/node/glob.cjs +75 -1
  532. package/dist/node/glob.cjs.map +1 -1
  533. package/dist/node/glob.mjs +73 -1
  534. package/dist/node/glob.mjs.map +1 -1
  535. package/dist/node/index.cjs +66 -1
  536. package/dist/node/index.mjs +16 -1
  537. package/dist/node/log/index.cjs +20 -1
  538. package/dist/node/log/index.mjs +7 -1
  539. package/dist/node/log/log-context-node.cjs +39 -1
  540. package/dist/node/log/log-context-node.cjs.map +1 -1
  541. package/dist/node/log/log-context-node.mjs +35 -1
  542. package/dist/node/log/log-context-node.mjs.map +1 -1
  543. package/dist/node/log/log-file-rotation.cjs +71 -1
  544. package/dist/node/log/log-file-rotation.cjs.map +1 -1
  545. package/dist/node/log/log-file-rotation.mjs +68 -1
  546. package/dist/node/log/log-file-rotation.mjs.map +1 -1
  547. package/dist/node/log/log-file.cjs +57 -1
  548. package/dist/node/log/log-file.cjs.map +1 -1
  549. package/dist/node/log/log-file.mjs +54 -1
  550. package/dist/node/log/log-file.mjs.map +1 -1
  551. package/dist/node/log/log-node.cjs +162 -1
  552. package/dist/node/log/log-node.cjs.map +1 -1
  553. package/dist/node/log/log-node.mjs +155 -1
  554. package/dist/node/log/log-node.mjs.map +1 -1
  555. package/dist/node/log/log-rotation.cjs +543 -3
  556. package/dist/node/log/log-rotation.cjs.map +1 -1
  557. package/dist/node/log/log-rotation.mjs +538 -3
  558. package/dist/node/log/log-rotation.mjs.map +1 -1
  559. package/dist/node/log/log-util.cjs +69 -3
  560. package/dist/node/log/log-util.cjs.map +1 -1
  561. package/dist/node/log/log-util.mjs +63 -3
  562. package/dist/node/log/log-util.mjs.map +1 -1
  563. package/dist/node/open-browser.cjs +20 -1
  564. package/dist/node/open-browser.cjs.map +1 -1
  565. package/dist/node/open-browser.mjs +18 -1
  566. package/dist/node/open-browser.mjs.map +1 -1
  567. package/package.json +15 -15
  568. package/src/common/schema/README.md +247 -66
  569. package/src/eslint-defaults.js +4 -0
  570. package/src/index.spec.ts +6 -6
  571. package/dist/bin-Ce3i6ABn.cjs +0 -3
  572. package/dist/bin-SPdenYkw.mjs +0 -3
  573. package/dist/chunk-0Lt9GpW0.mjs +0 -1
  574. package/dist/chunk-D-qHiVGv.cjs +0 -1
  575. package/src/common/schema/README-SCHEMA.md +0 -0
@@ -1,2 +1,300 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./math.cjs`),t=require(`./orderby.cjs`);function n(e){return e.filter((t,n)=>e.indexOf(t)===n)}function r(e,t){return n(e.filter(e=>!t.includes(e)))}function i(...e){return n(e.reduce((e=[],t)=>e.concat(t),[]))}function a(...e){return e.flat(1/0)}function o(e,t){return n(e).filter(e=>t.includes(e))}function s(e,t){return r(i(e,t),o(e,t))}function c(e,t){if(e&&Array.isArray(e)){let n;for(;(n=e.indexOf(t))!==-1;)e.splice(n,1);return e}return[]}function l(e,t){return e.includes(t)||e.push(t),e}function u(e,t){return e.splice(0,e.length,...e.filter(t)),e}function d(e,t){let n=e.findIndex(e=>e===t);return n>=0?e.splice(n,1):e.push(t),e}function f(e){return e.splice(0,e.length),e}function p(e,t){return e.splice(0,e.length,...t),e}function m(e,n=t.cmp){return Array.from(e).sort(n)}function h(e){return m(e,(e,t)=>e-t)}function g(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function _(t){return t.sort(()=>e.getSecureRandomIfPossible()>.5?1:-1),t}function v(e){return _(Array.from(e))}function y(e){for(;e.length>1;){let t=Array.from(e);if(_(t),!g(e,t))return t}return e}function b(t){return t[Math.floor(e.getSecureRandomIfPossible()*t.length)]}function x(...e){return a(...e).reduce((e,t)=>e==null||t>e?t:e,void 0)}function S(...e){return a(...e).reduce((e,t)=>e==null||t<e?t:e,void 0)}function C(...e){return a(...e).reduce((e,t)=>e+t,0)}function w(...e){let t=a(...e);return t.reduce((e,t)=>e+t,0)/t.length}function T(e,t){let n=[],r=0,i=e.length;for(;r<i;)n.push(e.slice(r,r+=t));return n}function E(e=0,t){if(e<=0)return[];let n=Array.from({length:e});for(let r=0;r<e;r++)n[r]=t instanceof Function?t(r):t;return n}exports.arrayAvg=w,exports.arrayBatches=T,exports.arrayEmptyInPlace=f,exports.arrayFilterInPlace=u,exports.arrayFlatten=a,exports.arrayIntersection=o,exports.arrayIsEqual=g,exports.arrayMax=x,exports.arrayMin=S,exports.arrayMinus=r,exports.arrayRandomElement=b,exports.arrayRemoveElement=c,exports.arraySetArrayInPlace=p,exports.arraySetElement=l,exports.arrayShuffle=v,exports.arrayShuffleForce=y,exports.arrayShuffleInPlace=_,exports.arraySorted=m,exports.arraySortedNumbers=h,exports.arraySum=C,exports.arraySymmetricDifference=s,exports.arrayToggleInPlace=d,exports.arrayUnion=i,exports.arrayUnique=n,exports.createArray=E;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_common_data_math = require('./math.cjs');
3
+ const require_common_data_orderby = require('./orderby.cjs');
4
+
5
+ //#region src/common/data/array.ts
6
+ /**
7
+ * Return a new array with duplicate values removed. Maintains first occurrence order.
8
+ * @typeParam T - element type
9
+ * @param arr - input array
10
+ * @returns new array containing unique elements from `arr`
11
+ */
12
+ function arrayUnique(arr) {
13
+ return arr.filter((n, index) => arr.indexOf(n) === index);
14
+ }
15
+ /**
16
+ * Return elements present in `x` but not in `y`.
17
+ * @typeParam T - element type
18
+ * @param left - left-hand array
19
+ * @param right - array of elements to exclude
20
+ * @returns new array with elements from `left` that are not included in `right`
21
+ */
22
+ function arrayMinus(left, right) {
23
+ return arrayUnique(left.filter((n) => !right.includes(n)));
24
+ }
25
+ /**
26
+ * Return the union of multiple arrays (unique elements across all inputs).
27
+ * @typeParam T - element type
28
+ * @param arrays - arrays to union
29
+ * @returns new array with unique elements from all provided arrays
30
+ */
31
+ function arrayUnion(...arrays) {
32
+ return arrayUnique(arrays.reduce((acc = [], value) => acc.concat(value), []));
33
+ }
34
+ /** `[1,[2,3]]` becomes `[1,2,3]` */
35
+ /**
36
+ * Flatten nested arrays to a single-level array.
37
+ * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.
38
+ * @typeParam T - element type
39
+ * @param arrays - one or more nested arrays to flatten
40
+ * @returns flattened array containing all elements
41
+ */
42
+ function arrayFlatten(...arrays) {
43
+ return arrays.flat(Number.POSITIVE_INFINITY);
44
+ }
45
+ /**
46
+ * Return the intersection of two arrays (elements present in both).
47
+ * @typeParam T - element type
48
+ * @param left - first array
49
+ * @param right - second array
50
+ * @returns new array with elements present in both `left` and `right`
51
+ */
52
+ function arrayIntersection(left, right) {
53
+ return arrayUnique(left).filter((n) => right.includes(n));
54
+ }
55
+ /**
56
+ * Return the symmetric difference between two arrays (elements in either array but not both).
57
+ * @typeParam T - element type
58
+ */
59
+ function arraySymmetricDifference(left, right) {
60
+ return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right));
61
+ }
62
+ /**
63
+ * Remove all occurrences of `el` from `arr` in-place and return the mutated array.
64
+ * If `arr` is not an array, returns an empty array.
65
+ * @typeParam T - element type
66
+ * @param arr - array to modify
67
+ * @param el - element to remove
68
+ * @returns the same array instance with `el` removed
69
+ */
70
+ function arrayRemoveElement(arr, el) {
71
+ if (arr && Array.isArray(arr)) {
72
+ let index;
73
+ while ((index = arr.indexOf(el)) !== -1) arr.splice(index, 1);
74
+ return arr;
75
+ }
76
+ return [];
77
+ }
78
+ /** Only have it once in the set */
79
+ /**
80
+ * Ensure `el` exists in `arr`. If not present, push it and return the array.
81
+ * @typeParam T - element type
82
+ * @param arr - target array
83
+ * @param el - element to ensure
84
+ * @returns the same array instance (modified if `el` was added)
85
+ */
86
+ function arraySetElement(arr, el) {
87
+ if (!arr.includes(el)) arr.push(el);
88
+ return arr;
89
+ }
90
+ /**
91
+ * Filter an array in-place using `fn` and return the same array instance.
92
+ * This replaces the array contents with the filtered result.
93
+ * @typeParam T - element type
94
+ * @param arr - array to filter in-place
95
+ * @param fn - predicate to determine which elements to keep
96
+ * @returns the same array instance after filtering
97
+ */
98
+ function arrayFilterInPlace(arr, fn) {
99
+ arr.splice(0, arr.length, ...arr.filter(fn));
100
+ return arr;
101
+ }
102
+ /**
103
+ * Toggle presence of `el` in `array` in-place: remove if present, add if missing.
104
+ * @typeParam T - element type
105
+ * @param arr - array to modify
106
+ * @param el - element to toggle
107
+ * @returns the same array instance after the toggle
108
+ */
109
+ function arrayToggleInPlace(arr, el) {
110
+ const index = arr.findIndex((e) => e === el);
111
+ if (index >= 0) arr.splice(index, 1);
112
+ else arr.push(el);
113
+ return arr;
114
+ }
115
+ /**
116
+ * Empty an array in-place (remove all elements) and return it.
117
+ * @typeParam T - element type
118
+ */
119
+ function arrayEmptyInPlace(arr) {
120
+ arr.splice(0, arr.length);
121
+ return arr;
122
+ }
123
+ /**
124
+ * Replace the contents of `array` in-place with `newContent` and return it.
125
+ * @typeParam T - element type
126
+ * @param arr - target array to overwrite
127
+ * @param newContent - new contents to set
128
+ * @returns the same array instance after replacement
129
+ */
130
+ function arraySetArrayInPlace(arr, newContent) {
131
+ arr.splice(0, arr.length, ...newContent);
132
+ return arr;
133
+ }
134
+ /**
135
+ * Return a sorted copy of the provided iterable or array-like object.
136
+ * @typeParam T - element type
137
+ * @param arr - iterable or array-like input
138
+ * @param compareFn - optional compare function (defaults to `cmp`)
139
+ * @returns a new array sorted according to `compareFn`
140
+ */
141
+ function arraySorted(arr, compareFn = require_common_data_orderby.cmp) {
142
+ return Array.from(arr).sort(compareFn);
143
+ }
144
+ /**
145
+ * Return a new array with numbers sorted in ascending order.
146
+ * @param arr - array of numbers
147
+ * @returns sorted array of numbers
148
+ */
149
+ function arraySortedNumbers(arr) {
150
+ return arraySorted(arr, (l, r) => l - r);
151
+ }
152
+ /**
153
+ * Check strict equality of two arrays by length and element-wise === comparison.
154
+ * @typeParam T - element type
155
+ * @param array1 - first array
156
+ * @param array2 - second array
157
+ * @returns `true` if arrays are same length and all elements strictly equal
158
+ */
159
+ function arrayIsEqual(array1, array2) {
160
+ return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
161
+ }
162
+ /**
163
+ * Shuffle an array in-place using a secure random source if available.
164
+ * Note: uses Array.sort with random comparator which is sufficient for many cases but
165
+ * not perfectly uniform. Returns the same mutated array.
166
+ * @typeParam T - element type
167
+ * @param array - array to shuffle in-place
168
+ * @returns the shuffled array (same instance)
169
+ */
170
+ function arrayShuffleInPlace(arr) {
171
+ arr.sort(() => require_common_data_math.getSecureRandomIfPossible() > .5 ? 1 : -1);
172
+ return arr;
173
+ }
174
+ /**
175
+ * Return a shuffled copy of `array` (original array is not modified).
176
+ * @typeParam T - element type
177
+ * @param array - input array
178
+ * @returns a new shuffled array
179
+ */
180
+ function arrayShuffle(arr) {
181
+ return arrayShuffleInPlace(Array.from(arr));
182
+ }
183
+ /** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */
184
+ /**
185
+ * Shuffle `array` and ensure the returned order differs from the original when possible.
186
+ * If array length is 0 or 1 it is returned unchanged.
187
+ * @typeParam T - element type
188
+ * @param array - input array
189
+ * @returns a shuffled array that's different from the input when feasible
190
+ */
191
+ function arrayShuffleForce(arr) {
192
+ while (arr.length > 1) {
193
+ const copy = Array.from(arr);
194
+ arrayShuffleInPlace(copy);
195
+ if (!arrayIsEqual(arr, copy)) return copy;
196
+ }
197
+ return arr;
198
+ }
199
+ /**
200
+ * Return a random element from `array` using a secure random source if available.
201
+ * @typeParam T - element type
202
+ * @param array - input array (must be non-empty)
203
+ * @returns a randomly selected element
204
+ */
205
+ function arrayRandomElement(arr) {
206
+ return arr[Math.floor(require_common_data_math.getSecureRandomIfPossible() * arr.length)];
207
+ }
208
+ /**
209
+ * Return the maximum value from one or more nested arrays.
210
+ * Uses the `>` operator for comparison.
211
+ * @typeParam T - element type (should support `>` comparison)
212
+ * @param arrays - nested arrays to search
213
+ * @returns the maximum value or `undefined` if no elements present
214
+ */
215
+ function arrayMax(...arrays) {
216
+ return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value > acc ? value : acc : value, void 0);
217
+ }
218
+ /**
219
+ * Return the minimum value from one or more nested arrays.
220
+ * Uses the `<` operator for comparison.
221
+ * @typeParam T - element type (should support `<` comparison)
222
+ * @param arrays - nested arrays to search
223
+ * @returns the minimum value or `undefined` if no elements present
224
+ */
225
+ function arrayMin(...arrays) {
226
+ return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value < acc ? value : acc : value, void 0);
227
+ }
228
+ /**
229
+ * Sum all numbers in one or more nested arrays.
230
+ * @param arrays - nested arrays of numbers
231
+ * @returns the numeric sum (0 for empty input)
232
+ */
233
+ function arraySum(...arrays) {
234
+ return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0);
235
+ }
236
+ /**
237
+ * Compute the average of numbers across one or more nested arrays.
238
+ * @param arrays - nested arrays of numbers
239
+ * @returns arithmetic mean (NaN if there are no elements)
240
+ */
241
+ function arrayAvg(...arrays) {
242
+ const flatArray = arrayFlatten(...arrays);
243
+ return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
244
+ }
245
+ /**
246
+ * Split an array into chunks of `chunkLength` (last chunk may be smaller).
247
+ * @typeParam T - element type
248
+ * @param arr - input array
249
+ * @param chunkLength - chunk size (positive integer)
250
+ * @returns array of chunk arrays
251
+ */
252
+ function arrayBatches(arr, chunkLength) {
253
+ const chunks = [];
254
+ let i = 0;
255
+ const n = arr.length;
256
+ while (i < n) chunks.push(arr.slice(i, i += chunkLength));
257
+ return chunks;
258
+ }
259
+ /**
260
+ * Create an array of given `length` filled with `item` or the result of `item(index)`.
261
+ * If `length` is <= 0 an empty array is returned.
262
+ * @typeParam T - element type
263
+ * @param length - desired length of the array
264
+ * @param item - value to fill or a function producing a value per index
265
+ * @returns newly created array of length `length`
266
+ */
267
+ function createArray(length = 0, item) {
268
+ if (length <= 0) return [];
269
+ const arr = Array.from({ length });
270
+ for (let i = 0; i < length; i++) arr[i] = item instanceof Function ? item(i) : item;
271
+ return arr;
272
+ }
273
+
274
+ //#endregion
275
+ exports.arrayAvg = arrayAvg;
276
+ exports.arrayBatches = arrayBatches;
277
+ exports.arrayEmptyInPlace = arrayEmptyInPlace;
278
+ exports.arrayFilterInPlace = arrayFilterInPlace;
279
+ exports.arrayFlatten = arrayFlatten;
280
+ exports.arrayIntersection = arrayIntersection;
281
+ exports.arrayIsEqual = arrayIsEqual;
282
+ exports.arrayMax = arrayMax;
283
+ exports.arrayMin = arrayMin;
284
+ exports.arrayMinus = arrayMinus;
285
+ exports.arrayRandomElement = arrayRandomElement;
286
+ exports.arrayRemoveElement = arrayRemoveElement;
287
+ exports.arraySetArrayInPlace = arraySetArrayInPlace;
288
+ exports.arraySetElement = arraySetElement;
289
+ exports.arrayShuffle = arrayShuffle;
290
+ exports.arrayShuffleForce = arrayShuffleForce;
291
+ exports.arrayShuffleInPlace = arrayShuffleInPlace;
292
+ exports.arraySorted = arraySorted;
293
+ exports.arraySortedNumbers = arraySortedNumbers;
294
+ exports.arraySum = arraySum;
295
+ exports.arraySymmetricDifference = arraySymmetricDifference;
296
+ exports.arrayToggleInPlace = arrayToggleInPlace;
297
+ exports.arrayUnion = arrayUnion;
298
+ exports.arrayUnique = arrayUnique;
299
+ exports.createArray = createArray;
2
300
  //# sourceMappingURL=array.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"array.cjs","names":["cmp","getSecureRandomIfPossible"],"sources":["../../../src/common/data/array.ts"],"sourcesContent":["/* eslint-disable no-cond-assign */\n\nimport type { NestedArray } from '../types'\nimport { getSecureRandomIfPossible } from './math'\nimport { cmp } from './orderby'\n\n/**\n * Return a new array with duplicate values removed. Maintains first occurrence order.\n * @typeParam T - element type\n * @param arr - input array\n * @returns new array containing unique elements from `arr`\n */\nexport function arrayUnique<T>(arr: T[]): T[] {\n return arr.filter((n: any, index: any) => arr.indexOf(n) === index)\n}\n\n/**\n * Return elements present in `x` but not in `y`.\n * @typeParam T - element type\n * @param left - left-hand array\n * @param right - array of elements to exclude\n * @returns new array with elements from `left` that are not included in `right`\n */\nexport function arrayMinus<T>(left: T[], right: T[]): T[] {\n return arrayUnique(left.filter((n: any) => !right.includes(n)))\n}\n\n/**\n * Return the union of multiple arrays (unique elements across all inputs).\n * @typeParam T - element type\n * @param arrays - arrays to union\n * @returns new array with unique elements from all provided arrays\n */\nexport function arrayUnion<T>(...arrays: T[][]): T[] {\n return arrayUnique(arrays.reduce((acc: T[] = [], value) => acc.concat(value), []))\n}\n\n/** `[1,[2,3]]` becomes `[1,2,3]` */\n/**\n * Flatten nested arrays to a single-level array.\n * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.\n * @typeParam T - element type\n * @param arrays - one or more nested arrays to flatten\n * @returns flattened array containing all elements\n */\nexport function arrayFlatten<T>(...arrays: NestedArray<T>[]): T[] {\n return (arrays as any).flat(Number.POSITIVE_INFINITY)\n}\n\n/**\n * Return the intersection of two arrays (elements present in both).\n * @typeParam T - element type\n * @param left - first array\n * @param right - second array\n * @returns new array with elements present in both `left` and `right`\n */\nexport function arrayIntersection<T>(left: T[], right: T[]): T[] {\n return arrayUnique<T>(left).filter((n: any) => right.includes(n))\n}\n\n/**\n * Return the symmetric difference between two arrays (elements in either array but not both).\n * @typeParam T - element type\n */\nexport function arraySymmetricDifference<T>(left: T[], right: T[]): T[] {\n return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right))\n // return arrayUnique(x.filter(n => !y.includes(n)).concat(y.filter(n => !x.includes(n))))\n}\n\n// export function arrayApply<T>(fn: any, a: T[]): T[] {\n// return a.reduce(fn, [])\n// }\n\n/**\n * Remove all occurrences of `el` from `arr` in-place and return the mutated array.\n * If `arr` is not an array, returns an empty array.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to remove\n * @returns the same array instance with `el` removed\n */\nexport function arrayRemoveElement<T>(arr: T[], el: T): T[] {\n if (arr && Array.isArray(arr)) {\n let index\n while ((index = arr.indexOf(el)) !== -1)\n arr.splice(index, 1)\n return arr\n }\n return []\n}\n\n/** Only have it once in the set */\n/**\n * Ensure `el` exists in `arr`. If not present, push it and return the array.\n * @typeParam T - element type\n * @param arr - target array\n * @param el - element to ensure\n * @returns the same array instance (modified if `el` was added)\n */\nexport function arraySetElement<T>(arr: T[], el: T): T[] {\n if (!arr.includes(el))\n arr.push(el)\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Filter an array in-place using `fn` and return the same array instance.\n * This replaces the array contents with the filtered result.\n * @typeParam T - element type\n * @param arr - array to filter in-place\n * @param fn - predicate to determine which elements to keep\n * @returns the same array instance after filtering\n */\nexport function arrayFilterInPlace<T>(arr: T[], fn: (el: T) => boolean): T[] {\n arr.splice(0, arr.length, ...arr.filter(fn))\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Toggle presence of `el` in `array` in-place: remove if present, add if missing.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to toggle\n * @returns the same array instance after the toggle\n */\nexport function arrayToggleInPlace<T>(arr: T[], el: T): T[] {\n const index = arr.findIndex(e => e === el)\n if (index >= 0)\n arr.splice(index, 1)\n else arr.push(el)\n return arr\n}\n\n/**\n * Empty an array in-place (remove all elements) and return it.\n * @typeParam T - element type\n */\nexport function arrayEmptyInPlace<T>(arr: T[]): T[] {\n arr.splice(0, arr.length)\n return arr\n}\n\n/**\n * Replace the contents of `array` in-place with `newContent` and return it.\n * @typeParam T - element type\n * @param arr - target array to overwrite\n * @param newContent - new contents to set\n * @returns the same array instance after replacement\n */\nexport function arraySetArrayInPlace<T>(arr: T[], newContent: T[]): T[] {\n arr.splice(0, arr.length, ...newContent)\n return arr\n}\n\n/**\n * Return a sorted copy of the provided iterable or array-like object.\n * @typeParam T - element type\n * @param arr - iterable or array-like input\n * @param compareFn - optional compare function (defaults to `cmp`)\n * @returns a new array sorted according to `compareFn`\n */\nexport function arraySorted<T>(\n arr: Iterable<T> | ArrayLike<T>,\n compareFn: ((a: T, b: T) => number) | undefined = cmp,\n): T[] {\n return Array.from(arr).sort(compareFn)\n}\n\n/**\n * Return a new array with numbers sorted in ascending order.\n * @param arr - array of numbers\n * @returns sorted array of numbers\n */\nexport function arraySortedNumbers(arr: number[]): number[] {\n return arraySorted(arr, (l: number, r: number) => l - r)\n}\n\n/**\n * Check strict equality of two arrays by length and element-wise === comparison.\n * @typeParam T - element type\n * @param array1 - first array\n * @param array2 - second array\n * @returns `true` if arrays are same length and all elements strictly equal\n */\nexport function arrayIsEqual<T>(array1: T[], array2: T[]): boolean {\n return (\n array1.length === array2.length\n && array1.every((value, index) => value === array2[index])\n )\n}\n\n/**\n * Shuffle an array in-place using a secure random source if available.\n * Note: uses Array.sort with random comparator which is sufficient for many cases but\n * not perfectly uniform. Returns the same mutated array.\n * @typeParam T - element type\n * @param array - array to shuffle in-place\n * @returns the shuffled array (same instance)\n */\nexport function arrayShuffleInPlace<T>(arr: T[]): T[] {\n arr.sort(() => (getSecureRandomIfPossible() > 0.5 ? 1 : -1))\n\n // Alternative https://github.com/sindresorhus/array-shuffle/blob/main/index.js#L8\n // for (let index = array.length - 1; index > 0; index--) {\n // const newIndex = Math.floor(Math.random() * (index + 1));\n // [array[index], array[newIndex]] = [array[newIndex], array[index]];\n // }\n\n return arr\n}\n\n/**\n * Return a shuffled copy of `array` (original array is not modified).\n * @typeParam T - element type\n * @param array - input array\n * @returns a new shuffled array\n */\nexport function arrayShuffle<T>(arr: T[]): T[] {\n return arrayShuffleInPlace(Array.from(arr))\n}\n\n/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */\n/**\n * Shuffle `array` and ensure the returned order differs from the original when possible.\n * If array length is 0 or 1 it is returned unchanged.\n * @typeParam T - element type\n * @param array - input array\n * @returns a shuffled array that's different from the input when feasible\n */\nexport function arrayShuffleForce<T>(arr: T[]): T[] {\n while (arr.length > 1) {\n const copy = Array.from(arr)\n arrayShuffleInPlace(copy)\n if (!arrayIsEqual(arr, copy))\n return copy\n }\n return arr\n}\n\n/**\n * Return a random element from `array` using a secure random source if available.\n * @typeParam T - element type\n * @param array - input array (must be non-empty)\n * @returns a randomly selected element\n */\nexport function arrayRandomElement<T>(arr: T[]): T {\n return arr[Math.floor(getSecureRandomIfPossible() * arr.length)]\n}\n\n/**\n * Return the maximum value from one or more nested arrays.\n * Uses the `>` operator for comparison.\n * @typeParam T - element type (should support `>` comparison)\n * @param arrays - nested arrays to search\n * @returns the maximum value or `undefined` if no elements present\n */\nexport function arrayMax<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value > acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Return the minimum value from one or more nested arrays.\n * Uses the `<` operator for comparison.\n * @typeParam T - element type (should support `<` comparison)\n * @param arrays - nested arrays to search\n * @returns the minimum value or `undefined` if no elements present\n */\nexport function arrayMin<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value < acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Sum all numbers in one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns the numeric sum (0 for empty input)\n */\nexport function arraySum(...arrays: NestedArray<number>[]): number {\n return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0)\n}\n\n/**\n * Compute the average of numbers across one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns arithmetic mean (NaN if there are no elements)\n */\nexport function arrayAvg(...arrays: NestedArray<number>[]): number {\n const flatArray = arrayFlatten(...arrays)\n return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length\n}\n\n/**\n * Split an array into chunks of `chunkLength` (last chunk may be smaller).\n * @typeParam T - element type\n * @param arr - input array\n * @param chunkLength - chunk size (positive integer)\n * @returns array of chunk arrays\n */\nexport function arrayBatches<T>(arr: T[], chunkLength: number): T[][] {\n const chunks = []\n let i = 0\n const n = arr.length\n while (i < n)\n chunks.push(arr.slice(i, (i += chunkLength)))\n return chunks\n}\n\n/**\n * Create an array of given `length` filled with `item` or the result of `item(index)`.\n * If `length` is <= 0 an empty array is returned.\n * @typeParam T - element type\n * @param length - desired length of the array\n * @param item - value to fill or a function producing a value per index\n * @returns newly created array of length `length`\n */\nexport function createArray<T>(\n length = 0,\n item?: T | ((index: number) => T), // todo remove optional\n): T[] {\n if (length <= 0)\n return []\n const arr: T[] = Array.from({ length })\n for (let i = 0; i < length; i++)\n // @ts-expect-error xxx\n arr[i] = item instanceof Function ? item(i) : item\n return arr\n}\n"],"mappings":"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"}
1
+ {"version":3,"file":"array.cjs","names":["cmp","getSecureRandomIfPossible"],"sources":["../../../src/common/data/array.ts"],"sourcesContent":["/* eslint-disable no-cond-assign */\n\nimport type { NestedArray } from '../types'\nimport { getSecureRandomIfPossible } from './math'\nimport { cmp } from './orderby'\n\n/**\n * Return a new array with duplicate values removed. Maintains first occurrence order.\n * @typeParam T - element type\n * @param arr - input array\n * @returns new array containing unique elements from `arr`\n */\nexport function arrayUnique<T>(arr: T[]): T[] {\n return arr.filter((n: any, index: any) => arr.indexOf(n) === index)\n}\n\n/**\n * Return elements present in `x` but not in `y`.\n * @typeParam T - element type\n * @param left - left-hand array\n * @param right - array of elements to exclude\n * @returns new array with elements from `left` that are not included in `right`\n */\nexport function arrayMinus<T>(left: T[], right: T[]): T[] {\n return arrayUnique(left.filter((n: any) => !right.includes(n)))\n}\n\n/**\n * Return the union of multiple arrays (unique elements across all inputs).\n * @typeParam T - element type\n * @param arrays - arrays to union\n * @returns new array with unique elements from all provided arrays\n */\nexport function arrayUnion<T>(...arrays: T[][]): T[] {\n return arrayUnique(arrays.reduce((acc: T[] = [], value) => acc.concat(value), []))\n}\n\n/** `[1,[2,3]]` becomes `[1,2,3]` */\n/**\n * Flatten nested arrays to a single-level array.\n * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.\n * @typeParam T - element type\n * @param arrays - one or more nested arrays to flatten\n * @returns flattened array containing all elements\n */\nexport function arrayFlatten<T>(...arrays: NestedArray<T>[]): T[] {\n return (arrays as any).flat(Number.POSITIVE_INFINITY)\n}\n\n/**\n * Return the intersection of two arrays (elements present in both).\n * @typeParam T - element type\n * @param left - first array\n * @param right - second array\n * @returns new array with elements present in both `left` and `right`\n */\nexport function arrayIntersection<T>(left: T[], right: T[]): T[] {\n return arrayUnique<T>(left).filter((n: any) => right.includes(n))\n}\n\n/**\n * Return the symmetric difference between two arrays (elements in either array but not both).\n * @typeParam T - element type\n */\nexport function arraySymmetricDifference<T>(left: T[], right: T[]): T[] {\n return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right))\n // return arrayUnique(x.filter(n => !y.includes(n)).concat(y.filter(n => !x.includes(n))))\n}\n\n// export function arrayApply<T>(fn: any, a: T[]): T[] {\n// return a.reduce(fn, [])\n// }\n\n/**\n * Remove all occurrences of `el` from `arr` in-place and return the mutated array.\n * If `arr` is not an array, returns an empty array.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to remove\n * @returns the same array instance with `el` removed\n */\nexport function arrayRemoveElement<T>(arr: T[], el: T): T[] {\n if (arr && Array.isArray(arr)) {\n let index\n while ((index = arr.indexOf(el)) !== -1)\n arr.splice(index, 1)\n return arr\n }\n return []\n}\n\n/** Only have it once in the set */\n/**\n * Ensure `el` exists in `arr`. If not present, push it and return the array.\n * @typeParam T - element type\n * @param arr - target array\n * @param el - element to ensure\n * @returns the same array instance (modified if `el` was added)\n */\nexport function arraySetElement<T>(arr: T[], el: T): T[] {\n if (!arr.includes(el))\n arr.push(el)\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Filter an array in-place using `fn` and return the same array instance.\n * This replaces the array contents with the filtered result.\n * @typeParam T - element type\n * @param arr - array to filter in-place\n * @param fn - predicate to determine which elements to keep\n * @returns the same array instance after filtering\n */\nexport function arrayFilterInPlace<T>(arr: T[], fn: (el: T) => boolean): T[] {\n arr.splice(0, arr.length, ...arr.filter(fn))\n return arr\n}\n\n// via https://stackoverflow.com/a/49587869 and Erwin\n/**\n * Toggle presence of `el` in `array` in-place: remove if present, add if missing.\n * @typeParam T - element type\n * @param arr - array to modify\n * @param el - element to toggle\n * @returns the same array instance after the toggle\n */\nexport function arrayToggleInPlace<T>(arr: T[], el: T): T[] {\n const index = arr.findIndex(e => e === el)\n if (index >= 0)\n arr.splice(index, 1)\n else arr.push(el)\n return arr\n}\n\n/**\n * Empty an array in-place (remove all elements) and return it.\n * @typeParam T - element type\n */\nexport function arrayEmptyInPlace<T>(arr: T[]): T[] {\n arr.splice(0, arr.length)\n return arr\n}\n\n/**\n * Replace the contents of `array` in-place with `newContent` and return it.\n * @typeParam T - element type\n * @param arr - target array to overwrite\n * @param newContent - new contents to set\n * @returns the same array instance after replacement\n */\nexport function arraySetArrayInPlace<T>(arr: T[], newContent: T[]): T[] {\n arr.splice(0, arr.length, ...newContent)\n return arr\n}\n\n/**\n * Return a sorted copy of the provided iterable or array-like object.\n * @typeParam T - element type\n * @param arr - iterable or array-like input\n * @param compareFn - optional compare function (defaults to `cmp`)\n * @returns a new array sorted according to `compareFn`\n */\nexport function arraySorted<T>(\n arr: Iterable<T> | ArrayLike<T>,\n compareFn: ((a: T, b: T) => number) | undefined = cmp,\n): T[] {\n return Array.from(arr).sort(compareFn)\n}\n\n/**\n * Return a new array with numbers sorted in ascending order.\n * @param arr - array of numbers\n * @returns sorted array of numbers\n */\nexport function arraySortedNumbers(arr: number[]): number[] {\n return arraySorted(arr, (l: number, r: number) => l - r)\n}\n\n/**\n * Check strict equality of two arrays by length and element-wise === comparison.\n * @typeParam T - element type\n * @param array1 - first array\n * @param array2 - second array\n * @returns `true` if arrays are same length and all elements strictly equal\n */\nexport function arrayIsEqual<T>(array1: T[], array2: T[]): boolean {\n return (\n array1.length === array2.length\n && array1.every((value, index) => value === array2[index])\n )\n}\n\n/**\n * Shuffle an array in-place using a secure random source if available.\n * Note: uses Array.sort with random comparator which is sufficient for many cases but\n * not perfectly uniform. Returns the same mutated array.\n * @typeParam T - element type\n * @param array - array to shuffle in-place\n * @returns the shuffled array (same instance)\n */\nexport function arrayShuffleInPlace<T>(arr: T[]): T[] {\n arr.sort(() => (getSecureRandomIfPossible() > 0.5 ? 1 : -1))\n\n // Alternative https://github.com/sindresorhus/array-shuffle/blob/main/index.js#L8\n // for (let index = array.length - 1; index > 0; index--) {\n // const newIndex = Math.floor(Math.random() * (index + 1));\n // [array[index], array[newIndex]] = [array[newIndex], array[index]];\n // }\n\n return arr\n}\n\n/**\n * Return a shuffled copy of `array` (original array is not modified).\n * @typeParam T - element type\n * @param array - input array\n * @returns a new shuffled array\n */\nexport function arrayShuffle<T>(arr: T[]): T[] {\n return arrayShuffleInPlace(Array.from(arr))\n}\n\n/** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */\n/**\n * Shuffle `array` and ensure the returned order differs from the original when possible.\n * If array length is 0 or 1 it is returned unchanged.\n * @typeParam T - element type\n * @param array - input array\n * @returns a shuffled array that's different from the input when feasible\n */\nexport function arrayShuffleForce<T>(arr: T[]): T[] {\n while (arr.length > 1) {\n const copy = Array.from(arr)\n arrayShuffleInPlace(copy)\n if (!arrayIsEqual(arr, copy))\n return copy\n }\n return arr\n}\n\n/**\n * Return a random element from `array` using a secure random source if available.\n * @typeParam T - element type\n * @param array - input array (must be non-empty)\n * @returns a randomly selected element\n */\nexport function arrayRandomElement<T>(arr: T[]): T {\n return arr[Math.floor(getSecureRandomIfPossible() * arr.length)]\n}\n\n/**\n * Return the maximum value from one or more nested arrays.\n * Uses the `>` operator for comparison.\n * @typeParam T - element type (should support `>` comparison)\n * @param arrays - nested arrays to search\n * @returns the maximum value or `undefined` if no elements present\n */\nexport function arrayMax<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value > acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Return the minimum value from one or more nested arrays.\n * Uses the `<` operator for comparison.\n * @typeParam T - element type (should support `<` comparison)\n * @param arrays - nested arrays to search\n * @returns the minimum value or `undefined` if no elements present\n */\nexport function arrayMin<T>(...arrays: NestedArray<T>[]): T {\n return arrayFlatten(...arrays).reduce(\n (acc: T, value: T) => (acc != null ? (value < acc ? value : acc) : value),\n undefined as T,\n )\n}\n\n/**\n * Sum all numbers in one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns the numeric sum (0 for empty input)\n */\nexport function arraySum(...arrays: NestedArray<number>[]): number {\n return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0)\n}\n\n/**\n * Compute the average of numbers across one or more nested arrays.\n * @param arrays - nested arrays of numbers\n * @returns arithmetic mean (NaN if there are no elements)\n */\nexport function arrayAvg(...arrays: NestedArray<number>[]): number {\n const flatArray = arrayFlatten(...arrays)\n return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length\n}\n\n/**\n * Split an array into chunks of `chunkLength` (last chunk may be smaller).\n * @typeParam T - element type\n * @param arr - input array\n * @param chunkLength - chunk size (positive integer)\n * @returns array of chunk arrays\n */\nexport function arrayBatches<T>(arr: T[], chunkLength: number): T[][] {\n const chunks = []\n let i = 0\n const n = arr.length\n while (i < n)\n chunks.push(arr.slice(i, (i += chunkLength)))\n return chunks\n}\n\n/**\n * Create an array of given `length` filled with `item` or the result of `item(index)`.\n * If `length` is <= 0 an empty array is returned.\n * @typeParam T - element type\n * @param length - desired length of the array\n * @param item - value to fill or a function producing a value per index\n * @returns newly created array of length `length`\n */\nexport function createArray<T>(\n length = 0,\n item?: T | ((index: number) => T), // todo remove optional\n): T[] {\n if (length <= 0)\n return []\n const arr: T[] = Array.from({ length })\n for (let i = 0; i < length; i++)\n // @ts-expect-error xxx\n arr[i] = item instanceof Function ? item(i) : item\n return arr\n}\n"],"mappings":"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"}
@@ -1,2 +1,275 @@
1
- import{getSecureRandomIfPossible as e}from"./math.mjs";import{cmp as t}from"./orderby.mjs";function n(e){return e.filter((t,n)=>e.indexOf(t)===n)}function r(e,t){return n(e.filter(e=>!t.includes(e)))}function i(...e){return n(e.reduce((e=[],t)=>e.concat(t),[]))}function a(...e){return e.flat(1/0)}function o(e,t){return n(e).filter(e=>t.includes(e))}function s(e,t){return r(i(e,t),o(e,t))}function c(e,t){if(e&&Array.isArray(e)){let n;for(;(n=e.indexOf(t))!==-1;)e.splice(n,1);return e}return[]}function l(e,t){return e.includes(t)||e.push(t),e}function u(e,t){return e.splice(0,e.length,...e.filter(t)),e}function d(e,t){let n=e.findIndex(e=>e===t);return n>=0?e.splice(n,1):e.push(t),e}function f(e){return e.splice(0,e.length),e}function p(e,t){return e.splice(0,e.length,...t),e}function m(e,n=t){return Array.from(e).sort(n)}function h(e){return m(e,(e,t)=>e-t)}function g(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function _(t){return t.sort(()=>e()>.5?1:-1),t}function v(e){return _(Array.from(e))}function y(e){for(;e.length>1;){let t=Array.from(e);if(_(t),!g(e,t))return t}return e}function b(t){return t[Math.floor(e()*t.length)]}function x(...e){return a(...e).reduce((e,t)=>e==null||t>e?t:e,void 0)}function S(...e){return a(...e).reduce((e,t)=>e==null||t<e?t:e,void 0)}function C(...e){return a(...e).reduce((e,t)=>e+t,0)}function w(...e){let t=a(...e);return t.reduce((e,t)=>e+t,0)/t.length}function T(e,t){let n=[],r=0,i=e.length;for(;r<i;)n.push(e.slice(r,r+=t));return n}function E(e=0,t){if(e<=0)return[];let n=Array.from({length:e});for(let r=0;r<e;r++)n[r]=t instanceof Function?t(r):t;return n}export{w as arrayAvg,T as arrayBatches,f as arrayEmptyInPlace,u as arrayFilterInPlace,a as arrayFlatten,o as arrayIntersection,g as arrayIsEqual,x as arrayMax,S as arrayMin,r as arrayMinus,b as arrayRandomElement,c as arrayRemoveElement,p as arraySetArrayInPlace,l as arraySetElement,v as arrayShuffle,y as arrayShuffleForce,_ as arrayShuffleInPlace,m as arraySorted,h as arraySortedNumbers,C as arraySum,s as arraySymmetricDifference,d as arrayToggleInPlace,i as arrayUnion,n as arrayUnique,E as createArray};
1
+ import { getSecureRandomIfPossible } from "./math.mjs";
2
+ import { cmp } from "./orderby.mjs";
3
+
4
+ //#region src/common/data/array.ts
5
+ /**
6
+ * Return a new array with duplicate values removed. Maintains first occurrence order.
7
+ * @typeParam T - element type
8
+ * @param arr - input array
9
+ * @returns new array containing unique elements from `arr`
10
+ */
11
+ function arrayUnique(arr) {
12
+ return arr.filter((n, index) => arr.indexOf(n) === index);
13
+ }
14
+ /**
15
+ * Return elements present in `x` but not in `y`.
16
+ * @typeParam T - element type
17
+ * @param left - left-hand array
18
+ * @param right - array of elements to exclude
19
+ * @returns new array with elements from `left` that are not included in `right`
20
+ */
21
+ function arrayMinus(left, right) {
22
+ return arrayUnique(left.filter((n) => !right.includes(n)));
23
+ }
24
+ /**
25
+ * Return the union of multiple arrays (unique elements across all inputs).
26
+ * @typeParam T - element type
27
+ * @param arrays - arrays to union
28
+ * @returns new array with unique elements from all provided arrays
29
+ */
30
+ function arrayUnion(...arrays) {
31
+ return arrayUnique(arrays.reduce((acc = [], value) => acc.concat(value), []));
32
+ }
33
+ /** `[1,[2,3]]` becomes `[1,2,3]` */
34
+ /**
35
+ * Flatten nested arrays to a single-level array.
36
+ * Example: `[1, [2, 3]]` becomes `[1, 2, 3]`.
37
+ * @typeParam T - element type
38
+ * @param arrays - one or more nested arrays to flatten
39
+ * @returns flattened array containing all elements
40
+ */
41
+ function arrayFlatten(...arrays) {
42
+ return arrays.flat(Number.POSITIVE_INFINITY);
43
+ }
44
+ /**
45
+ * Return the intersection of two arrays (elements present in both).
46
+ * @typeParam T - element type
47
+ * @param left - first array
48
+ * @param right - second array
49
+ * @returns new array with elements present in both `left` and `right`
50
+ */
51
+ function arrayIntersection(left, right) {
52
+ return arrayUnique(left).filter((n) => right.includes(n));
53
+ }
54
+ /**
55
+ * Return the symmetric difference between two arrays (elements in either array but not both).
56
+ * @typeParam T - element type
57
+ */
58
+ function arraySymmetricDifference(left, right) {
59
+ return arrayMinus(arrayUnion(left, right), arrayIntersection(left, right));
60
+ }
61
+ /**
62
+ * Remove all occurrences of `el` from `arr` in-place and return the mutated array.
63
+ * If `arr` is not an array, returns an empty array.
64
+ * @typeParam T - element type
65
+ * @param arr - array to modify
66
+ * @param el - element to remove
67
+ * @returns the same array instance with `el` removed
68
+ */
69
+ function arrayRemoveElement(arr, el) {
70
+ if (arr && Array.isArray(arr)) {
71
+ let index;
72
+ while ((index = arr.indexOf(el)) !== -1) arr.splice(index, 1);
73
+ return arr;
74
+ }
75
+ return [];
76
+ }
77
+ /** Only have it once in the set */
78
+ /**
79
+ * Ensure `el` exists in `arr`. If not present, push it and return the array.
80
+ * @typeParam T - element type
81
+ * @param arr - target array
82
+ * @param el - element to ensure
83
+ * @returns the same array instance (modified if `el` was added)
84
+ */
85
+ function arraySetElement(arr, el) {
86
+ if (!arr.includes(el)) arr.push(el);
87
+ return arr;
88
+ }
89
+ /**
90
+ * Filter an array in-place using `fn` and return the same array instance.
91
+ * This replaces the array contents with the filtered result.
92
+ * @typeParam T - element type
93
+ * @param arr - array to filter in-place
94
+ * @param fn - predicate to determine which elements to keep
95
+ * @returns the same array instance after filtering
96
+ */
97
+ function arrayFilterInPlace(arr, fn) {
98
+ arr.splice(0, arr.length, ...arr.filter(fn));
99
+ return arr;
100
+ }
101
+ /**
102
+ * Toggle presence of `el` in `array` in-place: remove if present, add if missing.
103
+ * @typeParam T - element type
104
+ * @param arr - array to modify
105
+ * @param el - element to toggle
106
+ * @returns the same array instance after the toggle
107
+ */
108
+ function arrayToggleInPlace(arr, el) {
109
+ const index = arr.findIndex((e) => e === el);
110
+ if (index >= 0) arr.splice(index, 1);
111
+ else arr.push(el);
112
+ return arr;
113
+ }
114
+ /**
115
+ * Empty an array in-place (remove all elements) and return it.
116
+ * @typeParam T - element type
117
+ */
118
+ function arrayEmptyInPlace(arr) {
119
+ arr.splice(0, arr.length);
120
+ return arr;
121
+ }
122
+ /**
123
+ * Replace the contents of `array` in-place with `newContent` and return it.
124
+ * @typeParam T - element type
125
+ * @param arr - target array to overwrite
126
+ * @param newContent - new contents to set
127
+ * @returns the same array instance after replacement
128
+ */
129
+ function arraySetArrayInPlace(arr, newContent) {
130
+ arr.splice(0, arr.length, ...newContent);
131
+ return arr;
132
+ }
133
+ /**
134
+ * Return a sorted copy of the provided iterable or array-like object.
135
+ * @typeParam T - element type
136
+ * @param arr - iterable or array-like input
137
+ * @param compareFn - optional compare function (defaults to `cmp`)
138
+ * @returns a new array sorted according to `compareFn`
139
+ */
140
+ function arraySorted(arr, compareFn = cmp) {
141
+ return Array.from(arr).sort(compareFn);
142
+ }
143
+ /**
144
+ * Return a new array with numbers sorted in ascending order.
145
+ * @param arr - array of numbers
146
+ * @returns sorted array of numbers
147
+ */
148
+ function arraySortedNumbers(arr) {
149
+ return arraySorted(arr, (l, r) => l - r);
150
+ }
151
+ /**
152
+ * Check strict equality of two arrays by length and element-wise === comparison.
153
+ * @typeParam T - element type
154
+ * @param array1 - first array
155
+ * @param array2 - second array
156
+ * @returns `true` if arrays are same length and all elements strictly equal
157
+ */
158
+ function arrayIsEqual(array1, array2) {
159
+ return array1.length === array2.length && array1.every((value, index) => value === array2[index]);
160
+ }
161
+ /**
162
+ * Shuffle an array in-place using a secure random source if available.
163
+ * Note: uses Array.sort with random comparator which is sufficient for many cases but
164
+ * not perfectly uniform. Returns the same mutated array.
165
+ * @typeParam T - element type
166
+ * @param array - array to shuffle in-place
167
+ * @returns the shuffled array (same instance)
168
+ */
169
+ function arrayShuffleInPlace(arr) {
170
+ arr.sort(() => getSecureRandomIfPossible() > .5 ? 1 : -1);
171
+ return arr;
172
+ }
173
+ /**
174
+ * Return a shuffled copy of `array` (original array is not modified).
175
+ * @typeParam T - element type
176
+ * @param array - input array
177
+ * @returns a new shuffled array
178
+ */
179
+ function arrayShuffle(arr) {
180
+ return arrayShuffleInPlace(Array.from(arr));
181
+ }
182
+ /** Randomly shuffle the order of the array's elements. Force to have a different order if array has more than one element. */
183
+ /**
184
+ * Shuffle `array` and ensure the returned order differs from the original when possible.
185
+ * If array length is 0 or 1 it is returned unchanged.
186
+ * @typeParam T - element type
187
+ * @param array - input array
188
+ * @returns a shuffled array that's different from the input when feasible
189
+ */
190
+ function arrayShuffleForce(arr) {
191
+ while (arr.length > 1) {
192
+ const copy = Array.from(arr);
193
+ arrayShuffleInPlace(copy);
194
+ if (!arrayIsEqual(arr, copy)) return copy;
195
+ }
196
+ return arr;
197
+ }
198
+ /**
199
+ * Return a random element from `array` using a secure random source if available.
200
+ * @typeParam T - element type
201
+ * @param array - input array (must be non-empty)
202
+ * @returns a randomly selected element
203
+ */
204
+ function arrayRandomElement(arr) {
205
+ return arr[Math.floor(getSecureRandomIfPossible() * arr.length)];
206
+ }
207
+ /**
208
+ * Return the maximum value from one or more nested arrays.
209
+ * Uses the `>` operator for comparison.
210
+ * @typeParam T - element type (should support `>` comparison)
211
+ * @param arrays - nested arrays to search
212
+ * @returns the maximum value or `undefined` if no elements present
213
+ */
214
+ function arrayMax(...arrays) {
215
+ return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value > acc ? value : acc : value, void 0);
216
+ }
217
+ /**
218
+ * Return the minimum value from one or more nested arrays.
219
+ * Uses the `<` operator for comparison.
220
+ * @typeParam T - element type (should support `<` comparison)
221
+ * @param arrays - nested arrays to search
222
+ * @returns the minimum value or `undefined` if no elements present
223
+ */
224
+ function arrayMin(...arrays) {
225
+ return arrayFlatten(...arrays).reduce((acc, value) => acc != null ? value < acc ? value : acc : value, void 0);
226
+ }
227
+ /**
228
+ * Sum all numbers in one or more nested arrays.
229
+ * @param arrays - nested arrays of numbers
230
+ * @returns the numeric sum (0 for empty input)
231
+ */
232
+ function arraySum(...arrays) {
233
+ return arrayFlatten(...arrays).reduce((acc, value) => acc + value, 0);
234
+ }
235
+ /**
236
+ * Compute the average of numbers across one or more nested arrays.
237
+ * @param arrays - nested arrays of numbers
238
+ * @returns arithmetic mean (NaN if there are no elements)
239
+ */
240
+ function arrayAvg(...arrays) {
241
+ const flatArray = arrayFlatten(...arrays);
242
+ return flatArray.reduce((acc, value) => acc + value, 0) / flatArray.length;
243
+ }
244
+ /**
245
+ * Split an array into chunks of `chunkLength` (last chunk may be smaller).
246
+ * @typeParam T - element type
247
+ * @param arr - input array
248
+ * @param chunkLength - chunk size (positive integer)
249
+ * @returns array of chunk arrays
250
+ */
251
+ function arrayBatches(arr, chunkLength) {
252
+ const chunks = [];
253
+ let i = 0;
254
+ const n = arr.length;
255
+ while (i < n) chunks.push(arr.slice(i, i += chunkLength));
256
+ return chunks;
257
+ }
258
+ /**
259
+ * Create an array of given `length` filled with `item` or the result of `item(index)`.
260
+ * If `length` is <= 0 an empty array is returned.
261
+ * @typeParam T - element type
262
+ * @param length - desired length of the array
263
+ * @param item - value to fill or a function producing a value per index
264
+ * @returns newly created array of length `length`
265
+ */
266
+ function createArray(length = 0, item) {
267
+ if (length <= 0) return [];
268
+ const arr = Array.from({ length });
269
+ for (let i = 0; i < length; i++) arr[i] = item instanceof Function ? item(i) : item;
270
+ return arr;
271
+ }
272
+
273
+ //#endregion
274
+ export { arrayAvg, arrayBatches, arrayEmptyInPlace, arrayFilterInPlace, arrayFlatten, arrayIntersection, arrayIsEqual, arrayMax, arrayMin, arrayMinus, arrayRandomElement, arrayRemoveElement, arraySetArrayInPlace, arraySetElement, arrayShuffle, arrayShuffleForce, arrayShuffleInPlace, arraySorted, arraySortedNumbers, arraySum, arraySymmetricDifference, arrayToggleInPlace, arrayUnion, arrayUnique, createArray };
2
275
  //# sourceMappingURL=array.mjs.map