@kaeawc/auto-mobile 0.0.90 → 0.0.92

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 (280) hide show
  1. package/README.md +7 -0
  2. package/README.md.backup +7 -0
  3. package/dist/build-info.json +12 -11
  4. package/dist/schemas/README.md +16 -0
  5. package/dist/schemas/prototype-icon-names.json +302 -0
  6. package/dist/schemas/prototype-platform-permissions.json +75 -0
  7. package/dist/schemas/test-plan.schema.json +2 -2
  8. package/dist/src/chunk-09442h7v.js +4 -0
  9. package/dist/src/chunk-0dfnyfkh.js +5 -0
  10. package/dist/src/chunk-0e4gm1kj.js +5 -0
  11. package/dist/src/chunk-0eb8576f.js +4 -0
  12. package/dist/src/chunk-0rjm4nx7.js +5 -0
  13. package/dist/src/chunk-0w1spptt.js +6 -0
  14. package/dist/src/chunk-1zmh2eak.js +4 -0
  15. package/dist/src/chunk-28k63ha3.js +5 -0
  16. package/dist/src/chunk-2d4wmp8b.js +4 -0
  17. package/dist/src/chunk-2e6s75qv.js +78 -0
  18. package/dist/src/chunk-2v7tw1nj.js +5 -0
  19. package/dist/src/chunk-32jpxz2y.js +323 -0
  20. package/dist/src/chunk-34zxqcmq.js +5 -0
  21. package/dist/src/chunk-3jmvqygr.js +238 -0
  22. package/dist/src/chunk-3swvfhqt.js +5 -0
  23. package/dist/src/chunk-44bt78m9.js +5 -0
  24. package/dist/src/chunk-488vt2bp.js +4 -0
  25. package/dist/src/chunk-4fgdhcwx.js +5 -0
  26. package/dist/src/chunk-4jp2se4w.js +4 -0
  27. package/dist/src/chunk-4pfftt07.js +5 -0
  28. package/dist/src/chunk-4vhr9e4t.js +4 -0
  29. package/dist/src/chunk-4xd6zs3y.js +15 -0
  30. package/dist/src/chunk-51567pg8.js +4 -0
  31. package/dist/src/chunk-5agqsfev.js +4 -0
  32. package/dist/src/chunk-5d706gmr.js +4 -0
  33. package/dist/src/chunk-5kd4rqk7.js +5 -0
  34. package/dist/src/chunk-5s645vr4.js +4 -0
  35. package/dist/src/chunk-61t538bm.js +4 -0
  36. package/dist/src/chunk-6d3mmqxt.js +54 -0
  37. package/dist/src/chunk-6hyt398x.js +5 -0
  38. package/dist/src/chunk-6mnr8kpm.js +4 -0
  39. package/dist/src/chunk-6pg7bqck.js +4 -0
  40. package/dist/src/chunk-79q5xsdc.js +42 -0
  41. package/dist/src/chunk-7bdgand3.js +4 -0
  42. package/dist/src/chunk-84cp9dw5.js +4 -0
  43. package/dist/src/chunk-86f2h5ww.js +5 -0
  44. package/dist/src/chunk-8cghfzb2.js +19 -0
  45. package/dist/src/chunk-8en08r7q.js +5 -0
  46. package/dist/src/chunk-950qcq1e.js +10 -0
  47. package/dist/src/chunk-9rkfyt6q.js +5 -0
  48. package/dist/src/chunk-9tf2p9y9.js +5 -0
  49. package/dist/src/chunk-9y5bcy28.js +6 -0
  50. package/dist/src/chunk-a2sc4jm0.js +5 -0
  51. package/dist/src/chunk-a4k9rt7z.js +5 -0
  52. package/dist/src/chunk-aa5ng3d1.js +4 -0
  53. package/dist/src/chunk-ajsrz473.js +5 -0
  54. package/dist/src/chunk-b3h0a6ca.js +4 -0
  55. package/dist/src/chunk-b4cxdzwy.js +20 -0
  56. package/dist/src/chunk-b6a737qt.js +4 -0
  57. package/dist/src/chunk-bn64x5z5.js +5 -0
  58. package/dist/src/chunk-bvh649za.js +12 -0
  59. package/dist/src/chunk-c9nk1r78.js +5 -0
  60. package/dist/src/chunk-c9tyfg4j.js +26 -0
  61. package/dist/src/chunk-cfsdfqnm.js +4 -0
  62. package/dist/src/chunk-cxyf04jc.js +7 -0
  63. package/dist/src/chunk-d57432wq.js +4 -0
  64. package/dist/src/chunk-da08tx5v.js +4 -0
  65. package/dist/src/chunk-eka89q3k.js +4 -0
  66. package/dist/src/chunk-f2tc08m2.js +4 -0
  67. package/dist/src/chunk-f8tnk179.js +5 -0
  68. package/dist/src/chunk-f9s1kkhx.js +5 -0
  69. package/dist/src/chunk-fbp8a4rx.js +4 -0
  70. package/dist/src/chunk-fd2z0sze.js +4 -0
  71. package/dist/src/chunk-fk927f4q.js +54 -0
  72. package/dist/src/chunk-fxmr3a0f.js +4 -0
  73. package/dist/src/chunk-gaqwhd44.js +4 -0
  74. package/dist/src/chunk-ggtd5x5a.js +5 -0
  75. package/dist/src/chunk-gndcfrm7.js +4 -0
  76. package/dist/src/chunk-h3n4adc6.js +310 -0
  77. package/dist/src/chunk-h5pjbb83.js +4 -0
  78. package/dist/src/chunk-hgnnh302.js +4 -0
  79. package/dist/src/chunk-hmke8nhx.js +5 -0
  80. package/dist/src/chunk-j2bx12hn.js +4 -0
  81. package/dist/src/chunk-j70y1a2g.js +4 -0
  82. package/dist/src/chunk-jdqvcq0a.js +5 -0
  83. package/dist/src/chunk-jhnbfj19.js +55 -0
  84. package/dist/src/chunk-js1jpyxp.js +6 -0
  85. package/dist/src/chunk-kbjq0qvb.js +4 -0
  86. package/dist/src/chunk-kfwx57xd.js +4 -0
  87. package/dist/src/chunk-km0dy5vc.js +71 -0
  88. package/dist/src/chunk-kzwctna2.js +4 -0
  89. package/dist/src/chunk-m9ehyehy.js +4 -0
  90. package/dist/src/chunk-mct91p1f.js +4 -0
  91. package/dist/src/chunk-mf9spd4g.js +5 -0
  92. package/dist/src/chunk-mgrcansb.js +4 -0
  93. package/dist/src/chunk-mqc1d0eb.js +6 -0
  94. package/dist/src/chunk-n1zmpk0z.js +4 -0
  95. package/dist/src/chunk-ncyjf63g.js +4 -0
  96. package/dist/src/chunk-nr64d21q.js +973 -0
  97. package/dist/src/chunk-nwm2pq5v.js +168 -0
  98. package/dist/src/chunk-pm06b05d.js +9 -0
  99. package/dist/src/chunk-q50s00ry.js +4 -0
  100. package/dist/src/chunk-qv2918jt.js +4 -0
  101. package/dist/src/chunk-qwye1958.js +14 -0
  102. package/dist/src/chunk-r0f1q783.js +5 -0
  103. package/dist/src/chunk-r14wwk37.js +18 -0
  104. package/dist/src/chunk-r20pe1nv.js +5 -0
  105. package/dist/src/chunk-r8z9pfve.js +5 -0
  106. package/dist/src/chunk-rdpgkjf6.js +4 -0
  107. package/dist/src/chunk-rkr0dks9.js +5 -0
  108. package/dist/src/chunk-rn84t3sf.js +11 -0
  109. package/dist/src/chunk-s123kn7n.js +4 -0
  110. package/dist/src/chunk-s1zq65ny.js +4 -0
  111. package/dist/src/chunk-s73qn3fx.js +4 -0
  112. package/dist/src/chunk-sjn0nj4p.js +5 -0
  113. package/dist/src/chunk-sns0c35v.js +7 -0
  114. package/dist/src/chunk-stfzjr9y.js +8 -0
  115. package/dist/src/chunk-sz1a7p43.js +4 -0
  116. package/dist/src/chunk-t4dr5c8v.js +8 -0
  117. package/dist/src/chunk-tc8k9c1j.js +4 -0
  118. package/dist/src/chunk-teznhase.js +4 -0
  119. package/dist/src/chunk-ty9xgmz4.js +4 -0
  120. package/dist/src/chunk-tyazf3sk.js +145 -0
  121. package/dist/src/chunk-v6npjrjm.js +5 -0
  122. package/dist/src/chunk-v90es00d.js +4 -0
  123. package/dist/src/chunk-vbvtzkwz.js +5 -0
  124. package/dist/src/chunk-vefd8qee.js +8 -0
  125. package/dist/src/chunk-vs9r72ta.js +17 -0
  126. package/dist/src/chunk-w2mwa0jk.js +4 -0
  127. package/dist/src/chunk-w7zsh13a.js +9 -0
  128. package/dist/src/chunk-w88k0bgr.js +4 -0
  129. package/dist/src/chunk-wry6skrm.js +4 -0
  130. package/dist/src/chunk-wzdt0enk.js +4 -0
  131. package/dist/src/chunk-xhhv854c.js +4 -0
  132. package/dist/src/chunk-y58270hd.js +4 -0
  133. package/dist/src/chunk-yk0hmbex.js +4 -0
  134. package/dist/src/chunk-ympy4fdz.js +28 -0
  135. package/dist/src/chunk-yw436axy.js +4 -0
  136. package/dist/src/chunk-z04jrpjy.js +5 -0
  137. package/dist/src/chunk-z2xznczw.js +4 -0
  138. package/dist/src/chunk-z4xnrgps.js +4 -0
  139. package/dist/src/chunk-z7csyszv.js +4 -0
  140. package/dist/src/chunk-z8t0v07j.js +11 -0
  141. package/dist/src/chunk-z916af47.js +228 -0
  142. package/dist/src/chunk-zcr8he8q.js +5 -0
  143. package/dist/src/chunk-zd9vmkzn.js +9 -0
  144. package/dist/src/chunk-zg67wjkh.js +5 -0
  145. package/dist/src/chunk-zj939v0h.js +5 -0
  146. package/dist/src/chunk-zkdjwtc1.js +4 -0
  147. package/dist/src/chunk-zkv5kzt6.js +4 -0
  148. package/dist/src/daemon/processEntry.js +4 -0
  149. package/dist/src/index.js +4 -2797
  150. package/dist/src/runtime/bunRuntimeGuard.js +4 -0
  151. package/dist/src/utils/workers/iosBundleExtractWorker.js +2 -3
  152. package/node_modules/strtok3/lib/BufferSizeError.js +1 -1
  153. package/node_modules/strtok3/lib/TokenWriter.js +151 -0
  154. package/node_modules/strtok3/lib/core.js +1 -0
  155. package/node_modules/strtok3/package.json +2 -2
  156. package/node_modules/token-types/LICENSE.txt +9 -9
  157. package/node_modules/token-types/{lib → dist/lib}/index.js +21 -3
  158. package/node_modules/token-types/package.json +81 -81
  159. package/package.json +10 -10
  160. package/schemas/README.md +16 -0
  161. package/schemas/prototype-icon-names.json +302 -0
  162. package/schemas/prototype-platform-permissions.json +75 -0
  163. package/schemas/test-plan.schema.json +2 -2
  164. package/node_modules/@borewit/text-codec/README.md +0 -87
  165. package/node_modules/@jimp/diff/node_modules/pixelmatch/README.md +0 -110
  166. package/node_modules/@jimp/diff/node_modules/pixelmatch/node_modules/pngjs/README.md +0 -433
  167. package/node_modules/@jimp/file-ops/dist/browser/index.js +0 -8
  168. package/node_modules/@jimp/js-png/README.md +0 -35
  169. package/node_modules/@jimp/js-png/src/__image_snapshots__/index-node-test-ts-png-should-use-png-options-1-snap.png +0 -0
  170. package/node_modules/@jimp/js-png/src/output.png +0 -0
  171. package/node_modules/@jimp/js-png/vitest.config.browser.mjs +0 -3
  172. package/node_modules/@jimp/plugin-resize/README.md +0 -12
  173. package/node_modules/@jimp/plugin-resize/vitest.config.browser.mjs +0 -3
  174. package/node_modules/@tokenizer/inflate/README.md +0 -114
  175. package/node_modules/@tokenizer/token/README.md +0 -19
  176. package/node_modules/await-to-js/README.md +0 -82
  177. package/node_modules/debug/README.md +0 -481
  178. package/node_modules/exif-parser/README.md +0 -83
  179. package/node_modules/file-type/readme.md +0 -667
  180. package/node_modules/ieee754/README.md +0 -51
  181. package/node_modules/mime/README.md +0 -178
  182. package/node_modules/ms/readme.md +0 -59
  183. package/node_modules/parse-bmfont-xml/README.md +0 -74
  184. package/node_modules/parse-bmfont-xml/lib/browser.js +0 -85
  185. package/node_modules/parse-bmfont-xml/node_modules/xml2js/README.md +0 -507
  186. package/node_modules/pngjs/README.md +0 -287
  187. package/node_modules/sax/README.md +0 -228
  188. package/node_modules/strtok3/README.md +0 -736
  189. package/node_modules/tinycolor2/README.md +0 -492
  190. package/node_modules/tinycolor2/cjs/test.js +0 -2191
  191. package/node_modules/tinycolor2/cjs/test_template.js +0 -26
  192. package/node_modules/tinycolor2/deno_asserts@0.168.0.mjs +0 -807
  193. package/node_modules/tinycolor2/esm/test.js +0 -2189
  194. package/node_modules/tinycolor2/esm/test_template.js +0 -24
  195. package/node_modules/tinycolor2/tinycolor.js +0 -1191
  196. package/node_modules/token-types/README.md +0 -120
  197. package/node_modules/uint8array-extras/readme.md +0 -318
  198. package/node_modules/xml-parse-from-string/README.md +0 -35
  199. package/node_modules/xmlbuilder/README.md +0 -86
  200. package/node_modules/zod/README.md +0 -208
  201. package/node_modules/zod/v4/locales/ar.d.cts +0 -4
  202. package/node_modules/zod/v4/locales/ar.d.ts +0 -4
  203. package/node_modules/zod/v4/locales/az.d.cts +0 -4
  204. package/node_modules/zod/v4/locales/az.d.ts +0 -4
  205. package/node_modules/zod/v4/locales/be.d.cts +0 -4
  206. package/node_modules/zod/v4/locales/be.d.ts +0 -4
  207. package/node_modules/zod/v4/locales/ca.d.cts +0 -4
  208. package/node_modules/zod/v4/locales/ca.d.ts +0 -4
  209. package/node_modules/zod/v4/locales/cs.d.cts +0 -4
  210. package/node_modules/zod/v4/locales/cs.d.ts +0 -4
  211. package/node_modules/zod/v4/locales/de.d.cts +0 -4
  212. package/node_modules/zod/v4/locales/de.d.ts +0 -4
  213. package/node_modules/zod/v4/locales/en.d.cts +0 -5
  214. package/node_modules/zod/v4/locales/en.d.ts +0 -5
  215. package/node_modules/zod/v4/locales/eo.d.cts +0 -5
  216. package/node_modules/zod/v4/locales/eo.d.ts +0 -5
  217. package/node_modules/zod/v4/locales/es.d.cts +0 -4
  218. package/node_modules/zod/v4/locales/es.d.ts +0 -4
  219. package/node_modules/zod/v4/locales/fa.d.cts +0 -4
  220. package/node_modules/zod/v4/locales/fa.d.ts +0 -4
  221. package/node_modules/zod/v4/locales/fi.d.cts +0 -4
  222. package/node_modules/zod/v4/locales/fi.d.ts +0 -4
  223. package/node_modules/zod/v4/locales/fr-CA.d.cts +0 -4
  224. package/node_modules/zod/v4/locales/fr-CA.d.ts +0 -4
  225. package/node_modules/zod/v4/locales/fr.d.cts +0 -4
  226. package/node_modules/zod/v4/locales/fr.d.ts +0 -4
  227. package/node_modules/zod/v4/locales/he.d.cts +0 -4
  228. package/node_modules/zod/v4/locales/he.d.ts +0 -4
  229. package/node_modules/zod/v4/locales/hu.d.cts +0 -4
  230. package/node_modules/zod/v4/locales/hu.d.ts +0 -4
  231. package/node_modules/zod/v4/locales/id.d.cts +0 -4
  232. package/node_modules/zod/v4/locales/id.d.ts +0 -4
  233. package/node_modules/zod/v4/locales/index.d.cts +0 -39
  234. package/node_modules/zod/v4/locales/index.d.ts +0 -39
  235. package/node_modules/zod/v4/locales/it.d.cts +0 -4
  236. package/node_modules/zod/v4/locales/it.d.ts +0 -4
  237. package/node_modules/zod/v4/locales/ja.d.cts +0 -4
  238. package/node_modules/zod/v4/locales/ja.d.ts +0 -4
  239. package/node_modules/zod/v4/locales/kh.d.cts +0 -4
  240. package/node_modules/zod/v4/locales/kh.d.ts +0 -4
  241. package/node_modules/zod/v4/locales/ko.d.cts +0 -4
  242. package/node_modules/zod/v4/locales/ko.d.ts +0 -4
  243. package/node_modules/zod/v4/locales/mk.d.cts +0 -4
  244. package/node_modules/zod/v4/locales/mk.d.ts +0 -4
  245. package/node_modules/zod/v4/locales/ms.d.cts +0 -4
  246. package/node_modules/zod/v4/locales/ms.d.ts +0 -4
  247. package/node_modules/zod/v4/locales/nl.d.cts +0 -4
  248. package/node_modules/zod/v4/locales/nl.d.ts +0 -4
  249. package/node_modules/zod/v4/locales/no.d.cts +0 -4
  250. package/node_modules/zod/v4/locales/no.d.ts +0 -4
  251. package/node_modules/zod/v4/locales/ota.d.cts +0 -4
  252. package/node_modules/zod/v4/locales/ota.d.ts +0 -4
  253. package/node_modules/zod/v4/locales/pl.d.cts +0 -4
  254. package/node_modules/zod/v4/locales/pl.d.ts +0 -4
  255. package/node_modules/zod/v4/locales/ps.d.cts +0 -4
  256. package/node_modules/zod/v4/locales/ps.d.ts +0 -4
  257. package/node_modules/zod/v4/locales/pt.d.cts +0 -4
  258. package/node_modules/zod/v4/locales/pt.d.ts +0 -4
  259. package/node_modules/zod/v4/locales/ru.d.cts +0 -4
  260. package/node_modules/zod/v4/locales/ru.d.ts +0 -4
  261. package/node_modules/zod/v4/locales/sl.d.cts +0 -4
  262. package/node_modules/zod/v4/locales/sl.d.ts +0 -4
  263. package/node_modules/zod/v4/locales/sv.d.cts +0 -4
  264. package/node_modules/zod/v4/locales/sv.d.ts +0 -4
  265. package/node_modules/zod/v4/locales/ta.d.cts +0 -4
  266. package/node_modules/zod/v4/locales/ta.d.ts +0 -4
  267. package/node_modules/zod/v4/locales/th.d.cts +0 -4
  268. package/node_modules/zod/v4/locales/th.d.ts +0 -4
  269. package/node_modules/zod/v4/locales/tr.d.cts +0 -5
  270. package/node_modules/zod/v4/locales/tr.d.ts +0 -5
  271. package/node_modules/zod/v4/locales/ua.d.cts +0 -4
  272. package/node_modules/zod/v4/locales/ua.d.ts +0 -4
  273. package/node_modules/zod/v4/locales/ur.d.cts +0 -4
  274. package/node_modules/zod/v4/locales/ur.d.ts +0 -4
  275. package/node_modules/zod/v4/locales/vi.d.cts +0 -4
  276. package/node_modules/zod/v4/locales/vi.d.ts +0 -4
  277. package/node_modules/zod/v4/locales/zh-CN.d.cts +0 -4
  278. package/node_modules/zod/v4/locales/zh-CN.d.ts +0 -4
  279. package/node_modules/zod/v4/locales/zh-TW.d.cts +0 -4
  280. package/node_modules/zod/v4/locales/zh-TW.d.ts +0 -4
@@ -1,736 +0,0 @@
1
- [![Node.js CI](https://github.com/Borewit/strtok3/actions/workflows/ci.yml/badge.svg)](https://github.com/Borewit/strtok3/actions/workflows/ci.yml)
2
- [![CodeQL](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml/badge.svg?branch=master)](https://github.com/Borewit/strtok3/actions/workflows/codeql.yml)
3
- [![NPM version](https://badge.fury.io/js/strtok3.svg)](https://npmjs.org/package/strtok3)
4
- [![npm downloads](http://img.shields.io/npm/dm/strtok3.svg)](https://npmcharts.com/compare/strtok3,token-types?start=1200&interval=30)
5
- [![DeepScan grade](https://deepscan.io/api/teams/5165/projects/8526/branches/103329/badge/grade.svg)](https://deepscan.io/dashboard#view=project&tid=5165&pid=8526&bid=103329)
6
- [![Known Vulnerabilities](https://snyk.io/test/github/Borewit/strtok3/badge.svg?targetFile=package.json)](https://snyk.io/test/github/Borewit/strtok3?targetFile=package.json)
7
- [![Codacy Badge](https://api.codacy.com/project/badge/Grade/59dd6795e61949fb97066ca52e6097ef)](https://www.codacy.com/app/Borewit/strtok3?utm_source=github.com&utm_medium=referral&utm_content=Borewit/strtok3&utm_campaign=Badge_Grade)
8
- [![Codecov](https://codecov.io/gh/Borewit/strtok3/branch/master/graph/badge.svg)](https://codecov.io/gh/Borewit/strtok3)
9
- # strtok3
10
-
11
- A promise-based streaming [*tokenizer*](#tokenizer-object) for [Node.js](https://nodejs.org) and browsers.
12
-
13
- The `strtok3` module provides several methods for creating a [*tokenizer*](#tokenizer-object) from various input sources.
14
- Designed for:
15
- * Seamless support in streaming environments.
16
- * Efficiently decode binary data, strings, and numbers.
17
- * Reading [predefined](https://github.com/Borewit/token-types) or custom tokens.
18
- * Offering [*tokenizers*](#tokenizer-object) for reading from [files](#fromfile-function), [streams](#fromstream-function) or [Uint8Arrays](#frombuffer-function).
19
-
20
- ### Features
21
- `strtok3` can read from:
22
- * Files, using a file path as input.
23
- * Node.js [streams](https://nodejs.org/api/stream.html).
24
- * WHATWG [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) objects containing `Uint8Array` chunks.
25
- * [Buffer](https://nodejs.org/api/buffer.html) or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array).
26
- * [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) objects.
27
- * HTTP chunked transfer provided by [@tokenizer/http](https://github.com/Borewit/tokenizer-http).
28
- * [Amazon S3](https://aws.amazon.com/s3) chunks with [@tokenizer/s3](https://github.com/Borewit/tokenizer-s3).
29
-
30
- ## Installation
31
-
32
- ```sh
33
- npm install strtok3
34
- ```
35
-
36
- ### Compatibility
37
-
38
- Starting with version 7, the module has migrated from [CommonJS](https://en.wikipedia.org/wiki/CommonJS) to [pure ECMAScript Module (ESM)](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c).
39
- The distributed JavaScript codebase is compliant with the [ECMAScript 2020 (11th Edition)](https://en.wikipedia.org/wiki/ECMAScript_version_history#11th_Edition_%E2%80%93_ECMAScript_2020) standard.
40
-
41
- Requires a modern browser, Node.js (V8) ≥ 18 engine or Bun (JavaScriptCore) ≥ 1.2.
42
- It can also be used in a browser environment when bundled with a module bundler.
43
-
44
- For TypeScript CommonJS backward compatibility, you can use [load-esm](https://github.com/Borewit/load-esm).
45
-
46
- Use Node.js 24 LTS to build the project and install development dependencies.
47
- This build requirement is separate from the Node.js ≥ 18 runtime requirement in `package.json`.
48
- CI builds once with Node.js 24, then runs the compiled JavaScript unit tests across the Node.js compatibility matrix and Bun 1.2.x, 1.3.x, and 1.4.x.
49
- Coverage is collected in a separate Node.js 24 job and uploaded to Codecov.
50
-
51
- For local development, running the TypeScript tests with `tsx` requires Node.js 18.19+ (18.x) or Node.js ≥ 20.6.0.
52
-
53
- ## Support the Project
54
- If you find this project useful and would like to support its development, consider sponsoring or contributing:
55
-
56
- - [Become a sponsor to Borewit](https://github.com/sponsors/Borewit)
57
-
58
- - Buy me a coffee:
59
-
60
- <a href="https://www.buymeacoffee.com/borewit" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/default-orange.png" alt="Buy me A coffee" height="41" width="174"></a>
61
-
62
- ## API Documentation
63
-
64
- ### strtok3 methods
65
-
66
- Use one of the methods to instantiate an [*abstract tokenizer*](#tokenizer-object):
67
- - [fromBlob](#fromblob-function)
68
- - [fromBuffer](#frombuffer-function)
69
- - [fromFile](#fromfile-function)
70
- - [fromStream](#fromstream-function)
71
- - [fromWebStream](#fromwebstream-function)
72
- - [createTokenizerView](#createtokenizerview-function)
73
-
74
- > [!NOTE]
75
- > `fromFile` requires Node.js file-system APIs, and `fromStream` requires a Node.js readable stream.
76
- > In browsers, use `fromBlob`, `fromBuffer`, or `fromWebStream`.
77
-
78
- All methods return a [`Tokenizer`](#tokenizer-object), either directly or via a promise.
79
- The `strtok3/core` entry point exports all factories except `fromFile` and can be used
80
- without Node.js file-system APIs. In browsers, `strtok3` resolves to this core entry point.
81
-
82
- #### `fromBlob()` function
83
-
84
- Create a tokenizer from a [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob).
85
-
86
- ```ts
87
- function fromBlob(blob: Blob, options?: ITokenizerOptions): BlobTokenizer
88
- ```
89
-
90
- | Parameter | Optional | Type | Description |
91
- |-----------|-----------|---------------------------------------------------|----------------------------------------------------------------------------------------|
92
- | blob | no | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) | [Blob](https://developer.mozilla.org/en-US/docs/Web/API/Blob) or [File](https://developer.mozilla.org/en-US/docs/Web/API/File) to read from |
93
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
94
-
95
- Returns a [*tokenizer*](#tokenizer-object).
96
-
97
- ```js
98
- import { fromBlob } from 'strtok3';
99
- import * as Token from 'token-types';
100
-
101
- async function parse() {
102
- const blob = new Blob([new Uint8Array([42])]);
103
-
104
- const tokenizer = fromBlob(blob);
105
-
106
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
107
- console.log(`My number: ${myUint8Number}`);
108
- }
109
-
110
- parse();
111
-
112
- ```
113
-
114
- #### `fromBuffer()` function
115
-
116
- Create a tokenizer from memory ([Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) or Node.js [Buffer](https://nodejs.org/api/buffer.html)).
117
-
118
- ```ts
119
- function fromBuffer(uint8Array: Uint8Array, options?: ITokenizerOptions): BufferTokenizer
120
- ```
121
-
122
- | Parameter | Optional | Type | Description |
123
- |------------|----------|--------------------------------------------------|-----------------------------------|
124
- | uint8Array | no | [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) | Buffer or Uint8Array to read from |
125
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
126
-
127
- Returns a [*tokenizer*](#tokenizer-object).
128
-
129
- ```js
130
- import { fromBuffer } from 'strtok3';
131
- import * as Token from 'token-types';
132
-
133
- const tokenizer = fromBuffer(new Uint8Array([42]));
134
-
135
- async function parse() {
136
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
137
- console.log(`My number: ${myUint8Number}`);
138
- }
139
-
140
- parse();
141
- ```
142
-
143
- #### `fromFile` function
144
-
145
- Creates a [*tokenizer*](#tokenizer-object) from a local file.
146
-
147
- ```ts
148
- function fromFile(sourceFilePath: string, options?: IFromFileOptions): Promise<FileTokenizer>
149
- ```
150
-
151
- | Parameter | Type | Description |
152
- |----------------|----------|----------------------------|
153
- | sourceFilePath | `string` | Path to file to read from |
154
- | options | [IFromFileOptions](#ifromfileoptions-interface) | Optional file tokenizer options |
155
-
156
- > [!NOTE]
157
- > - Only available for Node.js engines
158
- > - `fromFile` automatically embeds [file information](#ifileinfo-interface)
159
-
160
- A Promise resolving to a [*tokenizer*](#tokenizer-object) which can be used to parse a file.
161
-
162
- ```js
163
- import { fromFile } from 'strtok3';
164
- import * as Token from 'token-types';
165
-
166
- async function parse() {
167
- const tokenizer = await fromFile('somefile.bin');
168
- try {
169
- const myNumber = await tokenizer.readToken(Token.UINT8);
170
- console.log(`My number: ${myNumber}`);
171
- } finally {
172
- await tokenizer.close(); // Close the file
173
- }
174
- }
175
-
176
- parse();
177
-
178
-
179
- ```
180
-
181
- #### `fromStream()` function
182
-
183
- Create a tokenizer from a Node.js [readable stream](https://nodejs.org/api/stream.html#readable-streams) containing binary data.
184
-
185
- ```ts
186
- function fromStream(stream: Readable, options?: ITokenizerOptions): Promise<ReadStreamTokenizer>
187
- ```
188
-
189
- | Parameter | Optional | Type | Description |
190
- |-----------|----------|------|-------------|
191
- | stream | no | Readable | Node.js readable stream to read from |
192
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
193
-
194
- When importing from `strtok3` in Node.js, returns a promise resolving to a [*tokenizer*](#tokenizer-object).
195
- For streams created by `createReadStream`, the file path and size are added to `tokenizer.fileInfo`.
196
- The `strtok3/core` entry point also exports `fromStream`, but returns the tokenizer synchronously without looking up file information.
197
-
198
- ```js
199
- import { createReadStream } from 'node:fs';
200
- import { fromStream } from 'strtok3';
201
- import * as Token from 'token-types';
202
-
203
- async function parse() {
204
- const stream = createReadStream('somefile.bin');
205
- try {
206
- const tokenizer = await fromStream(stream);
207
- try {
208
- const myNumber = await tokenizer.readToken(Token.UINT8);
209
- console.log(`My number: ${myNumber}`);
210
- } finally {
211
- await tokenizer.close();
212
- }
213
- } finally {
214
- stream.destroy();
215
- }
216
- }
217
-
218
- parse();
219
- ```
220
-
221
- #### `fromWebStream()` function
222
-
223
- Create a tokenizer from a [WHATWG ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) containing `Uint8Array` chunks.
224
-
225
- Uses a BYOB reader when supported by the stream, otherwise a default reader. Source cleanup differs between these readers; see [`close()`](#close-function) and [`abort()`](#abort-function).
226
-
227
- ```ts
228
- function fromWebStream(webStream: AnyWebByteStream, options?: ITokenizerOptions): ReadStreamTokenizer
229
- ```
230
-
231
- | Parameter | Optional | Type | Description |
232
- |----------------|----------|--------------------------------------------------------------------------|------------------------------------|
233
- | webStream | no | [ReadableStream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) | WHATWG ReadableStream to read from |
234
- | options | yes | [ITokenizerOptions](#itokenizeroptions-interface) | Tokenizer options |
235
-
236
- Returns a [*tokenizer*](#tokenizer-object).
237
-
238
- ```js
239
- import { fromWebStream } from 'strtok3';
240
- import * as Token from 'token-types';
241
-
242
- async function parse() {
243
- const tokenizer = fromWebStream(readableStream);
244
- try {
245
- const myUint8Number = await tokenizer.readToken(Token.UINT8);
246
- console.log(`My number: ${myUint8Number}`);
247
- } finally {
248
- await tokenizer.close();
249
- }
250
- }
251
-
252
- parse();
253
- ```
254
-
255
- #### `createTokenizerView()` function
256
-
257
- Borrow a finite range of an existing tokenizer without buffering it or taking
258
- ownership of its input. Available from both `strtok3` and `strtok3/core`.
259
-
260
- ```ts
261
- function createTokenizerView(source: ITokenizer, length: number): ITokenizerView
262
- ```
263
-
264
- The view starts at `source.position`, with local `position` zero and
265
- `fileInfo.size` equal to `length`. Creation does not read or skip bytes. The size
266
- is the declared range, so it can exceed the actual remaining input. The outer
267
- file's MIME type, path, and URL are not copied to the view.
268
-
269
- ```js
270
- import { createTokenizerView, fromBuffer } from 'strtok3';
271
- import { UINT8 } from 'token-types';
272
-
273
- const source = fromBuffer(new Uint8Array([10, 20, 30, 40, 50]));
274
- await source.ignore(1);
275
- const chunk = createTokenizerView(source, 3); // source bytes [20, 30, 40]
276
-
277
- console.log(await chunk.readToken(UINT8)); // 20; chunk.position = 1
278
- const child = chunk.createView(1); // same as createTokenizerView(chunk, 1)
279
- console.log(await child.readToken(UINT8)); // 30; chunk.position = 2
280
- await child.close(); // source stays open, at position 3
281
-
282
- console.log(chunk.remaining); // 1
283
- await chunk.consumeRemainder(); // exactly consume 40, or throw on truncation
284
- await chunk.close();
285
- console.log(await source.readToken(UINT8)); // 50
286
- await source.close();
287
- ```
288
-
289
- All read and peek positions, including explicit offsets and `setPosition()`, are
290
- relative to the view's start. Nested views must fit inside their parent's
291
- remaining range. A view exposes `setPosition()` and reports random access only
292
- when its source supports it; a stream with a known size remains forward-only.
293
- The overload for an `IRandomAccessTokenizer` returns an
294
- `IRandomAccessTokenizerView`, including for nested `createView()` calls.
295
-
296
- A request crossing the declared boundary rejects with `TokenizerBoundaryError`,
297
- a `RangeError` with `position`, `length`, and `size` properties. This applies to
298
- reads, peeks, tokens, and skips, even with `mayBeLess: true`. Invalid lengths,
299
- offsets, and unsafe offset arithmetic reject before allocating token buffers or
300
- consuming input. The source's token allocation and stream lookahead limits still
301
- apply through nested views.
302
-
303
- A request inside the view that encounters truncated underlying input rejects
304
- with `EndOfStreamError`. Buffer reads and peeks with `mayBeLess: true` may return
305
- fewer bytes within the requested range; token reads and peeks always require a
306
- complete token. A failed exact read may have consumed part of the input; the
307
- shared cursor reflects the bytes consumed. Peeks do not advance that cursor.
308
-
309
- `ignore()` preserves the source's skip behavior, which may return a shorter
310
- count or reject at EOF. Use `consumeRemainder()` when the entire declared
311
- remainder must exist: it returns the number consumed, or rejects with
312
- `EndOfStreamError`. On random-access sources it verifies the final byte and
313
- advances the cursor without reading the whole remainder. On streams it drains
314
- the remainder using the source's bounded skip buffers.
315
-
316
- The source, parent, child, and sibling views share one cursor. Use them
317
- sequentially, and close a child before resuming its parent. `close()` is
318
- idempotent, does not drain the remainder, and never closes or aborts the source.
319
- After a partially consumed child closes, the parent resumes at that same byte,
320
- not at the child's declared end. Call `child.consumeRemainder()` before closing
321
- when the parent should resume after the entire child range. Closed views reject
322
- further operations and keep their last local position; closing a parent view
323
- also prevents its children from being used.
324
-
325
- Overlapping operations through a view or its parent/child chain are rejected;
326
- `close()` also rejects while that view has an active operation. Direct operations
327
- on the original source, or separate views created from it, cannot be coordinated
328
- by a view, so callers must keep those sequential too. Explicit `abort()`
329
- propagates to the shared source to cancel pending input and affects its other
330
- users; it also closes the view.
331
-
332
- ### `Tokenizer` object
333
- The *tokenizer* is an abstraction of a [stream](https://nodejs.org/api/stream.html), file or [Uint8Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), allowing _reading_ or _peeking_ from the stream.
334
- It can also be translated in chunked reads, as done in [@tokenizer/http](https://github.com/Borewit/tokenizer-http);
335
-
336
- #### Key Features:
337
-
338
- - Supports seeking within the stream using `tokenizer.ignore()`.
339
- - Offers `peek` methods to preview data without advancing the read pointer.
340
- - Maintains the read position via `tokenizer.position`.
341
- - Supports random access for buffer, blob, and file tokenizers.
342
-
343
- #### Tokenizer functions
344
-
345
- _Read_ methods advance the stream pointer, while _peek_ methods do not.
346
-
347
- There are two kinds of functions:
348
- 1. *read* methods: used to read a *token* or bytes into a buffer from the [*tokenizer*](#tokenizer-object). After a successful read, `tokenizer.position` is the starting position of the read plus the number of bytes read. An explicit position can skip ahead or, for random-access tokenizers, move backwards.
349
- 2. *peek* methods: same as the read, but it will *not* advance the pointer. It allows to read (peek) ahead.
350
-
351
- Reads and peeks require the full requested length unless `mayBeLess: true` is passed to
352
- `readBuffer` or `peekBuffer`. Otherwise, insufficient input rejects with the exported
353
- `EndOfStreamError`. Token methods always require the full token.
354
-
355
- A failed exact stream read can consume partial input and advance `tokenizer.position`
356
- by the number of bytes consumed. A failed exact stream peek leaves `tokenizer.position`
357
- unchanged and retains the partial bytes for subsequent reads. Caller-provided buffers
358
- may contain partial data even when the operation rejects.
359
-
360
- #### `readBuffer` function
361
-
362
- Read data from the _tokenizer_ into provided "buffer" (`Uint8Array`).
363
- `readBuffer(buffer, options?)`
364
-
365
- ```ts
366
- readBuffer(buffer: Uint8Array, options?: IReadChunkOptions): Promise<number>;
367
- ```
368
-
369
- | Parameter | Type | Description |
370
- |------------|----------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
371
- | buffer | [Buffer](https://nodejs.org/api/buffer.html) &#124; Uint8Array | Target buffer to write the data read to |
372
- | options | [IReadChunkOptions](#ireadchunkoptions-interface) | Optional settings for the length, position, and handling of partial reads |
373
-
374
- Return promise with number of bytes read.
375
- The number of bytes read may be less than requested if the `mayBeLess` flag is set.
376
-
377
- #### `peekBuffer` function
378
-
379
- Peek (read ahead), from [*tokenizer*](#tokenizer-object), into the buffer without advancing the stream pointer.
380
-
381
- ```ts
382
- peekBuffer(uint8Array: Uint8Array, options?: IReadChunkOptions): Promise<number>;
383
- ```
384
-
385
- | Parameter | Type | Description |
386
- |------------|-----------------------------------------|-----------------------------------------------------|
387
- | buffer | Buffer &#124; Uint8Array | Target buffer to write the data read (peeked) to. |
388
- | options | [IReadChunkOptions](#ireadchunkoptions-interface) | Optional settings for the length, position, and handling of partial reads |
389
-
390
- Return value `Promise<number>` Promise with number of bytes read. The number of bytes read may be less if the `mayBeLess` flag was set.
391
-
392
- For streams with a known size, a nonempty peek starting at or beyond that size
393
- rejects with `EndOfStreamError`, or returns zero with `mayBeLess: true`, before
394
- allocating lookahead or reading input. This also applies through tokenizer views.
395
- Peeks starting inside the advertised input retain their partial-read behavior
396
- when they cross EOF. Zero-length peeks remain no-ops.
397
-
398
- #### `readToken` function
399
-
400
- Read a *token* from the tokenizer-stream.
401
-
402
- ```ts
403
- readToken<Value>(token: IGetToken<Value>, position: number = this.position): Promise<Value>
404
- ```
405
-
406
- | Parameter | Type | Description |
407
- |------------|-------------------------|---------------------------------------------------------------------------------------------------------------------- |
408
- | token | [IGetToken](#token-object) | Token to read from the tokenizer-stream. |
409
- | position? | number | Offset where to begin reading. Defaults to `tokenizer.position` when omitted. |
410
-
411
- Returns a `Promise<Value>` resolving to the decoded token value. Rejects with `EndOfStreamError` if fewer than `token.len` bytes are available.
412
-
413
- #### `peekToken` function
414
-
415
- Peek a *token* from the [*tokenizer*](#tokenizer-object).
416
-
417
- ```ts
418
- peekToken<Value>(token: IGetToken<Value>, position: number | null = this.position): Promise<Value>
419
- ```
420
-
421
- | Parameter | Type | Description |
422
- |------------|----------------------------|-------------------------------------------------------------------------------------------------------------------------|
423
- | token | [IGetToken](#token-object) | Token to peek from the tokenizer-stream. |
424
- | position? | number &#124; null | Offset where to begin peeking. Defaults to `tokenizer.position` when omitted or `null`. |
425
-
426
- Return a promise with the token value peeked from the [*tokenizer*](#tokenizer-object).
427
-
428
- #### `readNumber` function
429
-
430
- Read a numeric [*token*](#token-object) from the [*tokenizer*](#tokenizer-object).
431
-
432
- ```ts
433
- readNumber(token: IToken<number>): Promise<number>
434
- ```
435
-
436
- | Parameter | Type | Description |
437
- |------------|---------------------------------|----------------------------------------------------|
438
- | token | [IToken<number>](#token-object) | Numeric token to read from the tokenizer-stream. |
439
-
440
- A promise resolving to a numeric value read and decoded from the *tokenizer-stream*.
441
- Uses a reusable 8-byte buffer, so `token.len` must be at most 8 bytes.
442
- For larger tokens or values such as `bigint`, use `readToken` instead.
443
-
444
- #### `peekNumber` function
445
-
446
- Peek a numeric [*token*](#token-object) without advancing `tokenizer.position`.
447
-
448
- ```ts
449
- peekNumber(token: IToken<number>): Promise<number>
450
- ```
451
-
452
- Returns a promise resolving to the decoded numeric value.
453
- Like `readNumber`, rejects with `EndOfStreamError` if the token cannot be read in full.
454
- The same 8-byte token limit applies; use `peekToken` for larger tokens or values such as `bigint`.
455
-
456
- #### `ignore` function
457
-
458
- Advance the offset pointer by the given number of bytes.
459
-
460
- ```ts
461
- ignore(length: number): Promise<number>
462
- ```
463
-
464
- | Parameter | Type | Description |
465
- |------------|--------|------------------------------------------------------------------|
466
- | length | number | Non-negative safe integer number of bytes to ignore. Advances `tokenizer.position`. |
467
-
468
- Returns a promise resolving to the number of bytes ignored.
469
- Buffer, blob, and file tokenizers stop at the known file size. Stream tokenizers reject with `EndOfStreamError` if the requested bytes are unavailable.
470
- When a stream has a known size, skips beyond that size reject before allocating
471
- a skip buffer or consuming input, including skips through tokenizer views.
472
- If the size is unknown, or the stream ends before its advertised size, a failed
473
- skip may consume available bytes before rejecting; `position` reflects those bytes.
474
-
475
- #### `close` function
476
- Clean up resources, such as closing a file pointer if applicable.
477
-
478
- ```ts
479
- close(): Promise<void>
480
- ```
481
-
482
- Await this method when finished with a tokenizer. For Node.js streams, it does not destroy the underlying stream; the caller remains responsible for its lifecycle.
483
-
484
- For buffer, blob, and file tokenizers, repeated or concurrent `close()` calls
485
- share one cleanup operation and invoke `onClose` at most once. If cleanup or the
486
- callback fails, subsequent calls reject with the same error. Calling `abort()`
487
- before `close()` does not suppress cleanup or the callback.
488
-
489
- Closing or aborting a Node.js stream tokenizer removes its reader-retaining
490
- stream listeners. After the source ends, shared error and close guards may remain
491
- until the source emits either event, including after tokenizer closure; these
492
- guards do not retain the tokenizer. The caller remains responsible for handling
493
- subsequent source errors.
494
-
495
- For Web streams, `close()` releases the reader lock. A BYOB reader leaves the source uncancelled, allowing another reader to continue reading it. A default reader cancels the source before releasing the lock, discarding remaining data. Bytes already read into tokenizer buffers, including peeked bytes, are not returned to the source.
496
-
497
- #### `abort` function
498
-
499
- Abort pending asynchronous stream operations.
500
-
501
- ```ts
502
- abort(): Promise<void>
503
- ```
504
-
505
- This is a no-op for buffer, blob, and file tokenizers.
506
-
507
- For Node.js streams, pending reads reject with the exported `AbortError`, and buffered
508
- peek data is discarded. The underlying stream is not destroyed. Calling `close()` or
509
- aborting the configured `AbortSignal` has the same effect on pending Node.js stream reads.
510
-
511
- For Web streams, `abort()` releases a BYOB reader's lock without cancelling the source. A default reader cancels the source but keeps its lock until `close()` is called. An `AbortSignal` invokes the same abort behavior.
512
-
513
- #### `supportsRandomAccess` function
514
-
515
- ```ts
516
- supportsRandomAccess(): boolean
517
- ```
518
-
519
- Returns `true` for buffer, blob, and file tokenizers, and `false` for stream tokenizers.
520
- When random access is supported, read and peek methods can use positions before `tokenizer.position`.
521
-
522
- #### `isRandomAccessTokenizer` helper
523
-
524
- Exported from both `strtok3` and `strtok3/core`:
525
-
526
- ```ts
527
- import { isRandomAccessTokenizer, type ITokenizer } from 'strtok3';
528
-
529
- function skipToEnd(tokenizer: ITokenizer): void {
530
- if (isRandomAccessTokenizer(tokenizer)) {
531
- tokenizer.setPosition(tokenizer.fileInfo.size);
532
- }
533
- }
534
- ```
535
-
536
- Narrows `ITokenizer` to `IRandomAccessTokenizer` by checking `supportsRandomAccess()`,
537
- a callable `setPosition`, and a numeric file size. A known size alone does not imply
538
- random access. Existing third-party implementations can keep returning a boolean
539
- from `supportsRandomAccess()` without changing their interface.
540
-
541
- #### `setPosition` function
542
-
543
- Available on buffer, blob, and file tokenizers (`IRandomAccessTokenizer`).
544
-
545
- ```ts
546
- setPosition(position: number): void
547
- ```
548
-
549
- Sets the current byte offset without reading data. The position must be a
550
- non-negative safe integer; invalid positions throw `RangeError` without changing
551
- the cursor. Seeking past EOF is allowed. At or past EOF, `ignore()` returns zero
552
- without moving the cursor backward, subject to safe end-position arithmetic.
553
-
554
- #### `Tokenizer` attributes
555
-
556
- - `fileInfo`
557
-
558
- Object containing optional file information, see [IFileInfo](#ifileinfo-interface).
559
-
560
- - `position`
561
-
562
- Pointer to the current position in the [*tokenizer*](#tokenizer-object) stream.
563
- For stream tokenizers, a *position* provided to a _read_ or _peek_ method must be at least this value.
564
- Buffer, blob, and file tokenizers also support earlier positions.
565
-
566
- ### `ITokenizerOptions` interface
567
-
568
- Set these options once when creating a tokenizer. The configured limit applies to subsequent
569
- reads and peeks for that tokenizer; no per-read limit is needed. Each attribute is optional:
570
-
571
- | Attribute | Type | Description |
572
- |-----------|------|-------------|
573
- | maxBufferSize | number | Maximum bytes in a dynamically sized tokenizer buffer or stream lookahead span. Disabled by default (`Infinity`). Must be a positive safe integer or `Infinity`. |
574
- | fileInfo | [IFileInfo](#ifileinfo-interface) | Additional metadata about the input |
575
- | onClose | `() => Promise<void>` | Asynchronous callback invoked when a buffer, blob, or file tokenizer is closed |
576
- | abortSignal | [AbortSignal](https://developer.mozilla.org/en-US/docs/Web/API/AbortSignal) | Signal used to abort asynchronous stream operations |
577
-
578
- Creating a tokenizer with an already-aborted `abortSignal` throws or rejects with `AbortError`
579
- before acquiring file handles or stream readers. Signal listeners are removed when the signal
580
- fires or the tokenizer is closed, so closed tokenizers can be collected even when a signal is reused.
581
-
582
- When `maxBufferSize` is configured, `readToken()` and `peekToken()` reject oversized buffers with `BufferSizeError`
583
- before allocating or consuming input. The error exposes `requestedSize` and `maxBufferSize`.
584
- Token lengths and positions must be non-negative safe integers. When the input size is known,
585
- a token extending beyond the input rejects with `EndOfStreamError` before allocation.
586
-
587
- For streams, the lookahead limit includes bytes between the current position and the requested
588
- peek position. `mayBeLess: true` does not bypass this limit. With a finite cap, reads into
589
- caller-provided buffers, Blob reads and `ignore()` use bounded chunks where internal buffers
590
- are needed, so their total requested length may exceed `maxBufferSize`.
591
-
592
- This limit does not cap total process memory, caller-owned input/output buffers, or allocations
593
- inside a token's `get()` method. Stream sources may also supply chunks larger than this limit.
594
- The cap is opt-in to preserve existing buffer sizes. Applications parsing untrusted input should
595
- set a finite limit, for example 64 MiB. Omit the option or set it to `Infinity` to disable the cap.
596
-
597
- ```js
598
- import { BufferSizeError, fromFile } from 'strtok3';
599
-
600
- const tokenizer = await fromFile('somefile.bin', { maxBufferSize: 64 * 1024 * 1024 });
601
- try {
602
- // Read or peek tokens here.
603
- } catch (error) {
604
- if (error instanceof BufferSizeError) {
605
- console.error(`Requested ${error.requestedSize} bytes; limit is ${error.maxBufferSize}`);
606
- } else {
607
- throw error;
608
- }
609
- } finally {
610
- await tokenizer.close();
611
- }
612
- ```
613
-
614
- ### `IFromFileOptions` interface
615
-
616
- Extends [ITokenizerOptions](#itokenizeroptions-interface) for `fromFile()`.
617
-
618
- | Attribute | Type | Description |
619
- |-----------|------|-------------|
620
- | regularFileOnly | `boolean` | When `true`, opens with `O_RDONLY \| O_NONBLOCK` and checks that the opened handle refers to a regular file. Defaults to `false`, preserving existing behavior. |
621
-
622
- Use this option when non-regular inputs, such as FIFOs, should be rejected without waiting for a writer. Validation uses the opened handle, so replacing the pathname before opening does not bypass the check. Symbolic links to regular files are accepted.
623
-
624
- If an opened handle is not a regular file, `fromFile()` closes it and rejects with the exported `NotRegularFileError`. Its `path` property identifies the requested path. Opening errors, stat errors, and abort errors continue to propagate; any handle acquired by the factory is closed if setup fails. After success, the caller must close the tokenizer.
625
-
626
- ```js
627
- import { fromFile, NotRegularFileError } from 'strtok3';
628
-
629
- try {
630
- const tokenizer = await fromFile('somefile.bin', { regularFileOnly: true });
631
- try {
632
- // Parse the regular file.
633
- } finally {
634
- await tokenizer.close();
635
- }
636
- } catch (error) {
637
- if (!(error instanceof NotRegularFileError)) {
638
- throw error;
639
- }
640
- // Handle an input that is not a regular file.
641
- }
642
- ```
643
-
644
- ### `IReadChunkOptions` interface
645
-
646
- Each attribute is optional:
647
-
648
- | Attribute | Type | Description |
649
- |-----------|---------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
650
- | length | number | Requested number of bytes to read or peek. Must be a non-negative safe integer no larger than the target buffer length. Defaults to the target buffer length. |
651
- | position | number | Byte offset to read or peek from. Must be a non-negative safe integer. Defaults to [tokenizer.position](#tokenizer-attributes) when omitted. Earlier positions require random access. |
652
- | mayBeLess | boolean | If `true`, allows fewer than the requested number of bytes to be read or peeked instead of throwing `EndOfStreamError`. Defaults to `false`. |
653
-
654
- Invalid lengths or positions, including a `position + length` that exceeds the safe
655
- integer range, reject with `RangeError`. Requesting an earlier position on a tokenizer
656
- without random access rejects with `Error`. Data is written starting at index 0 of the
657
- target buffer. To write at an offset, pass `buffer.subarray(offset)` as the target buffer.
658
-
659
- Example usage:
660
- ```js
661
- const bytesPeeked = await tokenizer.peekBuffer(buffer, {mayBeLess: true});
662
- ```
663
-
664
- ### `IFileInfo` interface
665
-
666
- Provides optional metadata about the file being tokenized.
667
-
668
- | Attribute | Type | Description |
669
- |-----------|---------|---------------------------------------------------------------------------------------------------|
670
- | size | number | File size in bytes |
671
- | mimeType | string | [MIME-type](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types) of file. |
672
- | path | string | File path |
673
- | url | string | File URL |
674
-
675
- ### `Token` object
676
-
677
- The *token* is basically a description of what to read from the [*tokenizer-stream*](#tokenizer-object).
678
- A basic set of *token types* can be found here: [*token-types*](https://github.com/Borewit/token-types).
679
-
680
- A token is something which implements the following interface:
681
- ```ts
682
- export interface IGetToken<T> {
683
-
684
- /**
685
- * Length in bytes of encoded value
686
- */
687
- len: number;
688
-
689
- /**
690
- * Decode value from buffer at offset
691
- * @param buf Buffer to read the decoded value from
692
- * @param off Decode offset
693
- */
694
- get(buf: Uint8Array, off: number): T;
695
- }
696
- ```
697
- The *tokenizer* reads `token.len` bytes from the *tokenizer-stream* into a Buffer.
698
- The `token.get` will be called with the Buffer. `token.get` is responsible for conversion from the buffer to the desired output type.
699
-
700
- ### Working with a fetch response
701
-
702
- Pass the response's [WHATWG readable stream](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream) directly to `fromWebStream`.
703
-
704
- ```js
705
- import { fromWebStream } from 'strtok3';
706
- import * as Token from 'token-types';
707
-
708
- (async () => {
709
-
710
- const response = await fetch(url);
711
- if (!response.ok || !response.body) {
712
- throw new Error(`Cannot read response: ${response.status}`);
713
- }
714
-
715
- const tokenizer = fromWebStream(response.body);
716
- try {
717
- const myNumber = await tokenizer.readToken(Token.UINT8);
718
- console.log(`My number: ${myNumber}`);
719
- } finally {
720
- await tokenizer.close();
721
- }
722
- })();
723
- ```
724
-
725
- ## Dependencies
726
-
727
- Dependencies:
728
- - [@tokenizer/token](https://github.com/Borewit/tokenizer-token): Provides token definitions and utilities used by `strtok3` for interpreting binary data.
729
-
730
- ## Contributing
731
-
732
- See [the contribution guide](CONTRIBUTING.md) for code style and development commands.
733
-
734
- ## Licence
735
-
736
- This project is licensed under the [MIT License](LICENSE.txt). Feel free to use, modify, and distribute as needed.