@blazetrails/ruby-compat 0.0.0-stage → 0.1.0-alpha0.2

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 (625) hide show
  1. package/LICENSE +21 -0
  2. package/NOTICE +6 -0
  3. package/README.md +440 -2
  4. package/dist/argument-error.d.ts +15 -0
  5. package/dist/argument-error.js +15 -0
  6. package/dist/argument-error.js.map +1 -0
  7. package/dist/array.d.ts +415 -0
  8. package/dist/array.js +1330 -0
  9. package/dist/array.js.map +1 -0
  10. package/dist/async-context-adapter.d.ts +19 -0
  11. package/dist/async-context-adapter.js +139 -0
  12. package/dist/async-context-adapter.js.map +1 -0
  13. package/dist/backtrace-location.d.ts +78 -0
  14. package/dist/backtrace-location.js +158 -0
  15. package/dist/backtrace-location.js.map +1 -0
  16. package/dist/base64.d.ts +73 -0
  17. package/dist/base64.js +164 -0
  18. package/dist/base64.js.map +1 -0
  19. package/dist/benchmark.d.ts +19 -0
  20. package/dist/benchmark.js +16 -0
  21. package/dist/benchmark.js.map +1 -0
  22. package/dist/big-decimal.d.ts +111 -0
  23. package/dist/big-decimal.js +584 -0
  24. package/dist/big-decimal.js.map +1 -0
  25. package/dist/bundler.d.ts +44 -0
  26. package/dist/bundler.js +97 -0
  27. package/dist/bundler.js.map +1 -0
  28. package/dist/cgi.d.ts +89 -0
  29. package/dist/cgi.js +168 -0
  30. package/dist/cgi.js.map +1 -0
  31. package/dist/child-process-adapter.d.ts +110 -0
  32. package/dist/child-process-adapter.js +272 -0
  33. package/dist/child-process-adapter.js.map +1 -0
  34. package/dist/class-module.d.ts +10 -0
  35. package/dist/class-module.js +10 -0
  36. package/dist/class-module.js.map +1 -0
  37. package/dist/classpath.d.ts +93 -0
  38. package/dist/classpath.js +210 -0
  39. package/dist/classpath.js.map +1 -0
  40. package/dist/closed-queue-error.d.ts +10 -0
  41. package/dist/closed-queue-error.js +10 -0
  42. package/dist/closed-queue-error.js.map +1 -0
  43. package/dist/comparable.d.ts +127 -0
  44. package/dist/comparable.js +376 -0
  45. package/dist/comparable.js.map +1 -0
  46. package/dist/complex.d.ts +49 -0
  47. package/dist/complex.js +164 -0
  48. package/dist/complex.js.map +1 -0
  49. package/dist/concurrent/atomic-boolean.d.ts +24 -0
  50. package/dist/concurrent/atomic-boolean.js +43 -0
  51. package/dist/concurrent/atomic-boolean.js.map +1 -0
  52. package/dist/concurrent/atomic-fixnum.d.ts +21 -0
  53. package/dist/concurrent/atomic-fixnum.js +35 -0
  54. package/dist/concurrent/atomic-fixnum.js.map +1 -0
  55. package/dist/concurrent/count-down-latch.d.ts +20 -0
  56. package/dist/concurrent/count-down-latch.js +50 -0
  57. package/dist/concurrent/count-down-latch.js.map +1 -0
  58. package/dist/concurrent/cyclic-barrier.d.ts +18 -0
  59. package/dist/concurrent/cyclic-barrier.js +50 -0
  60. package/dist/concurrent/cyclic-barrier.js.map +1 -0
  61. package/dist/concurrent/event.d.ts +19 -0
  62. package/dist/concurrent/event.js +31 -0
  63. package/dist/concurrent/event.js.map +1 -0
  64. package/dist/concurrent/map.d.ts +149 -0
  65. package/dist/concurrent/map.js +202 -0
  66. package/dist/concurrent/map.js.map +1 -0
  67. package/dist/concurrent/read-write-lock.d.ts +25 -0
  68. package/dist/concurrent/read-write-lock.js +70 -0
  69. package/dist/concurrent/read-write-lock.js.map +1 -0
  70. package/dist/concurrent/semaphore.d.ts +24 -0
  71. package/dist/concurrent/semaphore.js +74 -0
  72. package/dist/concurrent/semaphore.js.map +1 -0
  73. package/dist/concurrent/timer-task.d.ts +52 -0
  74. package/dist/concurrent/timer-task.js +112 -0
  75. package/dist/concurrent/timer-task.js.map +1 -0
  76. package/dist/constants.generated.d.ts +2 -0
  77. package/dist/constants.generated.js +64 -0
  78. package/dist/constants.generated.js.map +1 -0
  79. package/dist/converter-not-found-error.d.ts +14 -0
  80. package/dist/converter-not-found-error.js +14 -0
  81. package/dist/converter-not-found-error.js.map +1 -0
  82. package/dist/crypto-adapter.d.ts +64 -0
  83. package/dist/crypto-adapter.js +365 -0
  84. package/dist/crypto-adapter.js.map +1 -0
  85. package/dist/delegate.d.ts +156 -0
  86. package/dist/delegate.js +306 -0
  87. package/dist/delegate.js.map +1 -0
  88. package/dist/digest.d.ts +99 -0
  89. package/dist/digest.js +131 -0
  90. package/dist/digest.js.map +1 -0
  91. package/dist/dir.d.ts +225 -0
  92. package/dist/dir.js +608 -0
  93. package/dist/dir.js.map +1 -0
  94. package/dist/encoding-error.d.ts +14 -0
  95. package/dist/encoding-error.js +17 -0
  96. package/dist/encoding-error.js.map +1 -0
  97. package/dist/encoding.d.ts +121 -0
  98. package/dist/encoding.js +306 -0
  99. package/dist/encoding.js.map +1 -0
  100. package/dist/ensure.d.ts +15 -0
  101. package/dist/ensure.js +35 -0
  102. package/dist/ensure.js.map +1 -0
  103. package/dist/enumerable.d.ts +375 -0
  104. package/dist/enumerable.js +1102 -0
  105. package/dist/enumerable.js.map +1 -0
  106. package/dist/enumerator.d.ts +324 -0
  107. package/dist/enumerator.js +625 -0
  108. package/dist/enumerator.js.map +1 -0
  109. package/dist/eof-error.d.ts +14 -0
  110. package/dist/eof-error.js +14 -0
  111. package/dist/eof-error.js.map +1 -0
  112. package/dist/errno.d.ts +447 -0
  113. package/dist/errno.js +616 -0
  114. package/dist/errno.js.map +1 -0
  115. package/dist/exc-detailed-message.d.ts +15 -0
  116. package/dist/exc-detailed-message.js +106 -0
  117. package/dist/exc-detailed-message.js.map +1 -0
  118. package/dist/exc-to-s.d.ts +10 -0
  119. package/dist/exc-to-s.js +21 -0
  120. package/dist/exc-to-s.js.map +1 -0
  121. package/dist/exception.d.ts +44 -0
  122. package/dist/exception.js +115 -0
  123. package/dist/exception.js.map +1 -0
  124. package/dist/fiber-error.d.ts +12 -0
  125. package/dist/fiber-error.js +12 -0
  126. package/dist/fiber-error.js.map +1 -0
  127. package/dist/fiber.d.ts +51 -0
  128. package/dist/fiber.js +178 -0
  129. package/dist/fiber.js.map +1 -0
  130. package/dist/file-utils.d.ts +480 -0
  131. package/dist/file-utils.js +1824 -0
  132. package/dist/file-utils.js.map +1 -0
  133. package/dist/file.d.ts +643 -0
  134. package/dist/file.js +1334 -0
  135. package/dist/file.js.map +1 -0
  136. package/dist/float-domain-error.d.ts +17 -0
  137. package/dist/float-domain-error.js +17 -0
  138. package/dist/float-domain-error.js.map +1 -0
  139. package/dist/fork-children.d.ts +23 -0
  140. package/dist/fork-children.js +32 -0
  141. package/dist/fork-children.js.map +1 -0
  142. package/dist/frozen-error.d.ts +33 -0
  143. package/dist/frozen-error.js +41 -0
  144. package/dist/frozen-error.js.map +1 -0
  145. package/dist/fs-adapter.d.ts +158 -0
  146. package/dist/fs-adapter.js +253 -0
  147. package/dist/fs-adapter.js.map +1 -0
  148. package/dist/gem/deprecate.d.ts +10 -0
  149. package/dist/gem/deprecate.js +8 -0
  150. package/dist/gem/deprecate.js.map +1 -0
  151. package/dist/gem/requirement.d.ts +55 -0
  152. package/dist/gem/requirement.js +91 -0
  153. package/dist/gem/requirement.js.map +1 -0
  154. package/dist/gem/version.d.ts +50 -0
  155. package/dist/gem/version.js +148 -0
  156. package/dist/gem/version.js.map +1 -0
  157. package/dist/gem.d.ts +59 -0
  158. package/dist/gem.js +82 -0
  159. package/dist/gem.js.map +1 -0
  160. package/dist/hash.d.ts +967 -0
  161. package/dist/hash.js +1572 -0
  162. package/dist/hash.js.map +1 -0
  163. package/dist/http-adapter.d.ts +124 -0
  164. package/dist/http-adapter.js +220 -0
  165. package/dist/http-adapter.js.map +1 -0
  166. package/dist/immediate-executor.d.ts +20 -0
  167. package/dist/immediate-executor.js +39 -0
  168. package/dist/immediate-executor.js.map +1 -0
  169. package/dist/include.d.ts +778 -0
  170. package/dist/include.js +2208 -0
  171. package/dist/include.js.map +1 -0
  172. package/dist/index-error.d.ts +13 -0
  173. package/dist/index-error.js +13 -0
  174. package/dist/index-error.js.map +1 -0
  175. package/dist/index.d.ts +174 -0
  176. package/dist/index.js +166 -0
  177. package/dist/index.js.map +1 -0
  178. package/dist/invalid-byte-sequence-error.d.ts +62 -0
  179. package/dist/invalid-byte-sequence-error.js +75 -0
  180. package/dist/invalid-byte-sequence-error.js.map +1 -0
  181. package/dist/io-error.d.ts +14 -0
  182. package/dist/io-error.js +17 -0
  183. package/dist/io-error.js.map +1 -0
  184. package/dist/io.d.ts +867 -0
  185. package/dist/io.js +1960 -0
  186. package/dist/io.js.map +1 -0
  187. package/dist/ipaddr.d.ts +79 -0
  188. package/dist/ipaddr.js +405 -0
  189. package/dist/ipaddr.js.map +1 -0
  190. package/dist/json.d.ts +70 -0
  191. package/dist/json.js +181 -0
  192. package/dist/json.js.map +1 -0
  193. package/dist/kernel-catch.d.ts +59 -0
  194. package/dist/kernel-catch.js +184 -0
  195. package/dist/kernel-catch.js.map +1 -0
  196. package/dist/kernel-float.d.ts +19 -0
  197. package/dist/kernel-float.js +54 -0
  198. package/dist/kernel-float.js.map +1 -0
  199. package/dist/kernel-fork.d.ts +30 -0
  200. package/dist/kernel-fork.js +72 -0
  201. package/dist/kernel-fork.js.map +1 -0
  202. package/dist/kernel-format.d.ts +27 -0
  203. package/dist/kernel-format.js +901 -0
  204. package/dist/kernel-format.js.map +1 -0
  205. package/dist/kernel-hash.d.ts +7 -0
  206. package/dist/kernel-hash.js +33 -0
  207. package/dist/kernel-hash.js.map +1 -0
  208. package/dist/kernel-integer.d.ts +49 -0
  209. package/dist/kernel-integer.js +170 -0
  210. package/dist/kernel-integer.js.map +1 -0
  211. package/dist/kernel-rand.d.ts +16 -0
  212. package/dist/kernel-rand.js +237 -0
  213. package/dist/kernel-rand.js.map +1 -0
  214. package/dist/kernel-system.d.ts +39 -0
  215. package/dist/kernel-system.js +103 -0
  216. package/dist/kernel-system.js.map +1 -0
  217. package/dist/kernel-warn.d.ts +35 -0
  218. package/dist/kernel-warn.js +73 -0
  219. package/dist/kernel-warn.js.map +1 -0
  220. package/dist/key-error.d.ts +44 -0
  221. package/dist/key-error.js +59 -0
  222. package/dist/key-error.js.map +1 -0
  223. package/dist/keyword-splat.d.ts +41 -0
  224. package/dist/keyword-splat.js +65 -0
  225. package/dist/keyword-splat.js.map +1 -0
  226. package/dist/load-error.d.ts +19 -0
  227. package/dist/load-error.js +19 -0
  228. package/dist/load-error.js.map +1 -0
  229. package/dist/load.d.ts +128 -0
  230. package/dist/load.js +278 -0
  231. package/dist/load.js.map +1 -0
  232. package/dist/loaded-features.d.ts +13 -0
  233. package/dist/loaded-features.js +15 -0
  234. package/dist/loaded-features.js.map +1 -0
  235. package/dist/local-jump-error.d.ts +12 -0
  236. package/dist/local-jump-error.js +12 -0
  237. package/dist/local-jump-error.js.map +1 -0
  238. package/dist/logger/formatter.d.ts +21 -0
  239. package/dist/logger/formatter.js +43 -0
  240. package/dist/logger/formatter.js.map +1 -0
  241. package/dist/logger/log-device.d.ts +52 -0
  242. package/dist/logger/log-device.js +104 -0
  243. package/dist/logger/log-device.js.map +1 -0
  244. package/dist/logger/severity.d.ts +23 -0
  245. package/dist/logger/severity.js +42 -0
  246. package/dist/logger/severity.js.map +1 -0
  247. package/dist/logger.d.ts +127 -0
  248. package/dist/logger.js +218 -0
  249. package/dist/logger.js.map +1 -0
  250. package/dist/marshal.d.ts +83 -0
  251. package/dist/marshal.js +1487 -0
  252. package/dist/marshal.js.map +1 -0
  253. package/dist/match-data.d.ts +161 -0
  254. package/dist/match-data.js +284 -0
  255. package/dist/match-data.js.map +1 -0
  256. package/dist/method-cache.d.ts +81 -0
  257. package/dist/method-cache.js +109 -0
  258. package/dist/method-cache.js.map +1 -0
  259. package/dist/method-missing-proxy.d.ts +53 -0
  260. package/dist/method-missing-proxy.js +154 -0
  261. package/dist/method-missing-proxy.js.map +1 -0
  262. package/dist/method.d.ts +132 -0
  263. package/dist/method.js +320 -0
  264. package/dist/method.js.map +1 -0
  265. package/dist/monitor.d.ts +114 -0
  266. package/dist/monitor.js +270 -0
  267. package/dist/monitor.js.map +1 -0
  268. package/dist/mutex.d.ts +51 -0
  269. package/dist/mutex.js +150 -0
  270. package/dist/mutex.js.map +1 -0
  271. package/dist/name-error.d.ts +45 -0
  272. package/dist/name-error.js +54 -0
  273. package/dist/name-error.js.map +1 -0
  274. package/dist/net/http/exceptions.d.ts +31 -0
  275. package/dist/net/http/exceptions.js +46 -0
  276. package/dist/net/http/exceptions.js.map +1 -0
  277. package/dist/net/http/request.d.ts +137 -0
  278. package/dist/net/http/request.js +559 -0
  279. package/dist/net/http/request.js.map +1 -0
  280. package/dist/net/http/requests.d.ts +197 -0
  281. package/dist/net/http/requests.js +197 -0
  282. package/dist/net/http/requests.js.map +1 -0
  283. package/dist/net/http/response.d.ts +141 -0
  284. package/dist/net/http/response.js +416 -0
  285. package/dist/net/http/response.js.map +1 -0
  286. package/dist/net/http/responses.d.ts +345 -0
  287. package/dist/net/http/responses.js +486 -0
  288. package/dist/net/http/responses.js.map +1 -0
  289. package/dist/net/http.d.ts +278 -0
  290. package/dist/net/http.js +760 -0
  291. package/dist/net/http.js.map +1 -0
  292. package/dist/net/protocol.d.ts +227 -0
  293. package/dist/net/protocol.js +392 -0
  294. package/dist/net/protocol.js.map +1 -0
  295. package/dist/nil-class.d.ts +10 -0
  296. package/dist/nil-class.js +27 -0
  297. package/dist/nil-class.js.map +1 -0
  298. package/dist/no-method-error.d.ts +38 -0
  299. package/dist/no-method-error.js +45 -0
  300. package/dist/no-method-error.js.map +1 -0
  301. package/dist/not-implemented-error.d.ts +13 -0
  302. package/dist/not-implemented-error.js +13 -0
  303. package/dist/not-implemented-error.js.map +1 -0
  304. package/dist/numeric-class.d.ts +29 -0
  305. package/dist/numeric-class.js +41 -0
  306. package/dist/numeric-class.js.map +1 -0
  307. package/dist/numeric.d.ts +226 -0
  308. package/dist/numeric.js +848 -0
  309. package/dist/numeric.js.map +1 -0
  310. package/dist/object-space.d.ts +34 -0
  311. package/dist/object-space.js +152 -0
  312. package/dist/object-space.js.map +1 -0
  313. package/dist/object.d.ts +833 -0
  314. package/dist/object.js +2131 -0
  315. package/dist/object.js.map +1 -0
  316. package/dist/open-uri.d.ts +180 -0
  317. package/dist/open-uri.js +402 -0
  318. package/dist/open-uri.js.map +1 -0
  319. package/dist/open3.d.ts +69 -0
  320. package/dist/open3.js +134 -0
  321. package/dist/open3.js.map +1 -0
  322. package/dist/openssl.d.ts +479 -0
  323. package/dist/openssl.js +1052 -0
  324. package/dist/openssl.js.map +1 -0
  325. package/dist/optparse.d.ts +130 -0
  326. package/dist/optparse.js +457 -0
  327. package/dist/optparse.js.map +1 -0
  328. package/dist/os-adapter.d.ts +20 -0
  329. package/dist/os-adapter.js +95 -0
  330. package/dist/os-adapter.js.map +1 -0
  331. package/dist/pathname.d.ts +73 -0
  332. package/dist/pathname.js +412 -0
  333. package/dist/pathname.js.map +1 -0
  334. package/dist/pp.d.ts +60 -0
  335. package/dist/pp.js +195 -0
  336. package/dist/pp.js.map +1 -0
  337. package/dist/pretty-print.d.ts +89 -0
  338. package/dist/pretty-print.js +232 -0
  339. package/dist/pretty-print.js.map +1 -0
  340. package/dist/process-adapter.d.ts +229 -0
  341. package/dist/process-adapter.js +889 -0
  342. package/dist/process-adapter.js.map +1 -0
  343. package/dist/process.d.ts +202 -0
  344. package/dist/process.js +433 -0
  345. package/dist/process.js.map +1 -0
  346. package/dist/psych/class-loader.d.ts +92 -0
  347. package/dist/psych/class-loader.js +139 -0
  348. package/dist/psych/class-loader.js.map +1 -0
  349. package/dist/psych/coder.d.ts +144 -0
  350. package/dist/psych/coder.js +176 -0
  351. package/dist/psych/coder.js.map +1 -0
  352. package/dist/psych/core-ext.d.ts +8 -0
  353. package/dist/psych/core-ext.js +10 -0
  354. package/dist/psych/core-ext.js.map +1 -0
  355. package/dist/psych/emitter.d.ts +116 -0
  356. package/dist/psych/emitter.js +1130 -0
  357. package/dist/psych/emitter.js.map +1 -0
  358. package/dist/psych/exception.d.ts +43 -0
  359. package/dist/psych/exception.js +54 -0
  360. package/dist/psych/exception.js.map +1 -0
  361. package/dist/psych/handler.d.ts +59 -0
  362. package/dist/psych/handler.js +95 -0
  363. package/dist/psych/handler.js.map +1 -0
  364. package/dist/psych/handlers/document-stream.d.ts +17 -0
  365. package/dist/psych/handlers/document-stream.js +26 -0
  366. package/dist/psych/handlers/document-stream.js.map +1 -0
  367. package/dist/psych/nodes/alias.d.ts +15 -0
  368. package/dist/psych/nodes/alias.js +22 -0
  369. package/dist/psych/nodes/alias.js.map +1 -0
  370. package/dist/psych/nodes/document.d.ts +23 -0
  371. package/dist/psych/nodes/document.js +35 -0
  372. package/dist/psych/nodes/document.js.map +1 -0
  373. package/dist/psych/nodes/mapping.d.ts +25 -0
  374. package/dist/psych/nodes/mapping.js +35 -0
  375. package/dist/psych/nodes/mapping.js.map +1 -0
  376. package/dist/psych/nodes/node.d.ts +59 -0
  377. package/dist/psych/nodes/node.js +79 -0
  378. package/dist/psych/nodes/node.js.map +1 -0
  379. package/dist/psych/nodes/scalar.d.ts +35 -0
  380. package/dist/psych/nodes/scalar.js +47 -0
  381. package/dist/psych/nodes/scalar.js.map +1 -0
  382. package/dist/psych/nodes/sequence.d.ts +25 -0
  383. package/dist/psych/nodes/sequence.js +35 -0
  384. package/dist/psych/nodes/sequence.js.map +1 -0
  385. package/dist/psych/nodes/stream.d.ts +23 -0
  386. package/dist/psych/nodes/stream.js +31 -0
  387. package/dist/psych/nodes/stream.js.map +1 -0
  388. package/dist/psych/omap.d.ts +9 -0
  389. package/dist/psych/omap.js +9 -0
  390. package/dist/psych/omap.js.map +1 -0
  391. package/dist/psych/parser.d.ts +41 -0
  392. package/dist/psych/parser.js +139 -0
  393. package/dist/psych/parser.js.map +1 -0
  394. package/dist/psych/scalar-scanner.d.ts +31 -0
  395. package/dist/psych/scalar-scanner.js +169 -0
  396. package/dist/psych/scalar-scanner.js.map +1 -0
  397. package/dist/psych/syntax-error.d.ts +23 -0
  398. package/dist/psych/syntax-error.js +35 -0
  399. package/dist/psych/syntax-error.js.map +1 -0
  400. package/dist/psych/tree-builder.d.ts +51 -0
  401. package/dist/psych/tree-builder.js +118 -0
  402. package/dist/psych/tree-builder.js.map +1 -0
  403. package/dist/psych/visitors/depth-first.d.ts +27 -0
  404. package/dist/psych/visitors/depth-first.js +37 -0
  405. package/dist/psych/visitors/depth-first.js.map +1 -0
  406. package/dist/psych/visitors/emitter.d.ts +32 -0
  407. package/dist/psych/visitors/emitter.js +63 -0
  408. package/dist/psych/visitors/emitter.js.map +1 -0
  409. package/dist/psych/visitors/to-ruby.d.ts +110 -0
  410. package/dist/psych/visitors/to-ruby.js +396 -0
  411. package/dist/psych/visitors/to-ruby.js.map +1 -0
  412. package/dist/psych/visitors/visitor.d.ts +11 -0
  413. package/dist/psych/visitors/visitor.js +17 -0
  414. package/dist/psych/visitors/visitor.js.map +1 -0
  415. package/dist/psych/visitors/yaml-tree.d.ts +182 -0
  416. package/dist/psych/visitors/yaml-tree.js +593 -0
  417. package/dist/psych/visitors/yaml-tree.js.map +1 -0
  418. package/dist/psych-adapter.d.ts +65 -0
  419. package/dist/psych-adapter.js +121 -0
  420. package/dist/psych-adapter.js.map +1 -0
  421. package/dist/psych-yaml.d.ts +2 -0
  422. package/dist/psych-yaml.js +5 -0
  423. package/dist/psych-yaml.js.map +1 -0
  424. package/dist/psych.d.ts +257 -0
  425. package/dist/psych.js +332 -0
  426. package/dist/psych.js.map +1 -0
  427. package/dist/queue.d.ts +137 -0
  428. package/dist/queue.js +236 -0
  429. package/dist/queue.js.map +1 -0
  430. package/dist/racc/parser.d.ts +70 -0
  431. package/dist/racc/parser.js +206 -0
  432. package/dist/racc/parser.js.map +1 -0
  433. package/dist/range-error.d.ts +15 -0
  434. package/dist/range-error.js +15 -0
  435. package/dist/range-error.js.map +1 -0
  436. package/dist/range.d.ts +166 -0
  437. package/dist/range.js +421 -0
  438. package/dist/range.js.map +1 -0
  439. package/dist/rational.d.ts +168 -0
  440. package/dist/rational.js +587 -0
  441. package/dist/rational.js.map +1 -0
  442. package/dist/rb-config.d.ts +33 -0
  443. package/dist/rb-config.js +53 -0
  444. package/dist/rb-config.js.map +1 -0
  445. package/dist/rb-equal.d.ts +66 -0
  446. package/dist/rb-equal.js +262 -0
  447. package/dist/rb-equal.js.map +1 -0
  448. package/dist/rb-hash.d.ts +26 -0
  449. package/dist/rb-hash.js +108 -0
  450. package/dist/rb-hash.js.map +1 -0
  451. package/dist/regexp.d.ts +82 -0
  452. package/dist/regexp.js +191 -0
  453. package/dist/regexp.js.map +1 -0
  454. package/dist/repl-adapter.d.ts +270 -0
  455. package/dist/repl-adapter.js +562 -0
  456. package/dist/repl-adapter.js.map +1 -0
  457. package/dist/resolv.d.ts +30 -0
  458. package/dist/resolv.js +48 -0
  459. package/dist/resolv.js.map +1 -0
  460. package/dist/ruby-empty.d.ts +28 -0
  461. package/dist/ruby-empty.js +40 -0
  462. package/dist/ruby-empty.js.map +1 -0
  463. package/dist/ruby-platform.d.ts +39 -0
  464. package/dist/ruby-platform.js +49 -0
  465. package/dist/ruby-platform.js.map +1 -0
  466. package/dist/runtime-error.d.ts +15 -0
  467. package/dist/runtime-error.js +15 -0
  468. package/dist/runtime-error.js.map +1 -0
  469. package/dist/scheduled-task.d.ts +73 -0
  470. package/dist/scheduled-task.js +150 -0
  471. package/dist/scheduled-task.js.map +1 -0
  472. package/dist/secure-random.d.ts +50 -0
  473. package/dist/secure-random.js +141 -0
  474. package/dist/secure-random.js.map +1 -0
  475. package/dist/set.d.ts +158 -0
  476. package/dist/set.js +352 -0
  477. package/dist/set.js.map +1 -0
  478. package/dist/shellwords.d.ts +27 -0
  479. package/dist/shellwords.js +53 -0
  480. package/dist/shellwords.js.map +1 -0
  481. package/dist/signal-exception.d.ts +43 -0
  482. package/dist/signal-exception.js +88 -0
  483. package/dist/signal-exception.js.map +1 -0
  484. package/dist/socket.d.ts +230 -0
  485. package/dist/socket.js +484 -0
  486. package/dist/socket.js.map +1 -0
  487. package/dist/standard-error.d.ts +27 -0
  488. package/dist/standard-error.js +49 -0
  489. package/dist/standard-error.js.map +1 -0
  490. package/dist/stop-iteration.d.ts +10 -0
  491. package/dist/stop-iteration.js +10 -0
  492. package/dist/stop-iteration.js.map +1 -0
  493. package/dist/string/b.d.ts +19 -0
  494. package/dist/string/b.js +28 -0
  495. package/dist/string/b.js.map +1 -0
  496. package/dist/string/byte-methods.d.ts +57 -0
  497. package/dist/string/byte-methods.js +266 -0
  498. package/dist/string/byte-methods.js.map +1 -0
  499. package/dist/string/bytes.d.ts +35 -0
  500. package/dist/string/bytes.js +123 -0
  501. package/dist/string/bytes.js.map +1 -0
  502. package/dist/string/case-mapping.d.ts +57 -0
  503. package/dist/string/case-mapping.js +192 -0
  504. package/dist/string/case-mapping.js.map +1 -0
  505. package/dist/string/chomp.d.ts +15 -0
  506. package/dist/string/chomp.js +32 -0
  507. package/dist/string/chomp.js.map +1 -0
  508. package/dist/string/convert.d.ts +55 -0
  509. package/dist/string/convert.js +316 -0
  510. package/dist/string/convert.js.map +1 -0
  511. package/dist/string/delete.d.ts +14 -0
  512. package/dist/string/delete.js +17 -0
  513. package/dist/string/delete.js.map +1 -0
  514. package/dist/string/each.d.ts +108 -0
  515. package/dist/string/each.js +305 -0
  516. package/dist/string/each.js.map +1 -0
  517. package/dist/string/encode.d.ts +37 -0
  518. package/dist/string/encode.js +268 -0
  519. package/dist/string/encode.js.map +1 -0
  520. package/dist/string/force-encoding.d.ts +72 -0
  521. package/dist/string/force-encoding.js +147 -0
  522. package/dist/string/force-encoding.js.map +1 -0
  523. package/dist/string/inspect.d.ts +17 -0
  524. package/dist/string/inspect.js +81 -0
  525. package/dist/string/inspect.js.map +1 -0
  526. package/dist/string/method-table.d.ts +174 -0
  527. package/dist/string/method-table.js +805 -0
  528. package/dist/string/method-table.js.map +1 -0
  529. package/dist/string/scrub.d.ts +12 -0
  530. package/dist/string/scrub.js +33 -0
  531. package/dist/string/scrub.js.map +1 -0
  532. package/dist/string/slice.d.ts +26 -0
  533. package/dist/string/slice.js +73 -0
  534. package/dist/string/slice.js.map +1 -0
  535. package/dist/string/split.d.ts +11 -0
  536. package/dist/string/split.js +44 -0
  537. package/dist/string/split.js.map +1 -0
  538. package/dist/string/sub.d.ts +114 -0
  539. package/dist/string/sub.js +371 -0
  540. package/dist/string/sub.js.map +1 -0
  541. package/dist/string/succ.d.ts +14 -0
  542. package/dist/string/succ.js +118 -0
  543. package/dist/string/succ.js.map +1 -0
  544. package/dist/string/support.d.ts +142 -0
  545. package/dist/string/support.js +296 -0
  546. package/dist/string/support.js.map +1 -0
  547. package/dist/string/tr.d.ts +46 -0
  548. package/dist/string/tr.js +156 -0
  549. package/dist/string/tr.js.map +1 -0
  550. package/dist/string-io.d.ts +166 -0
  551. package/dist/string-io.js +248 -0
  552. package/dist/string-io.js.map +1 -0
  553. package/dist/string-scanner.d.ts +133 -0
  554. package/dist/string-scanner.js +248 -0
  555. package/dist/string-scanner.js.map +1 -0
  556. package/dist/struct.d.ts +54 -0
  557. package/dist/struct.js +222 -0
  558. package/dist/struct.js.map +1 -0
  559. package/dist/symbol.d.ts +48 -0
  560. package/dist/symbol.js +107 -0
  561. package/dist/symbol.js.map +1 -0
  562. package/dist/tempfile.d.ts +173 -0
  563. package/dist/tempfile.js +295 -0
  564. package/dist/tempfile.js.map +1 -0
  565. package/dist/temporal-tag.d.ts +23 -0
  566. package/dist/temporal-tag.js +29 -0
  567. package/dist/temporal-tag.js.map +1 -0
  568. package/dist/thread-error.d.ts +13 -0
  569. package/dist/thread-error.js +13 -0
  570. package/dist/thread-error.js.map +1 -0
  571. package/dist/thread-pool-executor.d.ts +121 -0
  572. package/dist/thread-pool-executor.js +254 -0
  573. package/dist/thread-pool-executor.js.map +1 -0
  574. package/dist/thread.d.ts +211 -0
  575. package/dist/thread.js +495 -0
  576. package/dist/thread.js.map +1 -0
  577. package/dist/timeout.d.ts +29 -0
  578. package/dist/timeout.js +41 -0
  579. package/dist/timeout.js.map +1 -0
  580. package/dist/tse.d.ts +40 -0
  581. package/dist/tse.js +66 -0
  582. package/dist/tse.js.map +1 -0
  583. package/dist/type-error.d.ts +14 -0
  584. package/dist/type-error.js +14 -0
  585. package/dist/type-error.js.map +1 -0
  586. package/dist/undefined-conversion-error.d.ts +10 -0
  587. package/dist/undefined-conversion-error.js +10 -0
  588. package/dist/undefined-conversion-error.js.map +1 -0
  589. package/dist/uri/common.d.ts +209 -0
  590. package/dist/uri/common.js +369 -0
  591. package/dist/uri/common.js.map +1 -0
  592. package/dist/uri/generic.d.ts +280 -0
  593. package/dist/uri/generic.js +806 -0
  594. package/dist/uri/generic.js.map +1 -0
  595. package/dist/uri/http.d.ts +23 -0
  596. package/dist/uri/http.js +30 -0
  597. package/dist/uri/http.js.map +1 -0
  598. package/dist/uri/https.d.ts +13 -0
  599. package/dist/uri/https.js +15 -0
  600. package/dist/uri/https.js.map +1 -0
  601. package/dist/uri/rfc2396-parser.d.ts +70 -0
  602. package/dist/uri/rfc2396-parser.js +264 -0
  603. package/dist/uri/rfc2396-parser.js.map +1 -0
  604. package/dist/uri/rfc3986-parser.d.ts +46 -0
  605. package/dist/uri/rfc3986-parser.js +171 -0
  606. package/dist/uri/rfc3986-parser.js.map +1 -0
  607. package/dist/uri.d.ts +13 -0
  608. package/dist/uri.js +13 -0
  609. package/dist/uri.js.map +1 -0
  610. package/dist/variable.d.ts +183 -0
  611. package/dist/variable.js +463 -0
  612. package/dist/variable.js.map +1 -0
  613. package/dist/verbose.d.ts +39 -0
  614. package/dist/verbose.js +49 -0
  615. package/dist/verbose.js.map +1 -0
  616. package/dist/yaml.d.ts +9 -0
  617. package/dist/yaml.js +9 -0
  618. package/dist/yaml.js.map +1 -0
  619. package/dist/zlib-adapter.d.ts +119 -0
  620. package/dist/zlib-adapter.js +230 -0
  621. package/dist/zlib-adapter.js.map +1 -0
  622. package/dist/zlib.d.ts +299 -0
  623. package/dist/zlib.js +679 -0
  624. package/dist/zlib.js.map +1 -0
  625. package/package.json +172 -3
package/dist/array.js ADDED
@@ -0,0 +1,1330 @@
1
+ import { IndexError } from "./index-error.js";
2
+ import { rbEql, rbEqq, rbEqual } from "./rb-equal.js";
3
+ import { rbHash } from "./rb-hash.js";
4
+ import { ArgumentError } from "./argument-error.js";
5
+ import { cmp, rbCmpint } from "./comparable.js";
6
+ import { Hash } from "./hash.js";
7
+ import { eachCons, find, partition, sortBy } from "./enumerable.js";
8
+ import { rbBigNorm, rbPlus } from "./numeric.js";
9
+ import { NoMethodError } from "./no-method-error.js";
10
+ import { conversionMismatch, isPlainHash, rbBuiltinClassName, rbObjClassname, rbObjIsProc, rtest, toS, } from "./object.js";
11
+ import { Base64 } from "./base64.js";
12
+ import { Range } from "./range.js";
13
+ import { b } from "./string/b.js";
14
+ import { num2long } from "./string/support.js";
15
+ import { TypeError } from "./type-error.js";
16
+ /** `toofew` (`vendor/ruby/v3.3.11/pack.c:120`). */
17
+ const toofew = "too few arguments";
18
+ /** `endstr` (`vendor/ruby/v3.3.11/pack.c:42`), the types `<` / `>` may follow. */
19
+ const endstr = "sSiIlLqQjJ";
20
+ /** `BIGENDIAN_P()` (`vendor/ruby/v3.3.11/pack.c:58-75`): the host byte order. */
21
+ const BIGENDIAN_P = new Uint8Array(new Uint16Array([1]).buffer)[0] === 0;
22
+ /** `uu_table` (`vendor/ruby/v3.3.11/pack.c:785`). */
23
+ const uuTable = "`!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_";
24
+ /** `b64_table` (`vendor/ruby/v3.3.11/pack.c:787`). */
25
+ const b64Table = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
26
+ /** `unknown_directive` (`vendor/ruby/v3.3.11/pack.c:160`). */
27
+ function unknownDirective(mode, type, fmt) {
28
+ throw new ArgumentError(`unknown ${mode} directive '${type}' in '${fmt}'`);
29
+ }
30
+ /**
31
+ * `encodes` (`vendor/ruby/v3.3.11/pack.c:791`) — `len` bytes of `s0` as Base64
32
+ * (`type == 'm'`) or uuencoded (`type == 'u'`), plus the trailing newline
33
+ * `tailLf` asks for. MRI's `buff_size` flush has no analogue: a JS array grows.
34
+ */
35
+ function encodes(str, s0, len, type, tailLf) {
36
+ const buff = [];
37
+ const trans = type === "u" ? uuTable : b64Table;
38
+ let padding;
39
+ const s = s0;
40
+ let i = 0;
41
+ if (type === "u") {
42
+ buff.push(String.fromCharCode(len + 32));
43
+ padding = "`";
44
+ }
45
+ else {
46
+ padding = "=";
47
+ }
48
+ while (len >= 3) {
49
+ buff.push(trans[0o77 & (s[i] >> 2)]);
50
+ buff.push(trans[0o77 & (((s[i] << 4) & 0o60) | ((s[i + 1] >> 4) & 0o17))]);
51
+ buff.push(trans[0o77 & (((s[i + 1] << 2) & 0o74) | ((s[i + 2] >> 6) & 0o3))]);
52
+ buff.push(trans[0o77 & s[i + 2]]);
53
+ i += 3;
54
+ len -= 3;
55
+ }
56
+ if (len === 2) {
57
+ buff.push(trans[0o77 & (s[i] >> 2)]);
58
+ buff.push(trans[0o77 & (((s[i] << 4) & 0o60) | ((s[i + 1] >> 4) & 0o17))]);
59
+ buff.push(trans[0o77 & (((s[i + 1] << 2) & 0o74) | ((0 >> 6) & 0o3))]);
60
+ buff.push(padding);
61
+ }
62
+ else if (len === 1) {
63
+ buff.push(trans[0o77 & (s[i] >> 2)]);
64
+ buff.push(trans[0o77 & (((s[i] << 4) & 0o60) | ((0 >> 4) & 0o17))]);
65
+ buff.push(padding);
66
+ buff.push(padding);
67
+ }
68
+ if (tailLf)
69
+ buff.push("\n");
70
+ str.push(buff.join(""));
71
+ }
72
+ /** @noRailsEquivalent PERMANENT — Ruby core `Array#pack` (`vendor/ruby/v3.3.11/pack.c:197`). */
73
+ export function pack(ary, fmt) {
74
+ const res = [];
75
+ let encInfo = 1;
76
+ let p = 0;
77
+ const pend = fmt.length;
78
+ let idx = 0;
79
+ const nextfrom = () => {
80
+ if (idx >= ary.length)
81
+ throw new ArgumentError(toofew);
82
+ return ary[idx++];
83
+ };
84
+ /** `hex_table` (`vendor/ruby/v3.3.11/pack.c:839`). */
85
+ const hexTable = "0123456789ABCDEF";
86
+ /**
87
+ * `qpencode` (`vendor/ruby/v3.3.11/pack.c:842`), less MRI's 1024-byte buffer flush.
88
+ */
89
+ function qpencode(str, s, len) {
90
+ const buff = [];
91
+ let n = 0;
92
+ let prev = -1;
93
+ for (const c of s) {
94
+ if (c > 126 || (c < 32 && c !== 0x0a && c !== 0x09) || c === 0x3d) {
95
+ buff.push("=", hexTable[c >> 4], hexTable[c & 0x0f]);
96
+ n += 3;
97
+ prev = -1;
98
+ }
99
+ else if (c === 0x0a) {
100
+ if (prev === 0x20 || prev === 0x09)
101
+ buff.push("=", "\n");
102
+ buff.push("\n");
103
+ n = 0;
104
+ prev = c;
105
+ }
106
+ else {
107
+ buff.push(String.fromCharCode(c));
108
+ n++;
109
+ prev = c;
110
+ }
111
+ if (n > len) {
112
+ buff.push("=", "\n");
113
+ n = 0;
114
+ prev = 0x0a;
115
+ }
116
+ }
117
+ if (n > 0)
118
+ buff.push("=", "\n");
119
+ str.push(buff.join(""));
120
+ }
121
+ while (p < pend) {
122
+ const type = fmt[p++];
123
+ if (/\s/.test(type))
124
+ continue;
125
+ if (type === "#") {
126
+ while (p < pend && fmt[p] !== "\n") {
127
+ p++;
128
+ }
129
+ continue;
130
+ }
131
+ switch (type) {
132
+ case "U":
133
+ if (encInfo === 1)
134
+ encInfo = 2;
135
+ break;
136
+ case "m":
137
+ case "M":
138
+ case "u":
139
+ break;
140
+ default:
141
+ encInfo = 0;
142
+ break;
143
+ }
144
+ let explicitEndian = "";
145
+ while (fmt[p] === "<" || fmt[p] === ">") {
146
+ if (!endstr.includes(type)) {
147
+ throw new ArgumentError(`'${fmt[p]}' allowed only after types ${endstr}`);
148
+ }
149
+ if (explicitEndian)
150
+ throw new RangeError("Can't use both '<' and '>'");
151
+ explicitEndian = fmt[p++];
152
+ }
153
+ let len;
154
+ if (fmt[p] === "*") {
155
+ len = "@Xxu".includes(type) ? 0 : "PMm".includes(type) ? 1 : ary.length - idx;
156
+ p++;
157
+ }
158
+ else if (fmt[p] >= "0" && fmt[p] <= "9") {
159
+ let digits = "";
160
+ while (fmt[p] >= "0" && fmt[p] <= "9")
161
+ digits += fmt[p++];
162
+ len = Number(digits);
163
+ }
164
+ else {
165
+ len = 1;
166
+ }
167
+ if (type === "U") {
168
+ while (len-- > 0) {
169
+ const from = nextfrom();
170
+ if (typeof from !== "number") {
171
+ throw new TypeError(`no implicit conversion of ${rbBuiltinClassName(from)} into Integer`);
172
+ }
173
+ const l = Math.trunc(from);
174
+ if (l < 0) {
175
+ throw new RangeError("pack(U): value out of range");
176
+ }
177
+ res.push(String.fromCodePoint(l));
178
+ }
179
+ continue;
180
+ }
181
+ if (type === "C" ||
182
+ type === "l" ||
183
+ type === "L" ||
184
+ type === "q" ||
185
+ type === "Q" ||
186
+ type === "S" ||
187
+ type === "v") {
188
+ const integerSize = type === "C" ? 1 : type === "v" || type === "S" ? 2 : type === "q" || type === "Q" ? 8 : 4;
189
+ const bigendianP = type === "v" ? false : explicitEndian ? explicitEndian === ">" : BIGENDIAN_P;
190
+ while (len-- > 0) {
191
+ const from = nextfrom();
192
+ if (typeof from !== "number" && typeof from !== "bigint") {
193
+ throw new TypeError(`no implicit conversion of ${rbBuiltinClassName(from)} into Integer`);
194
+ }
195
+ let v = BigInt.asUintN(integerSize * 8, BigInt(typeof from === "number" ? Math.trunc(from) : from));
196
+ const intbuf = [];
197
+ for (let i = 0; i < integerSize; i++, v >>= 8n)
198
+ intbuf.push(String.fromCharCode(Number(v & 0xffn)));
199
+ res.push((bigendianP ? intbuf.reverse() : intbuf).join(""));
200
+ }
201
+ continue;
202
+ }
203
+ if (type === "E") {
204
+ while (len-- > 0) {
205
+ const from = nextfrom();
206
+ if (typeof from !== "number" && typeof from !== "bigint") {
207
+ throw new TypeError(`can't convert ${rbBuiltinClassName(from)} into Float`);
208
+ }
209
+ const tmp = new DataView(new ArrayBuffer(8));
210
+ tmp.setFloat64(0, Number(from), true);
211
+ for (let i = 0; i < 8; i++)
212
+ res.push(String.fromCharCode(tmp.getUint8(i)));
213
+ }
214
+ continue;
215
+ }
216
+ if (type === "@") {
217
+ const str = res.join("");
218
+ len -= str.length;
219
+ res.length = 0;
220
+ res.push(len > 0 ? str + "\0".repeat(len) : str.slice(0, str.length + len));
221
+ continue;
222
+ }
223
+ if (type === "M") {
224
+ const from = nextfrom();
225
+ if (len <= 1)
226
+ len = 72;
227
+ qpencode(res, from instanceof Uint8Array ? from : b(String(from)), len);
228
+ continue;
229
+ }
230
+ if (type !== "m" && type !== "u")
231
+ unknownDirective("pack", type, fmt);
232
+ const from = nextfrom();
233
+ let s;
234
+ if (from instanceof Uint8Array)
235
+ s = from;
236
+ else
237
+ s = b(from);
238
+ let ptr = 0;
239
+ let plen = s.length;
240
+ if (len === 0 && type === "m") {
241
+ encodes(res, s.subarray(ptr), plen, type, 0);
242
+ continue;
243
+ }
244
+ if (len <= 2)
245
+ len = 45;
246
+ else if (len > 63 && type === "u")
247
+ len = 63;
248
+ else
249
+ len = Math.floor(len / 3) * 3;
250
+ while (plen > 0) {
251
+ const todo = plen > len ? len : plen;
252
+ encodes(res, s.subarray(ptr), todo, type, 1);
253
+ plen -= todo;
254
+ ptr += todo;
255
+ }
256
+ }
257
+ const str = res.join("");
258
+ if (encInfo !== 0)
259
+ return str;
260
+ return Uint8Array.from(str, (c) => c.charCodeAt(0));
261
+ }
262
+ /**
263
+ * `rb_ary_fetch` (`vendor/ruby/v3.3.11/array.c:1961`) in its one-argument form:
264
+ * a negative index counts from the end, and one outside the array raises
265
+ * `IndexError` (`array.c:1981`).
266
+ *
267
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#fetch`.
268
+ */
269
+ export function rbAryFetch(ary, pos) {
270
+ let idx = pos;
271
+ if (idx < 0)
272
+ idx += ary.length;
273
+ if (idx < 0 || ary.length <= idx) {
274
+ throw new IndexError(`index ${idx - (idx < 0 ? ary.length : 0)} outside of array bounds: ${-ary.length}...${ary.length}`);
275
+ }
276
+ return ary[idx];
277
+ }
278
+ /**
279
+ * `rb_ary_bsearch_index` (`vendor/ruby/v3.3.11/array.c:3513`): the find-minimum
280
+ * mode for a `true`/`false`/`nil` block, and the find-any mode for a numeric one.
281
+ *
282
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#bsearch_index`.
283
+ */
284
+ export function rbAryBsearchIndex(ary, block) {
285
+ let low = 0;
286
+ let high = ary.length;
287
+ let smaller;
288
+ let satisfied = false;
289
+ while (low < high) {
290
+ const mid = low + Math.floor((high - low) / 2);
291
+ const v = block(ary[mid]);
292
+ if (typeof v === "number") {
293
+ if (v === 0)
294
+ return mid;
295
+ smaller = v < 0;
296
+ }
297
+ else if (v === true) {
298
+ satisfied = true;
299
+ smaller = true;
300
+ }
301
+ else if (v == null || v === false) {
302
+ smaller = false;
303
+ }
304
+ else {
305
+ throw new TypeError(`wrong argument type ${v.constructor.name} (must be numeric, true, false or nil)`);
306
+ }
307
+ if (smaller) {
308
+ high = mid;
309
+ }
310
+ else {
311
+ low = mid + 1;
312
+ }
313
+ }
314
+ if (!satisfied)
315
+ return null;
316
+ return low;
317
+ }
318
+ /**
319
+ * `rb_ary_bsearch` (`vendor/ruby/v3.3.11/array.c:3493`).
320
+ *
321
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#bsearch`.
322
+ */
323
+ export function rbAryBsearch(ary, block) {
324
+ const indexResult = rbAryBsearchIndex(ary, block);
325
+ if (indexResult != null)
326
+ return ary[indexResult];
327
+ return null;
328
+ }
329
+ /**
330
+ * `rb_ary_replace` (`vendor/ruby/v3.3.11/array.c:4531`): `copy`'s contents
331
+ * become `orig`'s, in place, and `copy` is returned.
332
+ *
333
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#replace`.
334
+ */
335
+ export function rbAryReplace(copy, orig) {
336
+ if (copy === orig)
337
+ return copy;
338
+ copy.splice(0, copy.length, ...orig);
339
+ return copy;
340
+ }
341
+ /**
342
+ * @noRailsEquivalent PERMANENT — Ruby core `String#unpack1`
343
+ * (`vendor/ruby/v3.3.11/pack.c:1621`).
344
+ */
345
+ export function unpack1(str, fmt, { offset = 0 } = {}) {
346
+ const ary = packUnpackInternal(str, fmt, UNPACK_1, offset);
347
+ return ary.length > 0 ? ary[0] : null;
348
+ }
349
+ /**
350
+ * `String#unpack` (`vendor/ruby/v3.3.11/pack.c:1611` `pack_unpack`):
351
+ * `pack_unpack_internal` in `UNPACK_ARRAY` mode, every item the format
352
+ * pushes. The directives are {@link unpack1}'s, plus `u` (`pack.c:1362`),
353
+ * `m` (`pack.c:1417`) and `M` (`pack.c:1498`), each pushing an ASCII-8BIT
354
+ * String, a `Uint8Array`.
355
+ *
356
+ * @noRailsEquivalent PERMANENT
357
+ */
358
+ export function unpack(str, fmt, { offset = 0 } = {}) {
359
+ return packUnpackInternal(str, fmt, UNPACK_ARRAY, offset);
360
+ }
361
+ const UNPACK_ARRAY = 0;
362
+ const UNPACK_1 = 2;
363
+ /** `pack_unpack_internal` (`vendor/ruby/v3.3.11/pack.c:936`). */
364
+ function packUnpackInternal(str, fmt, mode, offset) {
365
+ const ary = [];
366
+ if (offset < 0)
367
+ throw new ArgumentError("offset can't be negative");
368
+ const ptr = typeof str === "string" ? Uint8Array.from(str, (c) => c.charCodeAt(0) & 0xff) : str;
369
+ const send = ptr.length;
370
+ if (offset > send)
371
+ throw new ArgumentError("offset outside of string");
372
+ /**
373
+ * `hex2num` (`vendor/ruby/v3.3.11/pack.c:895`).
374
+ */
375
+ function hex2num(c) {
376
+ const n = parseInt(String.fromCharCode(c), 36);
377
+ return Number.isNaN(n) || n >= 16 ? -1 : n;
378
+ }
379
+ /** `utf8_to_uv` (`vendor/ruby/v3.3.11/pack.c:1684`). */
380
+ function utf8ToUv(ptr, p, lenp) {
381
+ const utf8Limits = [0x0, 0x80, 0x800, 0x10000, 0x200000, 0x4000000, 0x80000000];
382
+ let c = ptr[p++];
383
+ let uv = c;
384
+ let n;
385
+ if (!(uv & 0x80))
386
+ return [uv, 1];
387
+ if (!(uv & 0x40))
388
+ throw new ArgumentError("malformed UTF-8 character");
389
+ if (!(uv & 0x20)) {
390
+ n = 2;
391
+ uv &= 0x1f;
392
+ }
393
+ else if (!(uv & 0x10)) {
394
+ n = 3;
395
+ uv &= 0x0f;
396
+ }
397
+ else if (!(uv & 0x08)) {
398
+ n = 4;
399
+ uv &= 0x07;
400
+ }
401
+ else if (!(uv & 0x04)) {
402
+ n = 5;
403
+ uv &= 0x03;
404
+ }
405
+ else if (!(uv & 0x02)) {
406
+ n = 6;
407
+ uv &= 0x01;
408
+ }
409
+ else {
410
+ throw new ArgumentError("malformed UTF-8 character");
411
+ }
412
+ if (n > lenp) {
413
+ throw new ArgumentError(`malformed UTF-8 character (expected ${n} bytes, given ${lenp} bytes)`);
414
+ }
415
+ lenp = n--;
416
+ while (n--) {
417
+ c = ptr[p++];
418
+ if ((c & 0xc0) !== 0x80)
419
+ throw new ArgumentError("malformed UTF-8 character");
420
+ uv = uv * 64 + (c & 0x3f);
421
+ }
422
+ if (uv < utf8Limits[lenp - 1])
423
+ throw new ArgumentError("redundant UTF-8 sequence");
424
+ return [uv, lenp];
425
+ }
426
+ let s = offset;
427
+ let p = 0;
428
+ const pend = fmt.length;
429
+ while (p < pend) {
430
+ let explicitEndian = "";
431
+ const type = fmt[p++];
432
+ if (/\s/.test(type))
433
+ continue;
434
+ if (type === "#") {
435
+ while (p < pend && fmt[p] !== "\n") {
436
+ p++;
437
+ }
438
+ continue;
439
+ }
440
+ while (fmt[p] === "<" || fmt[p] === ">") {
441
+ if (!endstr.includes(type)) {
442
+ throw new ArgumentError(`'${fmt[p]}' allowed only after types ${endstr}`);
443
+ }
444
+ if (explicitEndian)
445
+ throw new RangeError("Can't use both '<' and '>'");
446
+ explicitEndian = fmt[p++];
447
+ }
448
+ let len;
449
+ if (p >= pend) {
450
+ len = 1;
451
+ }
452
+ else if (fmt[p] === "*") {
453
+ len = send - s;
454
+ p++;
455
+ }
456
+ else if (fmt[p] >= "0" && fmt[p] <= "9") {
457
+ let digits = "";
458
+ while (fmt[p] >= "0" && fmt[p] <= "9")
459
+ digits += fmt[p++];
460
+ len = Number(digits);
461
+ }
462
+ else {
463
+ len = type !== "@" ? 1 : 0;
464
+ }
465
+ if (type === "C" ||
466
+ type === "l" ||
467
+ type === "L" ||
468
+ type === "q" ||
469
+ type === "Q" ||
470
+ type === "S" ||
471
+ type === "v") {
472
+ const signedP = type === "l" || type === "q";
473
+ const integerSize = type === "C" ? 1 : type === "v" || type === "S" ? 2 : type === "q" || type === "Q" ? 8 : 4;
474
+ const bigendianP = type === "v" ? false : explicitEndian ? explicitEndian === ">" : BIGENDIAN_P;
475
+ if (len > Math.floor((send - s) / integerSize))
476
+ len = Math.floor((send - s) / integerSize);
477
+ while (len-- > 0) {
478
+ let val = 0n;
479
+ for (let i = 0; i < integerSize; i++) {
480
+ const byte = BigInt(ptr[bigendianP ? s + i : s + integerSize - 1 - i]);
481
+ val = (val << 8n) | byte;
482
+ }
483
+ ary.push(rbBigNorm(signedP ? BigInt.asIntN(integerSize * 8, val) : val));
484
+ if (mode === UNPACK_1)
485
+ return ary;
486
+ s += integerSize;
487
+ }
488
+ continue;
489
+ }
490
+ if (type === "E") {
491
+ if (len > Math.floor((send - s) / 8))
492
+ len = Math.floor((send - s) / 8);
493
+ while (len-- > 0) {
494
+ const tmp = new DataView(new ArrayBuffer(8));
495
+ for (let i = 0; i < 8; i++)
496
+ tmp.setUint8(i, ptr[s + i]);
497
+ ary.push(tmp.getFloat64(0, true));
498
+ if (mode === UNPACK_1)
499
+ return ary;
500
+ s += 8;
501
+ }
502
+ continue;
503
+ }
504
+ if (type === "h") {
505
+ if (fmt[p - 1] === "*" || len > (send - s) * 2)
506
+ len = (send - s) * 2;
507
+ let bits = 0;
508
+ let bitstr = "";
509
+ for (let i = 0; i < len; i++) {
510
+ if (i & 1)
511
+ bits >>= 4;
512
+ else
513
+ bits = ptr[s++];
514
+ bitstr += "0123456789abcdef"[bits & 15];
515
+ }
516
+ ary.push(bitstr);
517
+ if (mode === UNPACK_1)
518
+ return ary;
519
+ continue;
520
+ }
521
+ if (type === "H") {
522
+ if (fmt[p - 1] === "*" || len > (send - s) * 2)
523
+ len = (send - s) * 2;
524
+ let bits = 0;
525
+ let bitstr = "";
526
+ for (let i = 0; i < len; i++) {
527
+ if (i & 1)
528
+ bits <<= 4;
529
+ else
530
+ bits = ptr[s++];
531
+ bitstr += "0123456789abcdef"[(bits >> 4) & 15];
532
+ }
533
+ ary.push(bitstr);
534
+ if (mode === UNPACK_1)
535
+ return ary;
536
+ continue;
537
+ }
538
+ if (type === "@") {
539
+ if (len > send)
540
+ throw new ArgumentError("@ outside of string");
541
+ s = len;
542
+ continue;
543
+ }
544
+ if (type === "U") {
545
+ if (len > send - s)
546
+ len = send - s;
547
+ while (len > 0 && s < send) {
548
+ const [l, alen] = utf8ToUv(ptr, s, send - s);
549
+ s += alen;
550
+ len--;
551
+ ary.push(l);
552
+ if (mode === UNPACK_1)
553
+ return ary;
554
+ }
555
+ continue;
556
+ }
557
+ if (type === "u") {
558
+ const buf = new Uint8Array(Math.floor(((send - s) * 3) / 4));
559
+ let optr = 0;
560
+ let total = 0;
561
+ const uuChar = () => s < send && ptr[s] >= 0x20 && ptr[s] < 0x61 ? (ptr[s++] - 0x20) & 0o77 : 0;
562
+ while (s < send && ptr[s] > 0x20 && ptr[s] < 0x61) {
563
+ let n = (ptr[s++] - 0x20) & 0o77;
564
+ total += n;
565
+ if (total > buf.length) {
566
+ n -= total - buf.length;
567
+ total = buf.length;
568
+ }
569
+ while (n > 0) {
570
+ const mlen = n > 3 ? 3 : n;
571
+ const a = uuChar();
572
+ const bb = uuChar();
573
+ const c = uuChar();
574
+ const d = uuChar();
575
+ const hunk = [(a << 2) | (bb >> 4), (bb << 4) | (c >> 2), (c << 6) | d];
576
+ for (let i = 0; i < mlen; i++)
577
+ buf[optr++] = hunk[i] & 0xff;
578
+ n -= mlen;
579
+ }
580
+ if (s < send && ptr[s] !== 0x0d && ptr[s] !== 0x0a)
581
+ s++;
582
+ if (s < send && ptr[s] === 0x0d)
583
+ s++;
584
+ if (s < send && ptr[s] === 0x0a)
585
+ s++;
586
+ }
587
+ ary.push(buf.slice(0, total));
588
+ if (mode === UNPACK_1)
589
+ return ary;
590
+ continue;
591
+ }
592
+ if (type === "m") {
593
+ let src = "";
594
+ for (let i = s; i < send; i++)
595
+ src += String.fromCharCode(ptr[i]);
596
+ const decoded = len === 0 ? Base64.strictDecode64(src) : Base64.decode64(src);
597
+ ary.push(Uint8Array.from(decoded, (c) => c.charCodeAt(0)));
598
+ s = send;
599
+ if (mode === UNPACK_1)
600
+ return ary;
601
+ continue;
602
+ }
603
+ if (type === "M") {
604
+ const buf = [];
605
+ let ss = s;
606
+ while (s < send) {
607
+ if (ptr[s] === 0x3d) {
608
+ if (++s === send)
609
+ break;
610
+ if (s + 1 < send && ptr[s] === 0x0d && ptr[s + 1] === 0x0a)
611
+ s++;
612
+ if (ptr[s] !== 0x0a) {
613
+ const c1 = hex2num(ptr[s]);
614
+ if (c1 === -1)
615
+ break;
616
+ if (++s === send)
617
+ break;
618
+ const c2 = hex2num(ptr[s]);
619
+ if (c2 === -1)
620
+ break;
621
+ buf.push((c1 << 4) | c2);
622
+ }
623
+ }
624
+ else {
625
+ buf.push(ptr[s]);
626
+ }
627
+ s++;
628
+ ss = s;
629
+ }
630
+ ary.push(Uint8Array.from([...buf, ...ptr.subarray(ss, send)]));
631
+ s = send;
632
+ if (mode === UNPACK_1)
633
+ return ary;
634
+ continue;
635
+ }
636
+ unknownDirective("unpack", type, fmt);
637
+ }
638
+ return ary;
639
+ }
640
+ /**
641
+ * Ruby `Array#slice` / `Array#[]` (`vendor/ruby/v3.3.11/array.c:1827` `rb_ary_aref`):
642
+ * `(index)` answers the element or nil, `(start, length)` a subarray
643
+ * (`rb_ary_aref2`, `:1837`), and a Range a subarray through
644
+ * `rb_range_beg_len` (`vendor/ruby/v3.3.11/range.c:1744`); an out-of-range start is nil.
645
+ * @noRailsEquivalent PERMANENT
646
+ */
647
+ export function arySlice(ary, arg, length) {
648
+ const argc = arguments.length - 1;
649
+ if (argc < 1 || argc > 2) {
650
+ throw new ArgumentError(`wrong number of arguments (given ${argc}, expected 1..2)`);
651
+ }
652
+ const alen = ary.length;
653
+ if (argc === 2) {
654
+ let beg = num2long(arg);
655
+ const len = num2long(length);
656
+ if (beg < 0)
657
+ beg += alen;
658
+ return subseq(ary, beg, len);
659
+ }
660
+ if (arg instanceof Range) {
661
+ let beg = arg.begin ?? 0;
662
+ let end = arg.end ?? alen;
663
+ if (beg < 0) {
664
+ beg += alen;
665
+ if (beg < 0)
666
+ return null;
667
+ }
668
+ if (end < 0)
669
+ end += alen;
670
+ if (arg.end !== null && !arg.excludeEnd)
671
+ end += 1;
672
+ return subseq(ary, beg, Math.max(0, end - beg));
673
+ }
674
+ const offset = num2long(arg);
675
+ const index = offset < 0 ? offset + alen : offset;
676
+ return index >= 0 && index < alen ? ary[index] : null;
677
+ }
678
+ function subseq(ary, beg, len) {
679
+ if (beg > ary.length || beg < 0 || len < 0)
680
+ return null;
681
+ return ary.slice(beg, beg + len);
682
+ }
683
+ /**
684
+ * Mirrors: Ruby's Array#sort_by! — `vendor/ruby/v3.3.11/array.c:3593`
685
+ * `rb_ary_sort_by_bang`, which replaces the receiver's elements with
686
+ * `sort_by`'s result and answers the receiver.
687
+ *
688
+ * @noRailsEquivalent PERMANENT
689
+ */
690
+ export function sortByBang(ary, block) {
691
+ const sorted = sortBy(ary, block);
692
+ ary.splice(0, ary.length, ...sorted);
693
+ return ary;
694
+ }
695
+ /**
696
+ * Ruby `Array#delete_if` (`vendor/ruby/v3.3.11/array.c:4330` `rb_ary_delete_if`):
697
+ * removes, in place, every element the block answers truthily for
698
+ * (`reject_bang_i`, `array.c:4225`) and answers the receiver. When the block
699
+ * raises, the elements not yet visited are kept after the ones already
700
+ * retained (`select_bang_ensure`, `array.c:3841`).
701
+ *
702
+ * @noRailsEquivalent PERMANENT
703
+ */
704
+ export function aryDeleteIf(ary, block) {
705
+ let i1 = 0;
706
+ let i2 = 0;
707
+ try {
708
+ for (; i1 < ary.length; i1++) {
709
+ const v = ary[i1];
710
+ const result = block(v);
711
+ if (result != null && result !== false)
712
+ continue;
713
+ if (i1 !== i2) {
714
+ ary[i2] = v;
715
+ }
716
+ i2++;
717
+ }
718
+ }
719
+ finally {
720
+ const len = ary.length;
721
+ if (i2 < len && i2 < i1) {
722
+ let tail = 0;
723
+ if (i1 < len) {
724
+ tail = len - i1;
725
+ ary.copyWithin(i2, i1, len);
726
+ }
727
+ ary.length = i2 + tail;
728
+ }
729
+ }
730
+ return ary;
731
+ }
732
+ /**
733
+ * Ruby `Array#delete` (`vendor/ruby/v3.3.11/array.c:3973` `rb_ary_delete`): removes, in
734
+ * place, every element `==` to `item` (`rb_equal`, so a record matches by
735
+ * `ActiveRecord::Core#==`, not identity) and answers the last one removed.
736
+ * When nothing matched it answers the block's value for `item`, or nil.
737
+ *
738
+ * @noRailsEquivalent PERMANENT
739
+ */
740
+ export function aryDelete(ary, item, block) {
741
+ let v = item;
742
+ let i2 = 0;
743
+ for (let i1 = 0; i1 < ary.length; i1++) {
744
+ const e = ary[i1];
745
+ if (rbEqual(e, item)) {
746
+ v = e;
747
+ continue;
748
+ }
749
+ if (i1 !== i2) {
750
+ ary[i2] = e;
751
+ }
752
+ i2++;
753
+ }
754
+ if (ary.length === i2) {
755
+ if (block) {
756
+ return block(item);
757
+ }
758
+ return undefined;
759
+ }
760
+ ary.length = i2;
761
+ return v;
762
+ }
763
+ /**
764
+ * Ruby `Array#delete_at` (`vendor/ruby/v3.3.11/array.c:4072` `rb_ary_delete_at_m`,
765
+ * over `rb_ary_delete_at`, `array.c:4027`): removes, in place, the element at
766
+ * `pos` and answers it. A negative `pos` counts back from the end, and one out
767
+ * of range either way answers `nil` and leaves the array alone.
768
+ *
769
+ * @noRailsEquivalent PERMANENT
770
+ */
771
+ export function deleteAt(ary, pos) {
772
+ pos = num2long(pos);
773
+ const len = ary.length;
774
+ if (pos >= len)
775
+ return null;
776
+ if (pos < 0) {
777
+ pos += len;
778
+ if (pos < 0)
779
+ return null;
780
+ }
781
+ const del = ary[pos];
782
+ ary.splice(pos, 1);
783
+ return del;
784
+ }
785
+ /**
786
+ * Ruby `Array#first(n)` (`ary_take_first_or_last_n`,
787
+ * `vendor/ruby/v3.3.11/array.c:1292`): at most `n` elements, and
788
+ * `ArgumentError` for a negative `n`.
789
+ *
790
+ * @noRailsEquivalent PERMANENT
791
+ */
792
+ export function rbAryFirst(ary, n) {
793
+ if (n < 0)
794
+ throw new ArgumentError("negative array size");
795
+ return ary.slice(0, n);
796
+ }
797
+ /**
798
+ * Ruby `Array#first` with no argument (`vendor/ruby/v3.3.11/array.c:1901` `ary_first`):
799
+ * the first element, or `nil` for an empty array. Any other enumerable is
800
+ * `Enumerable#first` (`vendor/ruby/v3.3.11/enum.c:1284` `enum_first`), whose
801
+ * `first_i` (`enum.c:1245`) breaks out of `each` at the first element. A
802
+ * receiver that is neither answers its own `first` (`rb_funcallv`,
803
+ * `vendor/ruby/v3.3.11/vm_eval.c:1080`), a method called or a reader read, or raises `NoMethodError` (`rb_method_missing`,
804
+ * `vendor/ruby/v3.3.11/vm_eval.c:869`).
805
+ *
806
+ * @noRailsEquivalent PERMANENT
807
+ */
808
+ export function first(ary) {
809
+ if (Array.isArray(ary))
810
+ return ary.length === 0 ? null : ary[0];
811
+ if (typeof ary?.[Symbol.iterator] !== "function") {
812
+ const member = ary?.first;
813
+ if (member !== undefined)
814
+ return (typeof member === "function" ? member.call(ary) : member);
815
+ throw new NoMethodError(ary == null
816
+ ? "undefined method 'first' for nil"
817
+ : `undefined method 'first' for an instance of ${rbObjClassname(ary)}`);
818
+ }
819
+ for (const i of ary) {
820
+ return i;
821
+ }
822
+ return null;
823
+ }
824
+ /** @noRailsEquivalent PERMANENT — Ruby core `Array#last` (`vendor/ruby/v3.3.11/array.c:1914`). */
825
+ export function last(ary, n) {
826
+ if (!Array.isArray(ary)) {
827
+ const member = ary?.last;
828
+ if (member === undefined) {
829
+ throw new NoMethodError(ary == null
830
+ ? "undefined method 'last' for nil"
831
+ : `undefined method 'last' for an instance of ${rbObjClassname(ary)}`);
832
+ }
833
+ return (typeof member === "function" ? member.call(ary, ...(n === undefined ? [] : [n])) : member);
834
+ }
835
+ const len = ary.length;
836
+ if (n === undefined)
837
+ return len === 0 ? null : ary[len - 1];
838
+ n = num2long(n);
839
+ if (n > len) {
840
+ n = len;
841
+ }
842
+ else if (n < 0) {
843
+ throw new ArgumentError("negative array size");
844
+ }
845
+ return ary.slice(len - n);
846
+ }
847
+ /**
848
+ * Ruby `Array#count` (`vendor/ruby/v3.3.11/array.c:6275` `rb_ary_count`): the number
849
+ * of elements the block answers truthily for (`RTEST`), or the length with no
850
+ * block. The `count(obj)` arm is not ported: nothing calls it.
851
+ *
852
+ * @noRailsEquivalent PERMANENT
853
+ */
854
+ export function aryCount(ary, block) {
855
+ if (!block)
856
+ return ary.length;
857
+ let n = 0;
858
+ for (const v of ary) {
859
+ const result = block(v);
860
+ if (result != null && result !== false)
861
+ n++;
862
+ }
863
+ return n;
864
+ }
865
+ /**
866
+ * Ruby `Array#reject` (`vendor/ruby/v3.3.11/array.c:4301` `rb_ary_reject`): a new
867
+ * array of the elements the block does not answer truthily for (`RTEST`,
868
+ * `ary_reject`, `:4210`). Each block result is awaited before the next element
869
+ * is yielded, so a block that awaits still runs in order, one at a time. The
870
+ * block-less enumerator arm is not ported: nothing calls it.
871
+ *
872
+ * @noRailsEquivalent PERMANENT
873
+ */
874
+ export async function aryReject(ary, block) {
875
+ const result = [];
876
+ for (const v of ary) {
877
+ const yielded = await block(v);
878
+ if (yielded == null || yielded === false)
879
+ result.push(v);
880
+ }
881
+ return result;
882
+ }
883
+ /**
884
+ * Ruby `Array#each` (`vendor/ruby/v3.3.11/array.c:2532` `rb_ary_each`): yields each
885
+ * element and returns the receiver. With no block it is
886
+ * `RETURN_SIZED_ENUMERATOR` (`:2535`), whose elements are the receiver's. A `Set`
887
+ * yields its members, and a `Map` or plain Hash its `[key, value]` pairs, as
888
+ * `rb_hash_each_pair` does (`vendor/ruby/v3.3.11/hash.c`).
889
+ *
890
+ * @noRailsEquivalent PERMANENT
891
+ */
892
+ export function each(recv, block) {
893
+ if (!block)
894
+ return recv;
895
+ const yielder = block;
896
+ const own = recv.each;
897
+ if (!isPlainHash(recv) && typeof own === "function")
898
+ return own.call(recv, yielder);
899
+ for (const i of isPlainHash(recv) ? Object.entries(recv) : recv) {
900
+ yielder(i);
901
+ }
902
+ return recv;
903
+ }
904
+ /** @noRailsEquivalent PERMANENT — Ruby core `rb_ary_to_h` (`vendor/ruby/v3.3.11/array.c:2988`). */
905
+ export function toH(ary, block) {
906
+ if (!Array.isArray(ary)) {
907
+ if (typeof ary.toH === "function") {
908
+ return ary.toH();
909
+ }
910
+ return ary;
911
+ }
912
+ const hash = new Hash();
913
+ for (let i = 0; i < ary.length; i++) {
914
+ const e = ary[i];
915
+ const keyValuePair = block ? block(e) : e;
916
+ if (!Array.isArray(keyValuePair)) {
917
+ throw new TypeError(`wrong element type ${rbBuiltinClassName(keyValuePair)} at ${i} (expected array)`);
918
+ }
919
+ if (keyValuePair.length !== 2) {
920
+ throw new ArgumentError(`wrong array length at ${i} (expected 2, was ${keyValuePair.length})`);
921
+ }
922
+ hash.set(keyValuePair[0], keyValuePair[1]);
923
+ }
924
+ return hash;
925
+ }
926
+ /** @noRailsEquivalent PERMANENT — Ruby core `rb_ary_to_a` (`vendor/ruby/v3.3.11/array.c:2952`). */
927
+ export function toA(ary) {
928
+ if (isPlainHash(ary))
929
+ return Object.entries(ary);
930
+ if (!Array.isArray(ary))
931
+ return [...ary];
932
+ if (ary.constructor !== Array) {
933
+ const dup = [];
934
+ dup.push(...ary);
935
+ return dup;
936
+ }
937
+ return ary;
938
+ }
939
+ /**
940
+ * Ruby `Array#take` (`vendor/ruby/v3.3.11/array.c:7532` `rb_ary_take`): the first `n` elements.
941
+ * @noRailsEquivalent PERMANENT
942
+ */
943
+ export function take(ary, n) {
944
+ const len = num2long(n);
945
+ if (len < 0)
946
+ throw new ArgumentError("attempt to take negative size");
947
+ return ary.slice(0, len);
948
+ }
949
+ /**
950
+ * Ruby `Array#compact` (`vendor/ruby/v3.3.11/array.c:6240` `rb_ary_compact`): a new
951
+ * array with every `nil` element removed.
952
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#compact`
953
+ * (`vendor/ruby/v3.3.11/array.c:6240`).
954
+ */
955
+ export function compact(ary) {
956
+ return ary.filter((element) => element != null);
957
+ }
958
+ /**
959
+ * Ruby `Array#compact!` (`vendor/ruby/v3.3.11/array.c:6207` `rb_ary_compact_bang`):
960
+ * removes every `nil` element in place, answering the array, or `nil` when
961
+ * none was removed.
962
+ *
963
+ * @noRailsEquivalent PERMANENT
964
+ */
965
+ export function compactBang(ary) {
966
+ let p = 0;
967
+ for (let t = 0; t < ary.length; t++) {
968
+ if (ary[t] != null)
969
+ ary[p++] = ary[t];
970
+ }
971
+ if (ary.length === p)
972
+ return null;
973
+ ary.length = p;
974
+ return ary;
975
+ }
976
+ /**
977
+ * `rb_check_array_type` (`vendor/ruby/v3.3.11/array.c:975`, over
978
+ * `rb_check_convert_type_with_id`, `vendor/ruby/v3.3.11/object.c:3184`): an
979
+ * Array, its `to_ary`, or nil. A `to_ary` answering anything else raises.
980
+ *
981
+ * @noRailsEquivalent PERMANENT
982
+ */
983
+ export function rbCheckArrayType(ary) {
984
+ if (Array.isArray(ary))
985
+ return ary;
986
+ const toAry = ary?.toAry;
987
+ if (typeof toAry !== "function")
988
+ return null;
989
+ const v = toAry.call(ary);
990
+ if (v == null)
991
+ return null;
992
+ if (!Array.isArray(v))
993
+ conversionMismatch(ary, "Array", "to_ary", v);
994
+ return v;
995
+ }
996
+ /** `rb_check_to_array` (`vendor/ruby/v3.3.11/array.c:981`): the receiver's `to_a`, or nil. */
997
+ function rbCheckToArray(ary) {
998
+ if (ary == null)
999
+ return [];
1000
+ if (ary instanceof Map)
1001
+ return [...ary.entries()];
1002
+ if (ary instanceof Set)
1003
+ return [...ary.values()];
1004
+ if (typeof ary !== "object")
1005
+ return null;
1006
+ const toA = ary.toA;
1007
+ if (typeof toA === "function") {
1008
+ const v = toA.call(ary);
1009
+ if (v == null)
1010
+ return null;
1011
+ if (!Array.isArray(v))
1012
+ conversionMismatch(ary, "Array", "to_a", v);
1013
+ return v;
1014
+ }
1015
+ const proto = Object.getPrototypeOf(ary);
1016
+ if (proto === Object.prototype || proto === null)
1017
+ return Object.entries(ary);
1018
+ return null;
1019
+ }
1020
+ /**
1021
+ * `Kernel#Array` (`rb_f_array`, `vendor/ruby/v3.3.11/object.c:3825`, over
1022
+ * `rb_Array`, `vendor/ruby/v3.3.11/object.c:3791`): the
1023
+ * argument's `to_ary`, else its `to_a`, else the argument in a one-element
1024
+ * Array.
1025
+ *
1026
+ * @noRailsEquivalent PERMANENT
1027
+ */
1028
+ export function rbFArray(val) {
1029
+ let tmp = rbCheckArrayType(val);
1030
+ if (tmp === null) {
1031
+ tmp = rbCheckToArray(val);
1032
+ if (tmp === null) {
1033
+ return [val];
1034
+ }
1035
+ }
1036
+ return tmp;
1037
+ }
1038
+ /**
1039
+ * Ruby `Array#flatten` with no level (`vendor/ruby/v3.3.11/array.c:6476`
1040
+ * `rb_ary_flatten`, over `flatten`, `array.c:6305`): every element that
1041
+ * answers {@link rbCheckArrayType} is replaced by its own flattened elements,
1042
+ * and an array reached again on its own path raises.
1043
+ *
1044
+ * @noRailsEquivalent PERMANENT
1045
+ */
1046
+ export function flatten(ary) {
1047
+ const result = [];
1048
+ const memo = new Set([ary]);
1049
+ const walk = (level) => {
1050
+ for (const elt of level) {
1051
+ const tmp = rbCheckArrayType(elt);
1052
+ if (tmp === null) {
1053
+ result.push(elt);
1054
+ continue;
1055
+ }
1056
+ if (memo.has(tmp))
1057
+ throw new ArgumentError("tried to flatten recursive array");
1058
+ memo.add(tmp);
1059
+ walk(tmp);
1060
+ memo.delete(tmp);
1061
+ }
1062
+ };
1063
+ walk(ary);
1064
+ return result;
1065
+ }
1066
+ /**
1067
+ * Ruby `Array#uniq` (`vendor/ruby/v3.3.11/array.c:6177` `rb_ary_uniq`): the elements in
1068
+ * order, deduplicated through `ary_make_hash` (`array.c:5342`) — a Hash, so it
1069
+ * keys on `hash`/`eql?`, never `==` or identity: `1` and `1n` collapse the way
1070
+ * Ruby's `1` and `1` do, a tuple is `eql?` by its elements, and a value whose
1071
+ * class defines only `==` stays distinct. With a block, each element is keyed
1072
+ * on the block's result (`ary_make_hash_by`, `array.c:5361`) and the first
1073
+ * element for each key is kept.
1074
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#uniq`
1075
+ * (`vendor/ruby/v3.3.11/array.c:6177`).
1076
+ */
1077
+ export function uniq(ary, block) {
1078
+ const hash = new Map();
1079
+ const result = [];
1080
+ for (const element of ary) {
1081
+ const k = block ? block(element) : element;
1082
+ const key = rbHash(k);
1083
+ const bucket = hash.get(key) ?? [];
1084
+ if (bucket.some((seen) => rbEql(seen, k)))
1085
+ continue;
1086
+ bucket.push(k);
1087
+ hash.set(key, bucket);
1088
+ result.push(element);
1089
+ }
1090
+ return result;
1091
+ }
1092
+ /**
1093
+ * Ruby `Array#uniq!` (`vendor/ruby/v3.3.11/array.c:6124` `rb_ary_uniq_bang`):
1094
+ * deduplicates in place as {@link uniq} does, answering the array, or `nil`
1095
+ * when nothing was removed.
1096
+ *
1097
+ * @noRailsEquivalent PERMANENT
1098
+ */
1099
+ export function uniqBang(ary, block) {
1100
+ const result = uniq(ary, block);
1101
+ if (ary.length === result.length)
1102
+ return null;
1103
+ ary.splice(0, ary.length, ...result);
1104
+ return ary;
1105
+ }
1106
+ /**
1107
+ * Ruby `Array#include?` (`vendor/ruby/v3.3.11/array.c:5222` `rb_ary_includes`):
1108
+ * whether an element is `==` to `item`. Each element is the receiver of the
1109
+ * `rb_equal` send, so a class's own `==` answers where a JS `includes`
1110
+ * compares identity.
1111
+ *
1112
+ * @noRailsEquivalent PERMANENT
1113
+ */
1114
+ export function aryIncludes(ary, item) {
1115
+ for (let i = 0; i < ary.length; i++) {
1116
+ const e = ary[i];
1117
+ if (rbEqual(e, item)) {
1118
+ return true;
1119
+ }
1120
+ }
1121
+ return false;
1122
+ }
1123
+ /**
1124
+ * Ruby `Array#|` (`vendor/ruby/v3.3.11/array.c:5600` `rb_ary_or`): `ary1`'s
1125
+ * elements then `ary2`'s, deduplicated across both the way `uniq` is — by
1126
+ * `hash`/`eql?` (`rb_ary_union`, `array.c:5562`), so two separately built
1127
+ * `eql?` tuples or Hashes collapse where a JS `includes` would keep both.
1128
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#|`
1129
+ * (`vendor/ruby/v3.3.11/array.c:5600`).
1130
+ */
1131
+ export function union(ary1, ary2) {
1132
+ return uniq([...ary1, ...ary2]);
1133
+ }
1134
+ /**
1135
+ * Ruby `Array#product` (`vendor/ruby/v3.3.11/array.c:7426` `rb_ary_product`), the
1136
+ * block-less form: every combination taking one element from `ary` and one from
1137
+ * each of `args`, the last array varying fastest.
1138
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#product`.
1139
+ */
1140
+ export function product(ary, ...args) {
1141
+ let result = ary.map((e) => [e]);
1142
+ for (const other of args) {
1143
+ result = result.flatMap((combo) => other.map((e) => [...combo, e]));
1144
+ }
1145
+ return result;
1146
+ }
1147
+ /**
1148
+ * Ruby `Array#intersect?` (`vendor/ruby/v3.3.11/array.c:5680` `rb_ary_intersect_p`):
1149
+ * whether the two arrays share an element, compared by `eql?` as
1150
+ * `rb_ary_includes_by_eql` does. An empty array on either side answers false.
1151
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#intersect?`
1152
+ * (`vendor/ruby/v3.3.11/array.c:5680`).
1153
+ */
1154
+ export function isIntersect(ary1, ary2) {
1155
+ if (ary1.length === 0 || ary2.length === 0)
1156
+ return false;
1157
+ for (const v of ary1) {
1158
+ if (ary2.some((e) => rbEql(e, v)))
1159
+ return true;
1160
+ }
1161
+ return false;
1162
+ }
1163
+ /**
1164
+ * Ruby `Array#sort` without a block (`vendor/ruby/v3.3.11/array.c:3473` `rb_ary_sort`):
1165
+ * a sorted copy, ordered by `sort_2` (`array.c:3301`), which sends `<=>` and
1166
+ * hands the answer to `rb_cmpint`, so a `nil` `<=>` raises
1167
+ * `ArgumentError: comparison of A with B failed`.
1168
+ *
1169
+ * @boundary: `ruby_qsort` (`vendor/ruby/v3.3.11/util.c:253`) is the platform `qsort_s`,
1170
+ * glibc's merge sort, which always passes the earlier element first. V8's
1171
+ * `Array#sort` does not, and the order names the classes in the message, so
1172
+ * the merge is written out.
1173
+ *
1174
+ * @noRailsEquivalent PERMANENT — Ruby core `Array#sort` (`vendor/ruby/v3.3.11/array.c:3473`).
1175
+ */
1176
+ export function sort(ary) {
1177
+ const sort2 = (a, b) => rbCmpint(cmp(a, b), a, b);
1178
+ const msort = (b) => {
1179
+ if (b.length <= 1)
1180
+ return b;
1181
+ const n1 = b.length >> 1;
1182
+ const b1 = msort(b.slice(0, n1));
1183
+ const b2 = msort(b.slice(n1));
1184
+ const tmp = [];
1185
+ let i = 0;
1186
+ let j = 0;
1187
+ while (i < b1.length && j < b2.length) {
1188
+ tmp.push(sort2(b1[i], b2[j]) <= 0 ? b1[i++] : b2[j++]);
1189
+ }
1190
+ return tmp.concat(b1.slice(i), b2.slice(j));
1191
+ };
1192
+ return msort([...ary]);
1193
+ }
1194
+ /**
1195
+ * Ruby `Array#join` (`vendor/ruby/v3.3.11/array.c:2806` `rb_ary_join`, over
1196
+ * `ary_join_1` at `:2778`): each element's string with `sep` between them. A
1197
+ * nested Array is joined in place with the same `sep` (`ary_join_1_ary`,
1198
+ * `:2760`), and one that contains itself raises `ArgumentError`. Every other
1199
+ * element is sent `to_s` (`rb_obj_as_string`), so a Symbol (`":name"`)
1200
+ * contributes its name. A nil `sep` is `$,`, which is nil: nothing between.
1201
+ * @noRailsEquivalent PERMANENT
1202
+ */
1203
+ export function aryJoin(ary, sep = null) {
1204
+ return aryJoin1([ary], ary, sep ?? "");
1205
+ }
1206
+ /** `ary_join_1` (`vendor/ruby/v3.3.11/array.c:2778`). */
1207
+ function aryJoin1(obj, ary, sep) {
1208
+ return ary
1209
+ .map((val) => {
1210
+ if (Array.isArray(val)) {
1211
+ if (obj.includes(val))
1212
+ throw new ArgumentError("recursive array join");
1213
+ return aryJoin1([...obj, val], val, sep);
1214
+ }
1215
+ return toS(val);
1216
+ })
1217
+ .join(sep);
1218
+ }
1219
+ /**
1220
+ * The Array methods `rbFSend` dispatches and `basicObjRespondTo` answers for
1221
+ * that a JS array has no member for, keyed by the camelCased Ruby name as
1222
+ * `STRING_METHOD_TABLE` keys String's. They are the ones `Init_Array`
1223
+ * (`vendor/ruby/v3.3.11/array.c:8606`) and `Enumerable`
1224
+ * (`vendor/ruby/v3.3.11/enum.c:5047`) define that a Relation sends its
1225
+ * records: by `delegate ..., to: :records`
1226
+ * (`vendor/rails/v8.0.5.2/activerecord/lib/active_record/relation/delegation.rb:98-103`)
1227
+ * and by `include Enumerable`
1228
+ * (`vendor/rails/v8.0.5.2/activerecord/lib/active_record/relation.rb:67`).
1229
+ * A name the ported `Enumerable` module answers is not repeated here. `-`, `|` and `&` go by the method Ruby
1230
+ * also names them (`difference`, `union`, `intersection`) and `+` is `plus`;
1231
+ * a block is a trailing `rbObjIsProc` function, and with no block an
1232
+ * entry answers a copy of the Array its enumerator would yield. A package
1233
+ * that reopens Array, as ActiveSupport's `core_ext/array` does, assigns an
1234
+ * entry.
1235
+ *
1236
+ * @noRailsEquivalent PERMANENT
1237
+ */
1238
+ export const ARRAY_METHOD_TABLE = Object.assign(Object.create(null), {
1239
+ /** `rb_ary_to_a` (`vendor/ruby/v3.3.11/array.c:2952`). */
1240
+ toA: (self) => toA(self),
1241
+ /** `rb_ary_to_ary_m` (`vendor/ruby/v3.3.11/array.c:3019`). */
1242
+ toAry: (self) => self,
1243
+ /** `rb_ary_plus` (`vendor/ruby/v3.3.11/array.c:4879`). */
1244
+ plus: (self, y) => rbPlus(self, y),
1245
+ /** `rb_ary_difference_multi` (`vendor/ruby/v3.3.11/array.c:5430`), over `rb_ary_diff` (`:5384`). */
1246
+ difference: (self, ...argv) => argv.reduce((ary1, ary2) => ary1.filter((elt) => !ary2.some((e) => rbEql(e, elt))), [...self]),
1247
+ /** `rb_ary_union_multi` (`vendor/ruby/v3.3.11/array.c:5635`). */
1248
+ union: (self, ...argv) => argv.reduce(union, uniq(self)),
1249
+ /** `rb_ary_intersection_multi` (`vendor/ruby/v3.3.11/array.c:5541`), over `rb_ary_and` (`:5486`). */
1250
+ intersection: (self, ...argv) => argv.reduce((ary1, ary2) => uniq(ary1.filter((v) => ary2.some((e) => rbEql(e, v)))), [...self]),
1251
+ /** `rb_ary_intersect_p` (`vendor/ruby/v3.3.11/array.c:5680`). */
1252
+ isIntersect: (self, ary2) => isIntersect(self, ary2),
1253
+ /** `rb_ary_index` (`vendor/ruby/v3.3.11/array.c:2026`). */
1254
+ index: (self, ...argv) => {
1255
+ if (argv.length === 0)
1256
+ return [...self];
1257
+ const [val] = argv;
1258
+ const i = self.findIndex((e) => (rbObjIsProc(val) ? rtest(val(e)) : rbEqual(e, val)));
1259
+ return i < 0 ? null : i;
1260
+ },
1261
+ /** `rb_ary_rindex` (`vendor/ruby/v3.3.11/array.c:2087`). */
1262
+ rindex: (self, ...argv) => {
1263
+ if (argv.length === 0)
1264
+ return [...self].reverse();
1265
+ const [val] = argv;
1266
+ for (let i = self.length; i--;) {
1267
+ if (rbObjIsProc(val) ? rtest(val(self[i])) : rbEqual(self[i], val))
1268
+ return i;
1269
+ }
1270
+ return null;
1271
+ },
1272
+ /** `rb_ary_collect` (`vendor/ruby/v3.3.11/array.c:3625`). */
1273
+ collect: (self, block) => (block ? self.map((v) => block(v)) : [...self]),
1274
+ /** `rb_ary_compact` (`vendor/ruby/v3.3.11/array.c:6240`). */
1275
+ compact: (self) => compact(self),
1276
+ /** `rb_ary_last` (`vendor/ruby/v3.3.11/array.c:1914`). */
1277
+ last: (self, ...argv) => (argv.length === 0 ? last(self) : last(self, argv[0])),
1278
+ /** `rb_ary_reject` (`vendor/ruby/v3.3.11/array.c:4301`). */
1279
+ reject: (self, block) => (block ? self.filter((v) => !rtest(block(v))) : [...self]),
1280
+ /** `rb_ary_rotate_m` (`vendor/ruby/v3.3.11/array.c:3240`). */
1281
+ rotate: (self, cnt = 1) => {
1282
+ const n = self.length === 0 ? 0 : ((cnt % self.length) + self.length) % self.length;
1283
+ return [...self.slice(n), ...self.slice(0, n)];
1284
+ },
1285
+ /** `Array#shuffle` (`vendor/ruby/v3.3.11/array.rb:26`), over `rb_ary_shuffle_bang` (`array.c:6497`). */
1286
+ shuffle: (self) => {
1287
+ const ary = [...self];
1288
+ for (let i = ary.length; i > 1;) {
1289
+ const j = Math.floor(Math.random() * i--);
1290
+ [ary[i], ary[j]] = [ary[j], ary[i]];
1291
+ }
1292
+ return ary;
1293
+ },
1294
+ /** `Array#sample` (`vendor/ruby/v3.3.11/array.rb:60`). */
1295
+ sample: (self, ...args) => {
1296
+ if (args.length && args[0] < 0)
1297
+ throw new ArgumentError("negative sample number");
1298
+ const ary = ARRAY_METHOD_TABLE.shuffle(self);
1299
+ return args.length ? ary.slice(0, args[0]) : (ary[0] ?? null);
1300
+ },
1301
+ /** `rb_ary_all_p` (`vendor/ruby/v3.3.11/array.c:7740`). */
1302
+ isAll: (self, ...argv) => self.every((v) => (argv.length ? rbEqq(argv[0], v) : rtest(v))),
1303
+ /** `enum_find` (`vendor/ruby/v3.3.11/enum.c:361`). */
1304
+ detect: (self, ifNone, block) => {
1305
+ if (!block)
1306
+ return [...self];
1307
+ return find(self, ...(ifNone === undefined ? [block] : [ifNone, block]));
1308
+ },
1309
+ /** `enum_partition` (`vendor/ruby/v3.3.11/enum.c:1102`). */
1310
+ partition: (self, block) => (block ? partition(self, block) : partition(self)),
1311
+ /** `enum_sort_by` (`vendor/ruby/v3.3.11/enum.c:1651`). */
1312
+ sortBy: (self, block) => !block
1313
+ ? [...self]
1314
+ : self
1315
+ .map((v) => [block(v), v])
1316
+ .sort((a, b) => rbCmpint(cmp(a[0], b[0]), a[0], b[0]))
1317
+ .map((pair) => pair[1]),
1318
+ /** `enum_each_with_index` (`vendor/ruby/v3.3.11/enum.c:2967`). */
1319
+ eachWithIndex: (self, block) => {
1320
+ if (!block)
1321
+ return self.map((v, i) => [v, i]);
1322
+ self.forEach((v, i) => block(v, i));
1323
+ return self;
1324
+ },
1325
+ /** `enum_each_cons` (`vendor/ruby/v3.3.11/enum.c:3244`). */
1326
+ eachCons: (self, n, block) => block ? eachCons(self, n, (cons) => block(cons)) : eachCons(self, n),
1327
+ /** `Enumerable#to_set` (`vendor/ruby/v3.3.11/prelude.rb:28`). */
1328
+ toSet: (self) => new Set(self),
1329
+ });
1330
+ //# sourceMappingURL=array.js.map