ranuts 0.4.0-alpha.4 → 0.4.1-alpha.1
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.
- package/CLAUDE.md +25 -21
- package/README.md +5 -1
- package/README.zh-CN.md +17 -1
- package/dist/{color-DPV7TsVU.js → color-B_KMM8UX.js} +1 -1
- package/dist/i18n-BJIS1fR1.js +1 -0
- package/dist/index.js +1 -1
- package/dist/src/node/index.js +1 -1
- package/dist/src/utils/binary.d.ts +140 -0
- package/dist/src/utils/device.d.ts +8 -0
- package/dist/src/utils/i18n/index.js +1 -1
- package/dist/src/utils/index.d.ts +4 -2
- package/dist/src/utils/index.js +1 -1
- package/dist/src/utils/secure.d.ts +58 -0
- package/dist/src/utils/str.d.ts +75 -0
- package/dist/test/binary.test.d.ts +1 -0
- package/dist/test/utils/secure.test.d.ts +1 -0
- package/dist/test/utils/text-boundary.test.d.ts +1 -0
- package/dist/umd/index.umd.cjs +1 -1
- package/dist/umd/utils/utils.umd.cjs +1 -1
- package/dist/utils-BNwhohXq.js +1 -0
- package/docs/API.md +25 -5
- package/package.json +1 -1
- package/dist/i18n-Bq-f7htr.js +0 -1
- package/dist/utils-CYrYCt5o.js +0 -1
package/CLAUDE.md
CHANGED
|
@@ -58,6 +58,7 @@ packages/ranuts/
|
|
|
58
58
|
│ │ ├── idb.ts # WebDB (declarative stores) + createHandoff (one-shot value handoff)
|
|
59
59
|
│ │ ├── worker.ts # WorkerClient — request/response over a Web Worker
|
|
60
60
|
│ │ ├── zip.ts # ZIP read/rewrite — crc32, inflateRaw, rewriteZip, createZip
|
|
61
|
+
│ │ ├── binary.ts # bytes ↔ base64 (chunked), gzip sniff/decompress, zip/HTML signature sniff, decodeTextBytes, saveFileToDisk
|
|
61
62
|
│ │ ├── async.ts # deferred / withTimeout / withTimeoutFallback / delay / createRaceGuard
|
|
62
63
|
│ │ ├── storage.ts # localStorage* + createStore (prefixed JSON view)
|
|
63
64
|
│ │ ├── segment.ts # offsets ↔ chunks, range→segment splitting (highlights)
|
|
@@ -226,27 +227,30 @@ npm run doc:api # regenerate docs/API.md from source + JSDoc
|
|
|
226
227
|
|
|
227
228
|
## Gotchas
|
|
228
229
|
|
|
229
|
-
| Pitfall | Fix
|
|
230
|
-
| -------------------------------------------------------------------------------- |
|
|
231
|
-
| Importing from a deep source path or `@/…` | Import from the public subpath (`ranuts/utils`, `ranuts/visual`, …). `@/…` is build-internal only.
|
|
232
|
-
| Importing `ranuts/node` in browser code | It externalizes `fs`/`http`/`child_process` — server-only. Use `ranuts/utils` for browser helpers.
|
|
233
|
-
| `new Application()` then `render()` with WebGPU | Device init is async — use `await Application.create(...)`, then `app.start()`.
|
|
234
|
-
| Hand-editing `docs/API.md` | It's generated. Edit the source JSDoc and run `npm run doc:api`.
|
|
235
|
-
| Adding an export but it's missing from `docs/API.md` | Re-export it from the module's `index.ts` barrel, then `npm run doc:api`.
|
|
236
|
-
| New entry point not importable as `ranuts/foo` | Wire all three: `package.json` exports + `vite.config.ts` es entry + generator `ENTRIES`.
|
|
237
|
-
| `console.log` left in a function that a test calls | `vitest.config.ts` `onConsoleLog` throws — remove it or the test fails.
|
|
238
|
-
| Assuming a GPU/Canvas test can run in CI | Test env is node (no DOM/GPU). Test pure logic; gate visual checks behind a browser demo.
|
|
239
|
-
| Passing a non-`#rrggbb` color to the GPU backend and expecting it to fail | It won't — `getRgb` resolves any CSS color via the browser parser, matching the Canvas backend.
|
|
240
|
-
| Branching on `isClient` in new code | It's a module-load-time constant — wrong after SSR, unstubbable in tests. Check `typeof window === 'undefined'` inside the function.
|
|
241
|
-
| `
|
|
242
|
-
|
|
|
243
|
-
|
|
|
244
|
-
|
|
|
245
|
-
|
|
|
246
|
-
|
|
|
247
|
-
|
|
|
248
|
-
|
|
|
249
|
-
|
|
|
230
|
+
| Pitfall | Fix |
|
|
231
|
+
| -------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
232
|
+
| Importing from a deep source path or `@/…` | Import from the public subpath (`ranuts/utils`, `ranuts/visual`, …). `@/…` is build-internal only. |
|
|
233
|
+
| Importing `ranuts/node` in browser code | It externalizes `fs`/`http`/`child_process` — server-only. Use `ranuts/utils` for browser helpers. |
|
|
234
|
+
| `new Application()` then `render()` with WebGPU | Device init is async — use `await Application.create(...)`, then `app.start()`. |
|
|
235
|
+
| Hand-editing `docs/API.md` | It's generated. Edit the source JSDoc and run `npm run doc:api`. |
|
|
236
|
+
| Adding an export but it's missing from `docs/API.md` | Re-export it from the module's `index.ts` barrel, then `npm run doc:api`. |
|
|
237
|
+
| New entry point not importable as `ranuts/foo` | Wire all three: `package.json` exports + `vite.config.ts` es entry + generator `ENTRIES`. |
|
|
238
|
+
| `console.log` left in a function that a test calls | `vitest.config.ts` `onConsoleLog` throws — remove it or the test fails. |
|
|
239
|
+
| Assuming a GPU/Canvas test can run in CI | Test env is node (no DOM/GPU). Test pure logic; gate visual checks behind a browser demo. |
|
|
240
|
+
| Passing a non-`#rrggbb` color to the GPU backend and expecting it to fail | It won't — `getRgb` resolves any CSS color via the browser parser, matching the Canvas backend. |
|
|
241
|
+
| Branching on `isClient` in new code | It's a module-load-time constant — wrong after SSR, unstubbable in tests. Check `typeof window === 'undefined'` inside the function. |
|
|
242
|
+
| Reaching for `randomString` / `getRandomString` to make a token or code | Both are `Math.random()` based and predictable. Use `secureRandomString` / `secureToken` from `secure.ts` for anything an attacker would want to guess. |
|
|
243
|
+
| Comparing a secret with `===` | Returns early at the first differing byte, leaking the shared prefix through timing. Use `safeEqual`. |
|
|
244
|
+
| Decoding chunked text per chunk | A multi-byte character straddling a boundary becomes replacement characters. `concatBytes` first, decode once. |
|
|
245
|
+
| `window.setTimeout` in a `ranuts/utils` module | Throws outside a document. Use the bare `setTimeout`. |
|
|
246
|
+
| A module-level factory that keeps mutable state shared by everything it produces | Give each produced function its own state (this is why `generateThrottle` was removed). |
|
|
247
|
+
| Reaching for `memoize` expecting per-argument caching | It only runs once and ignores later arguments. Use `once` (its new name), `singleFlight` for async, or a `Map` for real keyed caching. |
|
|
248
|
+
| Assuming `createSignal` deep-compares | It uses `Object.is` since 0.3. Pass `{ equals: isEqual }` when you want deep comparison. |
|
|
249
|
+
| Testing a boolean URL flag with `getAllQueryString(url).embed` | `?embed` (no value) is the usual spelling and reads as `''`, which is falsy. Use `queryFlag('embed')`. |
|
|
250
|
+
| `Promise.race([task, timeoutPromise])` for a deadline | Leaks the timer when the task wins. Use `withTimeout` / `withTimeoutFallback` — they always clear it. |
|
|
251
|
+
| Expecting `rewriteZip` to recompress | Rewritten and injected entries are written STORED, so the output is larger. Untouched entries keep their original compressed bytes. |
|
|
252
|
+
| Expecting `zip.ts` to open a >4 GiB archive | No ZIP64, no encryption, no multi-disk. `readZipEntries` returns `[]` for anything it cannot parse. |
|
|
253
|
+
| Calling `createHandoff().take()` twice | It is one-shot by design — the read and the delete share a transaction. The second call resolves `null`. |
|
|
250
254
|
|
|
251
255
|
---
|
|
252
256
|
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ Experimental utility library with commonly used functions and tools
|
|
|
10
10
|
<a href="https://github.com/chaxus/ran"><img src="https://img.badgesize.io/https:/unpkg.com/ranuts/dist/index.js?label=brotli&compression=brotli" alt="brotli"></a>
|
|
11
11
|
<a href="https://github.com/chaxus/ran"><img src="https://img.shields.io/badge/module%20formats-umd%2C%20esm-green.svg" alt="module formats: umd, esm"></a>
|
|
12
12
|
|
|
13
|
+
**English** | [中文](./README.zh-CN.md)
|
|
14
|
+
|
|
13
15
|
---
|
|
14
16
|
|
|
15
17
|
## ⚠️ Important Notice
|
|
@@ -53,9 +55,11 @@ Claude then uses it automatically (or invoke it as `/ranuts:ranuts`).
|
|
|
53
55
|
|
|
54
56
|
Import as required. You can select:
|
|
55
57
|
|
|
56
|
-
- `ranuts/utils` — DOM/BOM, string, object, number, colour, time, storage,
|
|
58
|
+
- `ranuts/utils` — DOM/BOM, string, object, number, colour, time, storage, binary/zip,
|
|
59
|
+
worker/IndexedDB, i18n helpers
|
|
57
60
|
- `ranuts/node` — HTTP server, router, ws, fs, streams, middleware (**Node only**)
|
|
58
61
|
- `ranuts/visual` — 2D rendering engine (Canvas / WebGL / WebGPU, **browser only**)
|
|
62
|
+
- `ranuts/sw` — cache strategies + the precache protocol's service-worker half (**service worker only**)
|
|
59
63
|
- `ranuts/vnode` — Snabbdom-style virtual DOM
|
|
60
64
|
- `ranuts/i18n` — the i18n engine on its own, without the rest of `utils`
|
|
61
65
|
|
package/README.zh-CN.md
CHANGED
|
@@ -36,13 +36,29 @@ npm install ranuts@latest --save
|
|
|
36
36
|
|
|
37
37
|
[一些常用的函数和工具](https://ran.chaxus.com/cn/src/ranuts/)
|
|
38
38
|
|
|
39
|
+
**面向 AI / 大模型:** 从 [CLAUDE.md](./CLAUDE.md)(入口点、运行时约束、代码约定)和
|
|
40
|
+
[docs/API.md](./docs/API.md)(自动生成的 API 参考,含每个导出符号的签名与说明,用
|
|
41
|
+
`npm run doc:api` 重新生成)开始。
|
|
42
|
+
|
|
43
|
+
也可以从 `ran` 插件市场安装现成的 **Claude Code skill**,它会把导入映射、`ranuts/utils`
|
|
44
|
+
清单、用法示例和代码约定交给助手,并指向包内附带的 API 参考:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
/plugin marketplace add chaxus/ran
|
|
48
|
+
/plugin install ranuts@ran
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
装好后 Claude 会自动使用(也可以手动调用 `/ranuts:ranuts`)。
|
|
52
|
+
|
|
39
53
|
## 使用方式
|
|
40
54
|
|
|
41
55
|
按需导入。您可以选择:
|
|
42
56
|
|
|
43
|
-
- `ranuts/utils` —— DOM/BOM
|
|
57
|
+
- `ranuts/utils` —— DOM/BOM、字符串、对象、数字、颜色、时间、存储、二进制/zip、
|
|
58
|
+
Worker/IndexedDB、i18n 等工具
|
|
44
59
|
- `ranuts/node` —— HTTP 服务、路由、ws、fs、流、中间件(**仅 Node**)
|
|
45
60
|
- `ranuts/visual` —— 2D 渲染引擎(Canvas / WebGL / WebGPU,**仅浏览器**)
|
|
61
|
+
- `ranuts/sw` —— 缓存策略 + 预缓存协议的 Service Worker 一侧(**仅 Service Worker**)
|
|
46
62
|
- `ranuts/vnode` —— Snabbdom 风格的虚拟 DOM
|
|
47
63
|
- `ranuts/i18n` —— 单独的 i18n 引擎,不牵入 `utils` 的其余部分
|
|
48
64
|
|