cat-tool
v1.0.0
Published
a web development tool library
Maintainers
Readme
cat-tool
面向浏览器应用的轻量 TypeScript 工具库,提供事件总线、并发队列、IndexedDB、页面水印、定位、UUID 和函数缓存等常用能力。
安装
npm install cat-tool所有工具都支持具名导入和独立子路径导入,后者可进一步缩小打包体积:
import { PromiseQueue, getLocation, memoize, uuid } from 'cat-tool';
// 或:import { PromiseQueue } from 'cat-tool/promise-queue';常用示例
const queue = new PromiseQueue(3);
const results = await Promise.all([
queue.enqueue(() => fetch('/api/a').then((response) => response.json())),
queue.enqueue(() => fetch('/api/b').then((response) => response.json())),
]);
const cached = memoize((id: string) => expensiveLookup(id), {
max: 100,
resolver: (id) => id,
});
const location = await getLocation({ timeout: 5000, maximumAge: 60_000 });
console.log(uuid.buildID(), location, results, cached('cat'));浏览器能力(定位、IndexedDB 和水印)会在运行时检查环境,不支持时返回可捕获的 Promise 错误或明确异常。旧版拼写 getLocaltion 仍保留,但新代码请使用 getLocation。
本地开发
npm test
npm run typecheck
npm run lint
npm run build对外可见的功能或修复需要通过 npm run changeset 记录版本变化。完整发布流程见
RELEASING.md。
