Catalog npm
PACKAGE EXPLORERView in registry

55ab-loach

npm

typescript pattern project

loachpatterns
Versions collected10
Direct dependencies11From release 1.2.0
Last observed20 Oct, 20:26 UTC

README

Current package documentation

loach

TypeScript 数据结构与算法工具库。

安装

npm install 55ab-loach

使用

import { Stack, Queue, QuadTree, AsyncQueue, math } from "55ab-loach";

Stack 栈

后进先出(LIFO)数据结构。

构造

const stack = new Stack<number>();
const stack = new Stack<number>({ maxCount: 100, items: [1, 2, 3] });

API

方法说明
push(item)入栈
pushs(items)批量入栈
pop()出栈,空栈返回 undefined
pops(count)批量出栈
peek()返回栈顶元素
isEmpty()栈是否为空
isFull()栈是否已满
size()栈长度
clear()清空栈
includes(item)是否包含元素
indexOf(item)查找元素索引
remove(item)移除指定元素
toArray()转为数组
forEach(callback)遍历
toString()字符串表示

属性:maxCount(可读写,默认 1000)


Queue 队列

先进先出(FIFO)数据结构。

构造

const queue = new Queue<number>();
const queue = new Queue<number>({ maxCount: 100, items: [1, 2, 3] });

API

方法说明
enQueue(item)入队
enQueues(items)批量入队
deQueue()出队,空队列返回 undefined
deQueues(count)批量出队
front()返回队首元素
back()返回队尾元素
isEmpty()队列是否为空
isFull()队列是否已满
size()队列长度
clear()清空队列
includes(item)是否包含元素
indexOf(item)查找元素索引
remove(item)移除指定元素
toArray()转为数组
forEach(callback)遍历
toString()字符串表示

属性:maxCount(可读写,默认 1000)


QuadTree 四叉树

空间分区数据结构,适用于碰撞检测、空间查询等场景。支持矩形和圆形两种形状。

构造

const qt = new QuadTree<IQuadItemObject>({
  x: 0,
  y: 0,
  width: 800,
  height: 600,
  maxObjects: 10, // 每个节点最大对象数,默认 10
  maxLevels: 4, // 最大分割层级,默认 4
});

数据类型

// 矩形对象
const rect: IQuadItemObject = {
  shape: "rect",
  x: 10,
  y: 10,
  width: 20,
  height: 20,
};

// 圆形对象
const circle: IQuadItemObject = { shape: "circle", x: 50, y: 50, radius: 10 };

API

方法说明
insert(item)插入对象,超出阈值自动分割
inserts(items)批量插入
remove(item)移除对象,返回是否成功
query(item)查询对象所在象限中的所有对象
queryRange(range)查询矩形范围内的所有对象
contains(item)是否包含指定对象
getAllObjects()获取所有对象
getSize()获取对象总数
getDepth()获取四叉树深度
clear()清除所有对象和子节点
isPointInBounds(point)判断点是否在范围内
subdivide()手动分割为四个子节点

属性:x, y, width, height, level, maxObjects(可读写), maxLevels(可读写), nodes, objects

碰撞检测示例

const qt = new QuadTree<IQuadItemObject>({
  x: 0,
  y: 0,
  width: 800,
  height: 600,
  maxObjects: 4,
});

const player = { shape: "rect", x: 100, y: 100, width: 20, height: 20 };
qt.insert(player);

// 查询与 player 同象限的候选对象
const candidates = qt.query(player);

// 查询指定矩形范围内的对象
const nearby = qt.queryRange({
  shape: "rect",
  x: 90,
  y: 90,
  width: 40,
  height: 40,
});

AsyncQueue 异步队列

并发控制的异步函数执行队列,支持任务调度、暂停/恢复、优先级和事件订阅。

构造

const queue = new AsyncQueue<number, number>({
  concurrency: 3,       // 最大并发数,默认 1
  timeout: 5000,        // 任务超时时间(ms),默认 0(不超时)
  retryCount: 2,        // 失败重试次数,默认 0
  retryDelay: 1000,     // 重试间隔(ms),默认 1000
  autoStart: true,      // 是否自动开始,默认 true
});

API

方法说明
enqueue(task, priority?)添加任务,支持优先级
start()开始执行队列
pause()暂停执行
resume()恢复执行
clear()清空队列
abort()中止所有任务
getStats()获取队列统计信息
on(event, handler)订阅事件
off(event, handler)取消订阅

事件

事件说明
taskStart任务开始
taskEnd任务完成
taskError任务错误
taskRetry任务重试
queueEmpty队列空
queueFull队列满
pause暂停
resume恢复
statsUpdate统计更新

示例

const queue = new AsyncQueue<string, number>({ concurrency: 2 });

queue.on("taskEnd", ({ result }) => {
  console.log("任务完成:", result);
});

queue.enqueue(async () => {
  const response = await fetch("https://api.example.com/data");
  return response.json();
});

queue.enqueue(async () => "second task", 1); // 高优先级

queue.start();

math 数学工具

import { math } from "55ab-loach";

math.distance(x1, y1, x2, y2); // 两点距离
math.rad(v1, v2); // 两点角度(弧度)
math.abs(a); // 绝对值
math.random(from, to, fixed); // 随机数
math.randomUint(from, to, fixed); // 随机正数

开发

npm run build       # 构建
npm run test        # 运行测试
npm run test:watch  # 监听模式运行测试

Downloads & popularity

0downloads
1-day window · source-reported counts20 Oct 2026
6130.50
2026-07-23: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-23–2026-07-232026-07-24: 11 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-24–2026-07-242026-07-25: 10 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-25–2026-07-252026-07-26: 6 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-26–2026-07-262026-07-27: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-27–2026-07-272026-07-28: 3 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-28–2026-07-282026-07-29: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-29–2026-07-292026-07-30: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-30–2026-07-302026-07-31: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-07-31–2026-07-312026-08-01: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-01–2026-08-012026-08-02: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-02–2026-08-022026-08-03: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-03–2026-08-032026-08-04: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-04–2026-08-042026-08-05: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-05–2026-08-052026-08-06: 13 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-06–2026-08-062026-08-07: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-07–2026-08-072026-08-08: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-08–2026-08-082026-08-09: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-09–2026-08-092026-08-10: 14 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-10–2026-08-102026-08-11: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-11–2026-08-112026-08-12: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-12–2026-08-122026-08-13: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-13–2026-08-132026-08-14: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-14–2026-08-142026-08-15: 61 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-15–2026-08-152026-08-16: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-16–2026-08-162026-08-17: 5 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-17–2026-08-172026-08-18: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-18–2026-08-182026-08-19: 5 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-19–2026-08-192026-08-20: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-20–2026-08-202026-08-21: 10 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-21–2026-08-212026-08-22: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-22–2026-08-222026-08-23: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-23–2026-08-232026-08-24: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-24–2026-08-242026-08-25: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-25–2026-08-252026-08-26: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-26–2026-08-262026-08-27: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-27–2026-08-272026-08-28: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-28–2026-08-282026-08-29: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-29–2026-08-292026-08-30: 6 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-30–2026-08-302026-08-31: 3 · observed 2026-10-21T11:01:40.6624041Z · period 2026-08-31–2026-08-312026-09-01: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-01–2026-09-012026-09-02: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-02–2026-09-022026-09-03: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-03–2026-09-032026-09-04: 50 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-04–2026-09-042026-09-05: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-05–2026-09-052026-09-06: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-06–2026-09-062026-09-07: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-07–2026-09-072026-09-08: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-08–2026-09-082026-09-09: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-09–2026-09-092026-09-10: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-10–2026-09-102026-09-11: 5 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-11–2026-09-112026-09-12: 30 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-12–2026-09-122026-09-13: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-13–2026-09-132026-09-14: 10 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-14–2026-09-142026-09-15: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-15–2026-09-152026-09-16: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-16–2026-09-162026-09-17: 38 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-17–2026-09-172026-09-18: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-18–2026-09-182026-09-19: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-19–2026-09-192026-09-20: 13 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-20–2026-09-202026-09-21: 3 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-21–2026-09-212026-09-22: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-22–2026-09-222026-09-23: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-23–2026-09-232026-09-24: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-24–2026-09-242026-09-25: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-25–2026-09-252026-09-26: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-26–2026-09-262026-09-27: 4 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-27–2026-09-272026-09-28: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-28–2026-09-282026-09-29: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-29–2026-09-292026-09-30: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-09-30–2026-09-302026-10-01: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-01–2026-10-012026-10-02: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-02–2026-10-022026-10-03: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-03–2026-10-032026-10-04: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-04–2026-10-042026-10-05: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-05–2026-10-052026-10-06: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-06–2026-10-062026-10-07: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-07–2026-10-072026-10-08: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-08–2026-10-082026-10-09: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-09–2026-10-092026-10-10: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-10–2026-10-102026-10-11: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-11–2026-10-112026-10-12: 2 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-12–2026-10-122026-10-13: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-13–2026-10-132026-10-14: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-14–2026-10-142026-10-15: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-15–2026-10-152026-10-16: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-16–2026-10-162026-10-17: 1 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-17–2026-10-172026-10-18: 10 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-18–2026-10-182026-10-19: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-19–2026-10-192026-10-20: 0 · observed 2026-10-21T11:01:40.6624041Z · period 2026-10-20–2026-10-20
23 Jul20 Oct

npm · 90 observations shown. Missing days are unknown.

View observed values
Date / source periodValueObserved at
2026-10-20 – 2026-10-2002026-10-21T11:01:40.6624041Z
2026-10-19 – 2026-10-1902026-10-21T11:01:40.6624041Z
2026-10-18 – 2026-10-18102026-10-21T11:01:40.6624041Z
2026-10-17 – 2026-10-1712026-10-21T11:01:40.6624041Z
2026-10-16 – 2026-10-1602026-10-21T11:01:40.6624041Z
2026-10-15 – 2026-10-1502026-10-21T11:01:40.6624041Z
2026-10-14 – 2026-10-1402026-10-21T11:01:40.6624041Z
2026-10-13 – 2026-10-1302026-10-21T11:01:40.6624041Z
2026-10-12 – 2026-10-1222026-10-21T11:01:40.6624041Z
2026-10-11 – 2026-10-1122026-10-21T11:01:40.6624041Z
2026-10-10 – 2026-10-1022026-10-21T11:01:40.6624041Z
2026-10-09 – 2026-10-0902026-10-21T11:01:40.6624041Z
2026-10-08 – 2026-10-0802026-10-21T11:01:40.6624041Z
2026-10-07 – 2026-10-0712026-10-21T11:01:40.6624041Z
2026-10-06 – 2026-10-0602026-10-21T11:01:40.6624041Z
2026-10-05 – 2026-10-0512026-10-21T11:01:40.6624041Z
2026-10-04 – 2026-10-0402026-10-21T11:01:40.6624041Z
2026-10-03 – 2026-10-0302026-10-21T11:01:40.6624041Z
2026-10-02 – 2026-10-0222026-10-21T11:01:40.6624041Z
2026-10-01 – 2026-10-0102026-10-21T11:01:40.6624041Z
2026-09-30 – 2026-09-3002026-10-21T11:01:40.6624041Z
2026-09-29 – 2026-09-2902026-10-21T11:01:40.6624041Z
2026-09-28 – 2026-09-2802026-10-21T11:01:40.6624041Z
2026-09-27 – 2026-09-2742026-10-21T11:01:40.6624041Z
2026-09-26 – 2026-09-2602026-10-21T11:01:40.6624041Z
2026-09-25 – 2026-09-2502026-10-21T11:01:40.6624041Z
2026-09-24 – 2026-09-2422026-10-21T11:01:40.6624041Z
2026-09-23 – 2026-09-2312026-10-21T11:01:40.6624041Z
2026-09-22 – 2026-09-2202026-10-21T11:01:40.6624041Z
2026-09-21 – 2026-09-2132026-10-21T11:01:40.6624041Z
2026-09-20 – 2026-09-20132026-10-21T11:01:40.6624041Z
2026-09-19 – 2026-09-1912026-10-21T11:01:40.6624041Z
2026-09-18 – 2026-09-1812026-10-21T11:01:40.6624041Z
2026-09-17 – 2026-09-17382026-10-21T11:01:40.6624041Z
2026-09-16 – 2026-09-1612026-10-21T11:01:40.6624041Z
2026-09-15 – 2026-09-1502026-10-21T11:01:40.6624041Z
2026-09-14 – 2026-09-14102026-10-21T11:01:40.6624041Z
2026-09-13 – 2026-09-1302026-10-21T11:01:40.6624041Z
2026-09-12 – 2026-09-12302026-10-21T11:01:40.6624041Z
2026-09-11 – 2026-09-1152026-10-21T11:01:40.6624041Z
2026-09-10 – 2026-09-1012026-10-21T11:01:40.6624041Z
2026-09-09 – 2026-09-0902026-10-21T11:01:40.6624041Z
2026-09-08 – 2026-09-0802026-10-21T11:01:40.6624041Z
2026-09-07 – 2026-09-0702026-10-21T11:01:40.6624041Z
2026-09-06 – 2026-09-0602026-10-21T11:01:40.6624041Z
2026-09-05 – 2026-09-0512026-10-21T11:01:40.6624041Z
2026-09-04 – 2026-09-04502026-10-21T11:01:40.6624041Z
2026-09-03 – 2026-09-0302026-10-21T11:01:40.6624041Z
2026-09-02 – 2026-09-0202026-10-21T11:01:40.6624041Z
2026-09-01 – 2026-09-0112026-10-21T11:01:40.6624041Z
2026-08-31 – 2026-08-3132026-10-21T11:01:40.6624041Z
2026-08-30 – 2026-08-3062026-10-21T11:01:40.6624041Z
2026-08-29 – 2026-08-2912026-10-21T11:01:40.6624041Z
2026-08-28 – 2026-08-2812026-10-21T11:01:40.6624041Z
2026-08-27 – 2026-08-2722026-10-21T11:01:40.6624041Z
2026-08-26 – 2026-08-2602026-10-21T11:01:40.6624041Z
2026-08-25 – 2026-08-2502026-10-21T11:01:40.6624041Z
2026-08-24 – 2026-08-2402026-10-21T11:01:40.6624041Z
2026-08-23 – 2026-08-2302026-10-21T11:01:40.6624041Z
2026-08-22 – 2026-08-2202026-10-21T11:01:40.6624041Z
2026-08-21 – 2026-08-21102026-10-21T11:01:40.6624041Z
2026-08-20 – 2026-08-2002026-10-21T11:01:40.6624041Z
2026-08-19 – 2026-08-1952026-10-21T11:01:40.6624041Z
2026-08-18 – 2026-08-1802026-10-21T11:01:40.6624041Z
2026-08-17 – 2026-08-1752026-10-21T11:01:40.6624041Z
2026-08-16 – 2026-08-1602026-10-21T11:01:40.6624041Z
2026-08-15 – 2026-08-15612026-10-21T11:01:40.6624041Z
2026-08-14 – 2026-08-1402026-10-21T11:01:40.6624041Z
2026-08-13 – 2026-08-1302026-10-21T11:01:40.6624041Z
2026-08-12 – 2026-08-1222026-10-21T11:01:40.6624041Z
2026-08-11 – 2026-08-1102026-10-21T11:01:40.6624041Z
2026-08-10 – 2026-08-10142026-10-21T11:01:40.6624041Z
2026-08-09 – 2026-08-0902026-10-21T11:01:40.6624041Z
2026-08-08 – 2026-08-0802026-10-21T11:01:40.6624041Z
2026-08-07 – 2026-08-0702026-10-21T11:01:40.6624041Z
2026-08-06 – 2026-08-06132026-10-21T11:01:40.6624041Z
2026-08-05 – 2026-08-0502026-10-21T11:01:40.6624041Z
2026-08-04 – 2026-08-0402026-10-21T11:01:40.6624041Z
2026-08-03 – 2026-08-0302026-10-21T11:01:40.6624041Z
2026-08-02 – 2026-08-0202026-10-21T11:01:40.6624041Z
2026-08-01 – 2026-08-0112026-10-21T11:01:40.6624041Z
2026-07-31 – 2026-07-3122026-10-21T11:01:40.6624041Z
2026-07-30 – 2026-07-3012026-10-21T11:01:40.6624041Z
2026-07-29 – 2026-07-2912026-10-21T11:01:40.6624041Z
2026-07-28 – 2026-07-2832026-10-21T11:01:40.6624041Z
2026-07-27 – 2026-07-2702026-10-21T11:01:40.6624041Z
2026-07-26 – 2026-07-2662026-10-21T11:01:40.6624041Z
2026-07-25 – 2026-07-25102026-10-21T11:01:40.6624041Z
2026-07-24 – 2026-07-24112026-10-21T11:01:40.6624041Z
2026-07-23 – 2026-07-2302026-10-21T11:01:40.6624041Z

Versions 10

Collected releases
VersionPublishedDirect dependenciesOpen version
1.2.0Registry latest23 Apr 202611
1.1.220 Apr 202611
1.1.010 Apr 202611
1.0.922 Oct 202510
1.0.85 Sept 202510
1.0.72 Sept 202510
1.0.621 Aug 202510
1.0.521 Aug 202510
1.0.421 Aug 202510
1.0.320 Aug 20257

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
canc55ab/loach

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 20:26 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:bd18ce5794b23b263cd348a0b34c20af411a7deedbb2461e86b7102c56df604c