@wener/utils 1.1.51 → 1.1.53

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 (499) hide show
  1. package/lib/arrays/MaybeArray.js +58 -8
  2. package/lib/arrays/arrayFromAsync.js +254 -6
  3. package/lib/asyncs/AsyncInterval.js +145 -9
  4. package/lib/asyncs/MaybePromise.js +0 -2
  5. package/lib/asyncs/Promises.js +95 -48
  6. package/lib/asyncs/createAsyncIterator.js +313 -23
  7. package/lib/asyncs/createLazyPromise.js +72 -31
  8. package/lib/asyncs/createLazyPromise.test.js +367 -0
  9. package/lib/asyncs/firstOfAsyncIterator.js +6 -6
  10. package/lib/asyncs/generatorOfStream.js +125 -14
  11. package/lib/asyncs/isIterator.js +1 -3
  12. package/lib/asyncs/isPromise.js +2 -4
  13. package/lib/asyncs/isThenable.js +0 -2
  14. package/lib/asyncs/nextOfAsyncIterator.js +15 -9
  15. package/lib/asyncs/promiseOfCallback.js +2 -4
  16. package/lib/asyncs/timeout.js +122 -13
  17. package/lib/browsers/copy.js +7 -8
  18. package/lib/browsers/download.js +215 -40
  19. package/lib/browsers/getFileFromDataTransfer.js +17 -14
  20. package/lib/browsers/loaders.js +251 -18
  21. package/lib/crypto/base.js +3 -3
  22. package/lib/crypto/getNodeCrypto.js +3 -5
  23. package/lib/crypto/hashing.js +236 -30
  24. package/lib/crypto/hashing.test.js +323 -0
  25. package/lib/crypto/md5.bench.js +11 -11
  26. package/lib/crypto/md5.d.js +0 -2
  27. package/lib/crypto/md5.js +0 -2
  28. package/lib/crypto/md5.test.js +7 -0
  29. package/lib/crypto/pem/pem.js +197 -35
  30. package/lib/crypto/pem/pem.test.js +104 -0
  31. package/lib/crypto/randomUUIDv7.js +0 -2
  32. package/lib/crypto/ulid.js +84 -48
  33. package/lib/crypto/ulid.test.js +115 -0
  34. package/lib/emitter/types.js +0 -2
  35. package/lib/errors/DetailError.js +297 -0
  36. package/lib/errors/Errors.js +2 -202
  37. package/lib/errors/Errors.mod.js +206 -0
  38. package/lib/errors/Errors.test.js +24 -0
  39. package/lib/fetch/HttpStatus.js +1 -3
  40. package/lib/fetch/createFetchWith.js +188 -19
  41. package/lib/fetch/createFetchWithLogging.js +17 -16
  42. package/lib/fetch/createFetchWithRetry.js +40 -24
  43. package/lib/fetch/dumpRequest.js +467 -41
  44. package/lib/fetch/dumpRequest.test.js +384 -0
  45. package/lib/fetch/dumpResponse.js +271 -16
  46. package/lib/fetch/dumpResponse.test.js +393 -0
  47. package/lib/fetch/http.types.js +0 -2
  48. package/lib/fetch/index.js +5 -7
  49. package/lib/fetch/isTextContentType.js +5 -0
  50. package/lib/fetch/resolveRequest.js +7 -0
  51. package/lib/fetch/types.js +0 -2
  52. package/lib/i18n/createTranslate.js +40 -20
  53. package/lib/i18n/createTranslate.test.js +177 -0
  54. package/lib/index.js +74 -76
  55. package/lib/io/AbstractEncoding.js +0 -2
  56. package/lib/io/ArrayBuffer.test-d.js +4 -6
  57. package/lib/io/ArrayBuffers.base64.test.js +60 -0
  58. package/lib/io/ArrayBuffers.js +2 -334
  59. package/lib/io/ArrayBuffers.mod.js +531 -0
  60. package/lib/io/ArrayBuffers.test.js +77 -0
  61. package/lib/io/Buffer.js +190 -20
  62. package/lib/io/Buffer.test.js +22 -0
  63. package/lib/io/ByteBuffer.js +752 -441
  64. package/lib/io/ByteBuffer.test.js +184 -0
  65. package/lib/io/base64.js +17 -19
  66. package/lib/io/dump.js +16 -16
  67. package/lib/io/isBuffer.js +2 -3
  68. package/lib/io/isBuffer.test.js +8 -0
  69. package/lib/io/isTransferable.js +16 -8
  70. package/lib/io/isTransferable.test.js +17 -0
  71. package/lib/io/parseDataUri.js +288 -40
  72. package/lib/io/parseDataUri.test.js +286 -0
  73. package/lib/io/types.js +1 -0
  74. package/lib/langs/AsyncCloser.js +270 -34
  75. package/lib/langs/Closer.js +95 -29
  76. package/lib/langs/MaybeFunction.js +38 -5
  77. package/lib/langs/classOf.js +0 -2
  78. package/lib/langs/deepEqual.js +82 -22
  79. package/lib/langs/deepEqual.test.js +11 -0
  80. package/lib/langs/deepFreeze.js +28 -9
  81. package/lib/langs/getGlobalStates.js +14 -10
  82. package/lib/langs/getObjectId.js +4 -6
  83. package/lib/langs/ifPresent.js +0 -2
  84. package/lib/langs/isClass.js +0 -2
  85. package/lib/langs/isDefined.js +0 -2
  86. package/lib/langs/isEmptyObject.js +1 -3
  87. package/lib/langs/isFunction.js +0 -2
  88. package/lib/langs/isNil.js +3 -0
  89. package/lib/langs/isPlainObject.js +2 -4
  90. package/lib/langs/langs.test.js +126 -0
  91. package/lib/langs/memoize.js +11 -7
  92. package/lib/langs/mixin.js +7 -4
  93. package/lib/langs/mixin.test.js +135 -0
  94. package/lib/langs/parseBoolean.js +11 -8
  95. package/lib/langs/shallowClone.js +5 -3
  96. package/lib/langs/shallowEqual.js +8 -6
  97. package/lib/libs/ms.js +28 -26
  98. package/lib/libs/ms.test.js +301 -0
  99. package/lib/logger/const.js +15 -0
  100. package/lib/logger/index.js +1 -0
  101. package/lib/logger/types.js +1 -0
  102. package/lib/maths/clamp.js +81 -12
  103. package/lib/maths/clamp.test.js +186 -0
  104. package/lib/maths/createRandom.test.js +36 -0
  105. package/lib/maths/random.js +162 -13
  106. package/lib/modules/isModule.js +0 -2
  107. package/lib/modules/parseModuleId.js +14 -15
  108. package/lib/modules/parseModuleId.test.js +153 -0
  109. package/lib/objects/computeIfAbsent.js +8 -3
  110. package/lib/objects/get.js +26 -8
  111. package/lib/objects/get.test-d.js +23 -25
  112. package/lib/objects/merge/index.js +1 -3
  113. package/lib/objects/merge/isMergeableObject.js +5 -3
  114. package/lib/objects/merge/merge.js +82 -26
  115. package/lib/objects/merge/merge.test.js +1397 -0
  116. package/lib/objects/parseObjectPath.js +47 -15
  117. package/lib/objects/parseObjectPath.test.js +138 -0
  118. package/lib/objects/set.js +25 -19
  119. package/lib/objects/set.test.js +522 -0
  120. package/lib/schema/typebox/index.js +2 -3
  121. package/lib/schema/typebox/typebox.js +6 -6
  122. package/lib/scripts/getGenerateContext.js +386 -77
  123. package/lib/server/crypto/md5.js +0 -2
  124. package/lib/server/fetch/createFetchWithProxy.js +2 -4
  125. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js +258 -31
  126. package/lib/server/fetch/createFetchWithProxyByUndici.js +307 -49
  127. package/lib/server/getPackageDir.js +2 -3
  128. package/lib/server/index.js +5 -7
  129. package/lib/server/jsdom.js +1 -3
  130. package/lib/server/node-fetch.js +2 -4
  131. package/lib/server/polyfill/polyfillBrowser.js +163 -9
  132. package/lib/server/polyfill/polyfillBrowser.test.js +164 -0
  133. package/lib/server/polyfill/polyfillCrypto.js +157 -9
  134. package/lib/server/polyfill/polyfillFetch.js +13 -13
  135. package/lib/server/polyfill/polyfillJsDom.js +264 -58
  136. package/lib/server/polyfill/polyfillWebSocket.js +11 -11
  137. package/lib/server/ws.js +1 -3
  138. package/lib/strings/bytes.test.js +327 -0
  139. package/lib/strings/camelCase.js +23 -14
  140. package/lib/strings/formatBytes.js +29 -20
  141. package/lib/strings/parseBytes.js +54 -0
  142. package/lib/strings/renderTemplate.js +17 -12
  143. package/lib/strings/renderTemplate.test.js +104 -0
  144. package/lib/typedoc.js +2 -4
  145. package/lib/types.d.js +0 -2
  146. package/lib/validations/asserts.js +0 -2
  147. package/lib/validations/isUUID.js +0 -2
  148. package/lib/validations/isUUID.test.js +87 -0
  149. package/lib/validations/parseTimestamp.js +12 -7
  150. package/lib/validations/parseTimestamp.test.js +6 -0
  151. package/lib/web/getGlobalThis.js +3 -4
  152. package/lib/web/getRandomValues.js +28 -20
  153. package/lib/web/randomUUID.js +7 -8
  154. package/lib/web/requestIdleCallback.js +13 -9
  155. package/lib/web/structuredClone.js +35 -28
  156. package/lib/web/structuredClone.test.js +81 -0
  157. package/package.json +9 -14
  158. package/src/arrays/MaybeArray.ts +22 -22
  159. package/src/arrays/arrayFromAsync.ts +3 -3
  160. package/src/asyncs/AsyncInterval.ts +8 -8
  161. package/src/asyncs/Promises.ts +51 -51
  162. package/src/asyncs/createAsyncIterator.ts +33 -33
  163. package/src/asyncs/createLazyPromise.test.ts +73 -73
  164. package/src/asyncs/createLazyPromise.ts +68 -73
  165. package/src/asyncs/firstOfAsyncIterator.ts +5 -5
  166. package/src/asyncs/generatorOfStream.ts +12 -12
  167. package/src/asyncs/isIterator.ts +1 -1
  168. package/src/asyncs/isThenable.ts +2 -2
  169. package/src/asyncs/nextOfAsyncIterator.ts +20 -20
  170. package/src/asyncs/promiseOfCallback.ts +13 -13
  171. package/src/asyncs/timeout.ts +23 -23
  172. package/src/browsers/copy.ts +48 -48
  173. package/src/browsers/download.ts +38 -36
  174. package/src/browsers/getFileFromDataTransfer.ts +35 -35
  175. package/src/browsers/loaders.ts +49 -49
  176. package/src/crypto/base.ts +3 -3
  177. package/src/crypto/getNodeCrypto.ts +2 -2
  178. package/src/crypto/hashing.test.ts +33 -47
  179. package/src/crypto/hashing.ts +67 -67
  180. package/src/crypto/md5.bench.ts +20 -24
  181. package/src/crypto/md5.test.ts +3 -3
  182. package/src/crypto/pem/pem.test.ts +26 -42
  183. package/src/crypto/pem/pem.ts +65 -65
  184. package/src/crypto/ulid.test.ts +31 -31
  185. package/src/crypto/ulid.ts +116 -116
  186. package/src/emitter/types.ts +6 -6
  187. package/src/errors/DetailError.ts +151 -0
  188. package/src/errors/Errors.mod.ts +104 -0
  189. package/src/errors/Errors.test.ts +15 -15
  190. package/src/errors/Errors.ts +1 -247
  191. package/src/fetch/HttpStatus.ts +77 -77
  192. package/src/fetch/createFetchWith.ts +25 -25
  193. package/src/fetch/createFetchWithLogging.ts +12 -15
  194. package/src/fetch/createFetchWithRetry.ts +79 -79
  195. package/src/fetch/dumpRequest.test.ts +176 -0
  196. package/src/fetch/dumpRequest.ts +149 -52
  197. package/src/fetch/dumpResponse.test.ts +160 -0
  198. package/src/fetch/dumpResponse.ts +48 -20
  199. package/src/fetch/http.types.ts +35 -35
  200. package/src/fetch/isTextContentType.ts +12 -0
  201. package/src/fetch/resolveRequest.ts +1 -0
  202. package/src/fetch/types.ts +2 -2
  203. package/src/i18n/createTranslate.test.ts +90 -113
  204. package/src/i18n/createTranslate.ts +55 -55
  205. package/src/index.ts +17 -19
  206. package/src/io/AbstractEncoding.ts +12 -12
  207. package/src/io/ArrayBuffer.test-d.ts +1 -1
  208. package/src/io/ArrayBuffers.base64.test.ts +52 -52
  209. package/src/io/ArrayBuffers.mod.ts +670 -0
  210. package/src/io/ArrayBuffers.test.ts +14 -14
  211. package/src/io/ArrayBuffers.ts +1 -446
  212. package/src/io/Buffer.test.ts +17 -17
  213. package/src/io/Buffer.ts +17 -17
  214. package/src/io/ByteBuffer.test.ts +37 -37
  215. package/src/io/ByteBuffer.ts +574 -566
  216. package/src/io/base64.ts +46 -44
  217. package/src/io/dump.ts +22 -22
  218. package/src/io/isBuffer.test.ts +2 -2
  219. package/src/io/isBuffer.ts +1 -1
  220. package/src/io/isTransferable.test.ts +4 -4
  221. package/src/io/isTransferable.ts +29 -29
  222. package/src/io/parseDataUri.test.ts +22 -27
  223. package/src/io/parseDataUri.ts +57 -57
  224. package/src/io/types.ts +13 -0
  225. package/src/langs/AsyncCloser.ts +34 -34
  226. package/src/langs/Closer.ts +28 -28
  227. package/src/langs/MaybeFunction.ts +5 -5
  228. package/src/langs/classOf.ts +1 -1
  229. package/src/langs/deepEqual.test.ts +1 -12
  230. package/src/langs/deepEqual.ts +82 -82
  231. package/src/langs/deepFreeze.ts +11 -11
  232. package/src/langs/getGlobalStates.ts +16 -16
  233. package/src/langs/getObjectId.ts +10 -13
  234. package/src/langs/ifPresent.ts +2 -2
  235. package/src/langs/isClass.ts +1 -1
  236. package/src/langs/isDefined.ts +1 -1
  237. package/src/langs/isEmptyObject.ts +1 -1
  238. package/src/langs/isFunction.ts +1 -1
  239. package/src/langs/isNil.ts +3 -0
  240. package/src/langs/isPlainObject.ts +4 -4
  241. package/src/langs/langs.test.ts +18 -18
  242. package/src/langs/memoize.ts +21 -21
  243. package/src/langs/mixin.test.ts +22 -26
  244. package/src/langs/mixin.ts +6 -9
  245. package/src/langs/parseBoolean.ts +30 -26
  246. package/src/langs/shallowClone.ts +11 -11
  247. package/src/langs/shallowEqual.ts +19 -19
  248. package/src/libs/ms.test.ts +274 -274
  249. package/src/libs/ms.ts +137 -137
  250. package/src/logger/const.ts +18 -0
  251. package/src/logger/index.ts +2 -0
  252. package/src/logger/types.ts +10 -0
  253. package/src/maths/clamp.test.ts +18 -18
  254. package/src/maths/clamp.ts +17 -17
  255. package/src/maths/createRandom.test.ts +12 -0
  256. package/src/maths/random.ts +50 -14
  257. package/src/modules/isModule.ts +4 -4
  258. package/src/modules/parseModuleId.test.ts +61 -68
  259. package/src/modules/parseModuleId.ts +29 -43
  260. package/src/objects/computeIfAbsent.ts +10 -10
  261. package/src/objects/get.test-d.ts +33 -51
  262. package/src/objects/get.ts +31 -31
  263. package/src/objects/merge/isMergeableObject.ts +5 -5
  264. package/src/objects/merge/merge.test.ts +658 -880
  265. package/src/objects/merge/merge.ts +84 -84
  266. package/src/objects/parseObjectPath.test.ts +13 -13
  267. package/src/objects/parseObjectPath.ts +25 -25
  268. package/src/objects/set.test.ts +271 -366
  269. package/src/objects/set.ts +36 -36
  270. package/src/schema/typebox/typebox.ts +20 -26
  271. package/src/scripts/getGenerateContext.ts +79 -79
  272. package/src/server/crypto/md5.ts +1 -1
  273. package/src/server/fetch/createFetchWithProxyByNodeFetch.ts +28 -31
  274. package/src/server/fetch/createFetchWithProxyByUndici.ts +63 -69
  275. package/src/server/getPackageDir.ts +7 -7
  276. package/src/server/polyfill/polyfillBrowser.test.ts +10 -10
  277. package/src/server/polyfill/polyfillBrowser.ts +3 -3
  278. package/src/server/polyfill/polyfillCrypto.ts +6 -6
  279. package/src/server/polyfill/polyfillFetch.ts +11 -21
  280. package/src/server/polyfill/polyfillJsDom.ts +59 -71
  281. package/src/server/polyfill/polyfillWebSocket.ts +14 -14
  282. package/src/strings/bytes.test.ts +69 -0
  283. package/src/strings/camelCase.ts +58 -63
  284. package/src/strings/formatBytes.ts +50 -29
  285. package/src/strings/parseBytes.ts +66 -0
  286. package/src/strings/renderTemplate.test.ts +10 -17
  287. package/src/strings/renderTemplate.ts +19 -22
  288. package/src/types.d.ts +9 -9
  289. package/src/validations/asserts.ts +8 -8
  290. package/src/validations/isUUID.test.ts +8 -8
  291. package/src/validations/isUUID.ts +1 -1
  292. package/src/validations/parseTimestamp.test.ts +2 -2
  293. package/src/validations/parseTimestamp.ts +21 -21
  294. package/src/web/getGlobalThis.ts +6 -6
  295. package/src/web/getRandomValues.ts +29 -29
  296. package/src/web/randomUUID.ts +5 -5
  297. package/src/web/requestIdleCallback.ts +7 -10
  298. package/src/web/structuredClone.test.ts +8 -8
  299. package/src/web/structuredClone.ts +62 -62
  300. package/tsconfig.json +35 -34
  301. package/lib/arrays/MaybeArray.js.map +0 -1
  302. package/lib/arrays/arrayFromAsync.js.map +0 -1
  303. package/lib/asyncs/AsyncInterval.js.map +0 -1
  304. package/lib/asyncs/MaybePromise.js.map +0 -1
  305. package/lib/asyncs/Promises.js.map +0 -1
  306. package/lib/asyncs/createAsyncIterator.js.map +0 -1
  307. package/lib/asyncs/createLazyPromise.js.map +0 -1
  308. package/lib/asyncs/firstOfAsyncIterator.js.map +0 -1
  309. package/lib/asyncs/generatorOfStream.js.map +0 -1
  310. package/lib/asyncs/isIterator.js.map +0 -1
  311. package/lib/asyncs/isPromise.js.map +0 -1
  312. package/lib/asyncs/isThenable.js.map +0 -1
  313. package/lib/asyncs/nextOfAsyncIterator.js.map +0 -1
  314. package/lib/asyncs/promiseOfCallback.js.map +0 -1
  315. package/lib/asyncs/timeout.js.map +0 -1
  316. package/lib/browsers/copy.js.map +0 -1
  317. package/lib/browsers/download.js.map +0 -1
  318. package/lib/browsers/getFileFromDataTransfer.js.map +0 -1
  319. package/lib/browsers/loaders.js.map +0 -1
  320. package/lib/cn/division/DivisionCode.js +0 -215
  321. package/lib/cn/division/DivisionCode.js.map +0 -1
  322. package/lib/cn/division/binarySearch.js +0 -27
  323. package/lib/cn/division/binarySearch.js.map +0 -1
  324. package/lib/cn/formatChineseAmount.js +0 -77
  325. package/lib/cn/formatChineseAmount.js.map +0 -1
  326. package/lib/cn/id/Mod11.js +0 -43
  327. package/lib/cn/id/Mod11.js.map +0 -1
  328. package/lib/cn/id/ResidentIdNumber.js +0 -98
  329. package/lib/cn/id/ResidentIdNumber.js.map +0 -1
  330. package/lib/cn/id/types.js +0 -8
  331. package/lib/cn/id/types.js.map +0 -1
  332. package/lib/cn/index.js +0 -14
  333. package/lib/cn/index.js.map +0 -1
  334. package/lib/cn/parseChineseNumber.js +0 -94
  335. package/lib/cn/parseChineseNumber.js.map +0 -1
  336. package/lib/cn/pinyin/cartesianProduct.js +0 -22
  337. package/lib/cn/pinyin/cartesianProduct.js.map +0 -1
  338. package/lib/cn/pinyin/data.json +0 -413
  339. package/lib/cn/pinyin/loader.js +0 -15
  340. package/lib/cn/pinyin/loader.js.map +0 -1
  341. package/lib/cn/pinyin/preload.js +0 -4
  342. package/lib/cn/pinyin/preload.js.map +0 -1
  343. package/lib/cn/pinyin/toPinyinPure.js +0 -32
  344. package/lib/cn/pinyin/toPinyinPure.js.map +0 -1
  345. package/lib/cn/pinyin/transform.js +0 -14
  346. package/lib/cn/pinyin/transform.js.map +0 -1
  347. package/lib/cn/types.js +0 -3
  348. package/lib/cn/types.js.map +0 -1
  349. package/lib/cn/uscc/Mod31.js +0 -49
  350. package/lib/cn/uscc/Mod31.js.map +0 -1
  351. package/lib/cn/uscc/USCC.js +0 -94
  352. package/lib/cn/uscc/USCC.js.map +0 -1
  353. package/lib/cn/uscc/isUSCC.js +0 -8
  354. package/lib/cn/uscc/isUSCC.js.map +0 -1
  355. package/lib/crypto/base.js.map +0 -1
  356. package/lib/crypto/getNodeCrypto.js.map +0 -1
  357. package/lib/crypto/hashing.js.map +0 -1
  358. package/lib/crypto/md5.bench.js.map +0 -1
  359. package/lib/crypto/md5.d.js.map +0 -1
  360. package/lib/crypto/md5.js.map +0 -1
  361. package/lib/crypto/pem/pem.js.map +0 -1
  362. package/lib/crypto/randomUUIDv7.js.map +0 -1
  363. package/lib/crypto/ulid.js.map +0 -1
  364. package/lib/emitter/types.js.map +0 -1
  365. package/lib/errors/Errors.js.map +0 -1
  366. package/lib/fetch/HttpStatus.js.map +0 -1
  367. package/lib/fetch/createFetchWith.js.map +0 -1
  368. package/lib/fetch/createFetchWithLogging.js.map +0 -1
  369. package/lib/fetch/createFetchWithRetry.js.map +0 -1
  370. package/lib/fetch/dumpRequest.js.map +0 -1
  371. package/lib/fetch/dumpResponse.js.map +0 -1
  372. package/lib/fetch/http.types.js.map +0 -1
  373. package/lib/fetch/index.js.map +0 -1
  374. package/lib/fetch/types.js.map +0 -1
  375. package/lib/i18n/createTranslate.js.map +0 -1
  376. package/lib/index.js.map +0 -1
  377. package/lib/io/AbstractEncoding.js.map +0 -1
  378. package/lib/io/ArrayBuffer.test-d.js.map +0 -1
  379. package/lib/io/ArrayBuffers.js.map +0 -1
  380. package/lib/io/Buffer.js.map +0 -1
  381. package/lib/io/ByteBuffer.js.map +0 -1
  382. package/lib/io/base64.js.map +0 -1
  383. package/lib/io/dump.js.map +0 -1
  384. package/lib/io/isBuffer.js.map +0 -1
  385. package/lib/io/isTransferable.js.map +0 -1
  386. package/lib/io/parseDataUri.js.map +0 -1
  387. package/lib/langs/AsyncCloser.js.map +0 -1
  388. package/lib/langs/Closer.js.map +0 -1
  389. package/lib/langs/MaybeFunction.js.map +0 -1
  390. package/lib/langs/classOf.js.map +0 -1
  391. package/lib/langs/deepEqual.js.map +0 -1
  392. package/lib/langs/deepFreeze.js.map +0 -1
  393. package/lib/langs/getGlobalStates.js.map +0 -1
  394. package/lib/langs/getObjectId.js.map +0 -1
  395. package/lib/langs/ifPresent.js.map +0 -1
  396. package/lib/langs/isClass.js.map +0 -1
  397. package/lib/langs/isDefined.js.map +0 -1
  398. package/lib/langs/isEmptyObject.js.map +0 -1
  399. package/lib/langs/isFunction.js.map +0 -1
  400. package/lib/langs/isNullish.js +0 -5
  401. package/lib/langs/isNullish.js.map +0 -1
  402. package/lib/langs/isPlainObject.js.map +0 -1
  403. package/lib/langs/memoize.js.map +0 -1
  404. package/lib/langs/mixin.js.map +0 -1
  405. package/lib/langs/parseBoolean.js.map +0 -1
  406. package/lib/langs/shallowClone.js.map +0 -1
  407. package/lib/langs/shallowEqual.js.map +0 -1
  408. package/lib/libs/ms.js.map +0 -1
  409. package/lib/logging/Logger.js +0 -5
  410. package/lib/logging/Logger.js.map +0 -1
  411. package/lib/logging/createChildLogger.js +0 -16
  412. package/lib/logging/createChildLogger.js.map +0 -1
  413. package/lib/logging/createLogger.js +0 -63
  414. package/lib/logging/createLogger.js.map +0 -1
  415. package/lib/logging/createNoopLogger.js +0 -13
  416. package/lib/logging/createNoopLogger.js.map +0 -1
  417. package/lib/logging/slog.js +0 -143
  418. package/lib/logging/slog.js.map +0 -1
  419. package/lib/maths/clamp.js.map +0 -1
  420. package/lib/maths/random.js.map +0 -1
  421. package/lib/mitt/index.js +0 -77
  422. package/lib/mitt/index.js.map +0 -1
  423. package/lib/modules/isModule.js.map +0 -1
  424. package/lib/modules/parseModuleId.js.map +0 -1
  425. package/lib/objects/computeIfAbsent.js.map +0 -1
  426. package/lib/objects/get.js.map +0 -1
  427. package/lib/objects/get.test-d.js.map +0 -1
  428. package/lib/objects/merge/index.js.map +0 -1
  429. package/lib/objects/merge/isMergeableObject.js.map +0 -1
  430. package/lib/objects/merge/merge.js.map +0 -1
  431. package/lib/objects/parseObjectPath.js.map +0 -1
  432. package/lib/objects/set.js.map +0 -1
  433. package/lib/schema/typebox/index.js.map +0 -1
  434. package/lib/schema/typebox/typebox.js.map +0 -1
  435. package/lib/scripts/getGenerateContext.js.map +0 -1
  436. package/lib/server/crypto/md5.js.map +0 -1
  437. package/lib/server/fetch/createFetchWithProxy.js.map +0 -1
  438. package/lib/server/fetch/createFetchWithProxyByNodeFetch.js.map +0 -1
  439. package/lib/server/fetch/createFetchWithProxyByUndici.js.map +0 -1
  440. package/lib/server/getPackageDir.js.map +0 -1
  441. package/lib/server/index.js.map +0 -1
  442. package/lib/server/jsdom.js.map +0 -1
  443. package/lib/server/node-fetch.js.map +0 -1
  444. package/lib/server/polyfill/polyfillBrowser.js.map +0 -1
  445. package/lib/server/polyfill/polyfillCrypto.js.map +0 -1
  446. package/lib/server/polyfill/polyfillFetch.js.map +0 -1
  447. package/lib/server/polyfill/polyfillJsDom.js.map +0 -1
  448. package/lib/server/polyfill/polyfillWebSocket.js.map +0 -1
  449. package/lib/server/ws.js.map +0 -1
  450. package/lib/strings/camelCase.js.map +0 -1
  451. package/lib/strings/formatBytes.js.map +0 -1
  452. package/lib/strings/renderTemplate.js.map +0 -1
  453. package/lib/typedoc.js.map +0 -1
  454. package/lib/types.d.js.map +0 -1
  455. package/lib/validations/asserts.js.map +0 -1
  456. package/lib/validations/isUUID.js.map +0 -1
  457. package/lib/validations/parseTimestamp.js.map +0 -1
  458. package/lib/web/getGlobalThis.js.map +0 -1
  459. package/lib/web/getRandomValues.js.map +0 -1
  460. package/lib/web/randomUUID.js.map +0 -1
  461. package/lib/web/requestIdleCallback.js.map +0 -1
  462. package/lib/web/structuredClone.js.map +0 -1
  463. package/src/cn/README.md +0 -3
  464. package/src/cn/division/DivisionCode.ts +0 -173
  465. package/src/cn/division/binarySearch.test.ts +0 -64
  466. package/src/cn/division/binarySearch.ts +0 -25
  467. package/src/cn/division/division.test.ts +0 -22
  468. package/src/cn/formatChineseAmount.ts +0 -61
  469. package/src/cn/id/Mod11.ts +0 -26
  470. package/src/cn/id/ResidentIdNumber.ts +0 -126
  471. package/src/cn/id/id.test.ts +0 -20
  472. package/src/cn/id/types.ts +0 -26
  473. package/src/cn/index.ts +0 -17
  474. package/src/cn/parseChineseNumber.test.ts +0 -159
  475. package/src/cn/parseChineseNumber.ts +0 -97
  476. package/src/cn/pinyin/cartesianProduct.test.ts +0 -64
  477. package/src/cn/pinyin/cartesianProduct.ts +0 -24
  478. package/src/cn/pinyin/data.json +0 -413
  479. package/src/cn/pinyin/loader.ts +0 -12
  480. package/src/cn/pinyin/preload.ts +0 -3
  481. package/src/cn/pinyin/toPinyin.test.ts +0 -12
  482. package/src/cn/pinyin/toPinyinPure.ts +0 -43
  483. package/src/cn/pinyin/transform.ts +0 -12
  484. package/src/cn/scripts/gen.test.ts +0 -131
  485. package/src/cn/types.ts +0 -11
  486. package/src/cn/uscc/Mod31.ts +0 -38
  487. package/src/cn/uscc/USCC.ts +0 -94
  488. package/src/cn/uscc/isUSCC.ts +0 -8
  489. package/src/cn/uscc/uscc.test.ts +0 -16
  490. package/src/langs/isNullish.ts +0 -3
  491. package/src/logging/Logger.ts +0 -25
  492. package/src/logging/createChildLogger.ts +0 -16
  493. package/src/logging/createLogger.ts +0 -50
  494. package/src/logging/createNoopLogger.ts +0 -13
  495. package/src/logging/logger.test.ts +0 -36
  496. package/src/logging/slog.test.ts +0 -8
  497. package/src/logging/slog.ts +0 -221
  498. package/src/mitt/README.md +0 -1
  499. package/src/mitt/index.ts +0 -114
@@ -1,446 +1 @@
1
- import { classOf } from '../langs/classOf';
2
- import { getGlobalThis } from '../web/getGlobalThis';
3
- import { decodeBase64ToUint8Array, encodeArrayBufferToBase64 } from './base64';
4
- import { isBuffer } from './isBuffer';
5
-
6
- /**
7
- * Various utils to work with {@link ArrayBuffer}
8
- *
9
- * @see https://github.com/tc39/proposal-resizablearraybuffer
10
- */
11
- export namespace ArrayBuffers {
12
- /*
13
- Uint8Array to/from base64 and hex
14
- Stage 3
15
- Uint8Array.fromBase64, Uint8Array.prototype.toBase64
16
- Uint8Array.fromHex, Uint8Array.prototype.toHex
17
- https://github.com/tc39/proposal-arraybuffer-base64
18
- */
19
-
20
- /*
21
- In-Place Resizable and Growable ArrayBuffers
22
- Stage 4
23
- Chrome 111, Nodejs 20, Safari 16.4
24
-
25
- SharedArrayBuffer & ArrayBuffer
26
- constructor(byteLength, {maxByteLength})
27
- prototype.resize(newByteLength)
28
- prototype.slice(start, end)
29
- prototype.{resizable,maxByteLength}
30
- https://github.com/tc39/proposal-resizablearraybuffer
31
- */
32
-
33
- export type BinaryStringEncoding =
34
- | 'ascii'
35
- | 'utf16le'
36
- // | 'utf-16le'
37
- | 'ucs2'
38
- | 'ucs-2'
39
- | 'base64'
40
- | 'base64url'
41
- | 'latin1'
42
- | 'binary'
43
- | 'utf8'
44
- | 'utf-8'
45
- | 'hex';
46
-
47
- let nativeBufferAllowed: boolean = true;
48
- let isBufferAvailable: undefined | boolean;
49
-
50
- /**
51
- * isNativeBufferAvailable check if the native {@link Buffer} is available
52
- */
53
- export function isNativeBufferAvailable(): boolean {
54
- // eslint-disable-next-line no-return-assign
55
- return (isBufferAvailable ??= !(getGlobalThis().Buffer as any)?.isPollyfill?.());
56
- }
57
-
58
- export function isNativeBufferAllowed(): boolean {
59
- return Boolean(nativeBufferAllowed && isBufferAvailable);
60
- }
61
-
62
- export function setNativeBufferAllowed(v: boolean): void {
63
- nativeBufferAllowed = v;
64
- }
65
-
66
- /**
67
- * isArrayBuffer check if the given value is an {@link ArrayBuffer}
68
- */
69
- export function isArrayBuffer(v: any): v is ArrayBuffer {
70
- return v instanceof ArrayBuffer;
71
- }
72
-
73
- /**
74
- * slice the given view with the given offset and length, will handle the {@link Buffer} as well
75
- *
76
- * @see {@link https://nodejs.org/api/buffer.html#bufslicestart-end Buffer.slice}
77
- */
78
- export function slice<T extends TypedArray>(o: T, start?: number, end?: number): T {
79
- // NodeJS Buffer slice is not the same as UInt8Array slice
80
- // https://nodejs.org/api/buffer.html#bufslicestart-end
81
- if (isBuffer(o)) {
82
- return Uint8Array.prototype.slice.call(o, start, end) as T;
83
- }
84
- return o.slice(start, end) as T;
85
- }
86
-
87
- /**
88
- * asView convert the given value to given {@link TypedArray} view
89
- *
90
- * TypedArray can be {@link Buffer}, will avoid copy
91
- */
92
- export function asView<C extends ArrayBufferViewConstructor<unknown>>(
93
- TypedArray: C,
94
- v: BufferSource,
95
- byteOffset?: number,
96
- byteLength?: number,
97
- ): InstanceType<C> {
98
- if (v instanceof TypedArray && (byteOffset ?? 0) === 0 && byteLength === undefined) {
99
- return v as InstanceType<C>;
100
- }
101
- if (ArrayBuffer.isView(v) || isBuffer(v)) {
102
- if (isNativeBufferAllowed() && (TypedArray as any) === Buffer) {
103
- // new Buffer() is deprecated
104
- return Buffer.from(v.buffer, byteOffset, byteLength) as InstanceType<C>;
105
- }
106
- return new TypedArray(v.buffer, v.byteOffset + (byteOffset ?? 0), byteLength ?? v.byteLength) as InstanceType<C>;
107
- }
108
- return new TypedArray(v, byteOffset, byteLength) as InstanceType<C>;
109
- }
110
-
111
- /**
112
- * toString convert the given {@link BufferSource} to string
113
- */
114
- export function toString(source: BufferSource | string, encoding: BinaryStringEncoding = 'utf8'): string {
115
- // 'ascii' 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'base64url' | 'latin1' | 'binary' | 'hex'
116
- if (typeof source === 'string') {
117
- switch (encoding) {
118
- case 'base64':
119
- return btoa(source);
120
- case 'utf-8':
121
- case 'utf8':
122
- return source;
123
- default:
124
- throw new Error(`[ArrayBuffers.toString] Unsupported encoding for string: ${encoding}`);
125
- }
126
- }
127
- let u8 = asView(Uint8Array, source);
128
- if (isNativeBufferAllowed()) {
129
- return Buffer.from(u8).toString(encoding);
130
- }
131
- // reference
132
- // https://github.com/feross/buffer/blob/master/index.js
133
- switch (encoding) {
134
- case 'hex': {
135
- return [...u8].map((b) => hexLookupTable[b]).join('');
136
- }
137
- case 'base64': {
138
- return encodeArrayBufferToBase64(u8);
139
- }
140
- case 'utf8':
141
- // falls through
142
- case 'utf-8':
143
- return new TextDecoder().decode(source);
144
- case 'ascii': {
145
- return String.fromCharCode(...u8.map((v) => v & 0x7f));
146
- }
147
- case 'latin1':
148
- // falls through
149
- case 'binary': {
150
- return String.fromCharCode(...u8);
151
- }
152
- case 'ucs2':
153
- // falls through
154
- case 'ucs-2':
155
- // case 'utf-16le':
156
- // falls through
157
- case 'utf16le': {
158
- let res = '';
159
- // If length is odd, the last 8 bits must be ignored (same as node.js)
160
- for (let i = 0; i < u8.length - 1; i += 2) {
161
- res += String.fromCharCode(u8[i] + u8[i + 1] * 256);
162
- }
163
- return res;
164
- }
165
- default:
166
- throw new Error(`[ArrayBuffers.toString] Unknown encoding: ${encoding}`);
167
- }
168
- }
169
-
170
- function normalizeEncoding(encoding: string | undefined) {
171
- switch (encoding?.toLowerCase()) {
172
- case 'utf-8':
173
- case 'utf8':
174
- return 'utf8';
175
- case 'utf-16le':
176
- case 'ucs2':
177
- case 'ucs-2':
178
- return 'utf16le';
179
- case 'hex':
180
- case 'ascii':
181
- case 'latin1':
182
- case 'binary':
183
- case 'base64':
184
- case 'utf16le':
185
- return encoding;
186
- default:
187
- return undefined;
188
- }
189
- }
190
-
191
- /**
192
- * Returns true if encoding is the name of a supported character encoding, or false otherwise.
193
- */
194
- export function isEncoding(v?: string): v is BinaryStringEncoding {
195
- return normalizeEncoding(v) !== undefined;
196
- }
197
-
198
- export function toJSON<T = any>(v: BufferSource | string, reviver?: (this: any, key: string, value: any) => any): T {
199
- return JSON.parse(toString(v), reviver);
200
- }
201
-
202
- /**
203
- * from convert the given value to {@link ArrayBuffer} like
204
- */
205
- export function from(
206
- src: string | BufferSource | Array<number> | Iterable<number>,
207
- encoding?: BinaryStringEncoding,
208
- ): ArrayBuffer | TypedArray;
209
- /**
210
- * from convert the given value to {@link TypedArray}
211
- */
212
- export function from<C extends ArrayBufferViewConstructor<unknown>>(
213
- src: string | BufferSource | Array<number> | Iterable<number>,
214
- encoding: BinaryStringEncoding,
215
- TypedArray: C,
216
- ): InstanceType<C>;
217
- export function from(
218
- src: string | BufferSource | Array<number> | Iterable<number>,
219
- encoding: BinaryStringEncoding = 'utf8',
220
- view?: any,
221
- ): any {
222
- if (!src) {
223
- return new (view || ArrayBuffer)(0);
224
- }
225
- if (isBufferSource(src)) {
226
- return view ? asView(view, src) : src;
227
- }
228
- // Array<number> | Iterable<number>
229
- if ((typeof src !== 'string' && isIterable(src)) || Array.isArray(src)) {
230
- return (view || Uint8Array).from(src);
231
- }
232
- if (view) {
233
- return asView(view, from(src, encoding));
234
- }
235
- if (typeof src === 'string') {
236
- // is string
237
- if (isNativeBufferAllowed()) {
238
- return Buffer.from(src, encoding);
239
- }
240
- switch (encoding) {
241
- case 'utf-8':
242
- // falls through
243
- case 'utf8':
244
- return new TextEncoder().encode(src).buffer;
245
- case 'base64':
246
- // replaceAll need higher version of nodejs
247
- // return decodeBase64ToArrayBuffer(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));
248
- return fromBase64(src);
249
- case 'hex':
250
- // return new Uint8Array(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16))).buffer;
251
- return fromHex(src);
252
- default:
253
- throw new Error(`ArrayBuffers.from unsupported encoding: ${encoding}`);
254
- }
255
- }
256
-
257
- const type = classOf(src);
258
- throw new TypeError(`ArrayBuffers.from unsupported type ${type}`);
259
- }
260
-
261
- /**
262
- * concat the given {@link BufferSource} to a new {@link ArrayBuffer}
263
- */
264
- export function concat(buffers: Array<BufferSource>, result?: ArrayBuffer, offset = 0): ArrayBuffer {
265
- // https://stackoverflow.com/questions/10786128/appending-arraybuffers
266
-
267
- const length = buffers.reduce((a, b) => a + b.byteLength, 0);
268
- const r = result ? new Uint8Array(result) : new Uint8Array(length);
269
- for (const buffer of buffers) {
270
- if (!buffer?.byteLength) continue;
271
- let n: Uint8Array;
272
- if (buffer instanceof ArrayBuffer) {
273
- n = new Uint8Array(buffer);
274
- } else if (ArrayBuffer.isView(buffer)) {
275
- n = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
276
- } else {
277
- throw new Error(`ArrayBuffers.concat unsupported type ${classOf(buffer)}`);
278
- }
279
- r.set(n, offset);
280
- offset += buffer.byteLength;
281
- }
282
- return r.buffer;
283
- }
284
-
285
- export function fromBase64(v: string): Uint8Array {
286
- if ('fromBase64' in Uint8Array) {
287
- return Uint8Array.fromBase64(v);
288
- }
289
- if (isNativeBufferAllowed()) {
290
- return Buffer.from(v, 'base64');
291
- }
292
- return decodeBase64ToUint8Array(v.replace(/[^0-9a-zA-Z=+/_]/g, ''));
293
- }
294
-
295
- export function fromHex(v: string): Uint8Array {
296
- if ('fromHex' in Uint8Array) {
297
- return Uint8Array.fromHex(v);
298
- }
299
- if (isNativeBufferAllowed()) {
300
- return Buffer.from(v, 'hex');
301
- }
302
- return new Uint8Array(v.match(/.{1,2}/g)!.map((byte) => parseInt(byte, 16)));
303
- }
304
-
305
- /**
306
- * toBase64 convert the given {@link BufferSource} to base64 string
307
- * @param source if string, will be encoded as utf8
308
- */
309
- export function toBase64(source: BufferSource | string): string {
310
- if (typeof source === 'string') {
311
- source = new TextEncoder().encode(source);
312
- }
313
- if ('toBase64' in Uint8Array.prototype) {
314
- return toUint8Array(source).toBase64();
315
- }
316
- if (isNativeBufferAllowed()) {
317
- return Buffer.from(asView(Uint8Array, source)).toString('base64');
318
- }
319
- return encodeArrayBufferToBase64(toArrayBuffer(source));
320
- }
321
-
322
- export function toHex(v: BufferSource): string {
323
- if ('toHex' in Uint8Array.prototype) {
324
- return toUint8Array(v).toHex();
325
- }
326
- if (isNativeBufferAllowed()) {
327
- return Buffer.from(asView(Uint8Array, v)).toString('hex');
328
- }
329
- return toString(v, 'hex');
330
- }
331
-
332
- export function resize(v: ArrayBuffer, newByteLength?: number, maxByteLength?: number): ArrayBuffer {
333
- if (newByteLength === undefined || newByteLength === null) {
334
- return v;
335
- }
336
-
337
- // Chrome 111, Nodejs 20
338
- if ('resize' in v && typeof v.resize === 'function') {
339
- if ('resizable' in v && v.resizable) {
340
- if ('maxByteLength' in v && typeof v.maxByteLength === 'number' && v.maxByteLength >= newByteLength) {
341
- v.resize(newByteLength);
342
- return v as ArrayBuffer;
343
- }
344
- }
345
- }
346
-
347
- const old = v;
348
- const newBuf = new ArrayBuffer(newByteLength, { maxByteLength: maxByteLength });
349
- const oldView = new Uint8Array(old);
350
- const newView = new Uint8Array(newBuf);
351
- newView.set(oldView);
352
- return newBuf;
353
- }
354
-
355
- export function toArrayBuffer(v: BufferSource): ArrayBuffer {
356
- if (v instanceof ArrayBuffer) {
357
- return v;
358
- }
359
- if (ArrayBuffer.isView(v)) {
360
- if (v.byteOffset > 0) {
361
- throw new Error('ArrayBuffers.toArrayBuffer do not support view with offset');
362
- }
363
- return v.buffer;
364
- }
365
- throw new Error(`ArrayBuffers.toArrayBuffer unsupported type ${classOf(v)}`);
366
- }
367
-
368
- export function toUint8Array(v: BufferSource): Uint8Array {
369
- return asView(Uint8Array, v);
370
- }
371
-
372
- export function alloc(size: number, fill?: string | number, encoding?: BinaryStringEncoding): ArrayBuffer {
373
- if (fill !== undefined) {
374
- if (typeof fill === 'number') {
375
- return new Uint8Array(size).fill(fill);
376
- }
377
- // as cast
378
- // https://stackoverflow.com/questions/73994091
379
- return asView(Uint8Array, from(fill, encoding)).slice(0, size);
380
- }
381
- return new ArrayBuffer(size);
382
- }
383
- }
384
-
385
- export type TypedArray =
386
- | Uint8Array
387
- | Uint8ClampedArray
388
- | Uint16Array
389
- | Uint32Array
390
- | Int8Array
391
- | Int16Array
392
- | Int32Array
393
- | BigUint64Array
394
- | BigInt64Array
395
- | Float32Array
396
- | Float64Array;
397
-
398
- type ArrayBufferViewConstructor<T> = new (buffer: ArrayBufferLike, byteOffset?: number, byteLength?: number) => T;
399
-
400
- const hexLookupTable = (function () {
401
- const alphabet = '0123456789abcdef';
402
- const table = new Array(256);
403
- for (let i = 0; i < 16; ++i) {
404
- const i16 = i * 16;
405
- for (let j = 0; j < 16; ++j) {
406
- table[i16 + j] = alphabet[i] + alphabet[j];
407
- }
408
- }
409
- return table;
410
- })();
411
-
412
- declare global {
413
- interface ArrayBuffer {
414
- resize?: (newByteLength: number) => void;
415
- resizable?: boolean;
416
- }
417
-
418
- interface ArrayBufferConstructor {
419
- new (byteLength: number, opts?: { maxByteLength?: number }): ArrayBuffer;
420
- }
421
-
422
- interface SharedArrayBuffer {
423
- resize?: (newByteLength: number) => void;
424
- resizable?: boolean;
425
- }
426
-
427
- interface Uint8Array {
428
- toBase64(): string;
429
-
430
- toHex(): string;
431
- }
432
-
433
- interface Uint8ArrayConstructor {
434
- fromBase64(v: string): Uint8Array;
435
-
436
- fromHex(v: string): Uint8Array;
437
- }
438
- }
439
-
440
- function isIterable(obj: any): obj is Iterable<any> {
441
- return typeof obj?.[Symbol.iterator] === 'function';
442
- }
443
-
444
- function isBufferSource(v: any): v is BufferSource {
445
- return ArrayBuffer.isView(v) || v instanceof ArrayBuffer;
446
- }
1
+ export * as ArrayBuffers from './ArrayBuffers.mod';
@@ -3,21 +3,21 @@ import { Buffer } from './Buffer';
3
3
  import { isBuffer } from './isBuffer';
4
4
 
5
5
  test('basic', () => {
6
- {
7
- const buf = new Buffer(0);
8
- expect(Buffer.isBuffer(buf)).toBeTruthy();
9
- expect(isBuffer(buf)).toBeTruthy();
10
- }
11
- // const b = new Buffer(10)
12
- // t.is(b.length,10)
13
- // t.is(b.byteLength,10)
14
- // t.is(b.byteOffset,0)
15
- // t.is(b.buffer.byteLength,10)
16
- // t.is(b.buffer.byteOffset,0)
17
- // t.is(b.buffer.length,1)
18
- // t.is(b.buffer[0].byteLength,10)
19
- // t.is(b.buffer[0].byteOffset,0)
20
- // t.is(b.buffer[0].length,10)
21
- // t.is(b.buffer[0][0],0)
22
- // t.is(b.buffer[0][9],0)
6
+ {
7
+ const buf = new Buffer(0);
8
+ expect(Buffer.isBuffer(buf)).toBeTruthy();
9
+ expect(isBuffer(buf)).toBeTruthy();
10
+ }
11
+ // const b = new Buffer(10)
12
+ // t.is(b.length,10)
13
+ // t.is(b.byteLength,10)
14
+ // t.is(b.byteOffset,0)
15
+ // t.is(b.buffer.byteLength,10)
16
+ // t.is(b.buffer.byteOffset,0)
17
+ // t.is(b.buffer.length,1)
18
+ // t.is(b.buffer[0].byteLength,10)
19
+ // t.is(b.buffer[0].byteOffset,0)
20
+ // t.is(b.buffer[0].length,10)
21
+ // t.is(b.buffer[0][0],0)
22
+ // t.is(b.buffer[0][9],0)
23
23
  });
package/src/io/Buffer.ts CHANGED
@@ -5,26 +5,26 @@ import { isBuffer } from './isBuffer';
5
5
  * Buffer is a polyfill version of NodeJS Buffer
6
6
  */
7
7
  export class Buffer extends Uint8Array {
8
- // constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number) {
9
- // super(buffer, byteOffset, length);
10
- // }
8
+ // constructor(buffer: ArrayBufferLike, byteOffset?: number, length?: number) {
9
+ // super(buffer, byteOffset, length);
10
+ // }
11
11
 
12
- static get isPolyfill() {
13
- return true;
14
- }
12
+ static get isPolyfill() {
13
+ return true;
14
+ }
15
15
 
16
- static isBuffer(v: any): v is Buffer {
17
- return v instanceof Buffer || isBuffer(v);
18
- }
16
+ static isBuffer(v: any): v is Buffer {
17
+ return v instanceof Buffer || isBuffer(v);
18
+ }
19
19
 
20
- static from(array: string | BufferSource | ArrayLike<number> | Iterable<number>, arg2?: any): Buffer {
21
- // todo mapfn
22
- return new Buffer(ArrayBuffers.from(array, arg2) as ArrayBuffer);
23
- }
20
+ static from(array: string | BufferSource | ArrayLike<number> | Iterable<number>, arg2?: any): Buffer {
21
+ // todo mapfn
22
+ return new Buffer(ArrayBuffers.from(array, arg2) as ArrayBuffer);
23
+ }
24
24
 
25
- static isEncoding = ArrayBuffers.isEncoding;
25
+ static isEncoding = ArrayBuffers.isEncoding;
26
26
 
27
- toString(encoding?: string): string {
28
- return ArrayBuffers.toString(this, encoding as any);
29
- }
27
+ toString(encoding?: string): string {
28
+ return ArrayBuffers.toString(this, encoding as any);
29
+ }
30
30
  }
@@ -2,46 +2,46 @@ import { assert, describe, test } from 'vitest';
2
2
  import { ByteBuffer } from './ByteBuffer';
3
3
 
4
4
  describe('ByteBuffer', async () => {
5
- test('base', () => {
6
- let buf = new ByteBuffer();
7
- buf.writeString('Hello');
8
- buf.writeString('World');
9
- assert.equal(buf.length, 10);
10
- assert.equal(buf.position, 10);
11
- buf.length = 5;
12
- assert.equal(buf.length, 5);
13
- buf.position = 0;
14
- assert.equal(buf.readString(5), 'Hello');
15
- });
5
+ test('base', () => {
6
+ let buf = new ByteBuffer();
7
+ buf.writeString('Hello');
8
+ buf.writeString('World');
9
+ assert.equal(buf.length, 10);
10
+ assert.equal(buf.position, 10);
11
+ buf.length = 5;
12
+ assert.equal(buf.length, 5);
13
+ buf.position = 0;
14
+ assert.equal(buf.readString(5), 'Hello');
15
+ });
16
16
 
17
- test('overflow max length', () => {
18
- let buf = new ByteBuffer();
19
- buf.writeBytes(new Uint8Array(1025));
20
- assert.equal(buf.length, 1025);
21
- });
17
+ test('overflow max length', () => {
18
+ let buf = new ByteBuffer();
19
+ buf.writeBytes(new Uint8Array(1025));
20
+ assert.equal(buf.length, 1025);
21
+ });
22
22
 
23
- test('overflow max length tow step', () => {
24
- let buf = new ByteBuffer();
25
- buf.writeBytes(new Uint8Array(1023));
26
- buf.writeBytes(new Uint8Array(2));
27
- assert.equal(buf.length, 1025);
28
- console.log(`Max`, (buf.buffer as any).maxByteLength);
29
- });
23
+ test('overflow max length tow step', () => {
24
+ let buf = new ByteBuffer();
25
+ buf.writeBytes(new Uint8Array(1023));
26
+ buf.writeBytes(new Uint8Array(2));
27
+ assert.equal(buf.length, 1025);
28
+ console.log(`Max`, (buf.buffer as any).maxByteLength);
29
+ });
30
30
 
31
- test('writeBytes fill zero', () => {
32
- let buf = new ByteBuffer();
33
- buf.writeBytes(new Uint8Array([1, 2]));
34
- buf.position = 0;
35
- // console.log('->', buf.position, buf.length, buf.remaining());
36
- // console.log(toHexDump(buf.buffer));
31
+ test('writeBytes fill zero', () => {
32
+ let buf = new ByteBuffer();
33
+ buf.writeBytes(new Uint8Array([1, 2]));
34
+ buf.position = 0;
35
+ // console.log('->', buf.position, buf.length, buf.remaining());
36
+ // console.log(toHexDump(buf.buffer));
37
37
 
38
- // truncate to size fill zero
39
- buf.writeBytes(new Uint8Array([1]), 10);
40
- // console.log('->', buf.position, buf.length, buf.remaining());
41
- // console.log(toHexDump(buf.buffer));
38
+ // truncate to size fill zero
39
+ buf.writeBytes(new Uint8Array([1]), 10);
40
+ // console.log('->', buf.position, buf.length, buf.remaining());
41
+ // console.log(toHexDump(buf.buffer));
42
42
 
43
- assert.equal(buf.view.getInt8(0), 1);
44
- assert.equal(buf.view.getInt8(1), 0);
45
- assert.equal(buf.length, 10);
46
- });
43
+ assert.equal(buf.view.getInt8(0), 1);
44
+ assert.equal(buf.view.getInt8(1), 0);
45
+ assert.equal(buf.length, 10);
46
+ });
47
47
  });