open-index/open-npm huggingface dataset:
npm package: @ianj15/ws-utils
Description: 实现了一个功能完善的 WebSocket 客户端类 WebSocketClient，支持心跳机制、断线重连和心跳超时重连等功能
Author: ianj21
Latest version: 0.0.3

### ws-utils

### Instructions

实现了一个功能完善的 WebSocket 客户端类 WebSocketClient，支持心跳机制、断线重连和心跳超时重连等功能

### Example

```
import WebSocketClient from "@ianj15/ws-utils";

const wsClient = new WebSocketClient("ws://example.com/socket", {
  onOpen: () => console.log("连接已打开"),
  onMessage: (event) => console.log("收到消息:", event.data),
  onClose: (event) => console.log("连接已关闭", event.code, event.reason),
  onError: (error) => console.error("连接错误:", error),
});

// 发送消息
wsClient.send({ type: "message", content: "Hello, Server!" });

// 关闭连接
// wsClient.close();
```

### API


| 参数                 | 说明                     | 类型            | 默认值 |
| -------------------- | ------------------------ | --------------- | ------ |
| reconnectInterval    | 初始重连间隔时间（毫秒） | number          | 5000   |
| maxReconnectInterval | 最大重连间隔时间（毫秒） | number          | 60000  |
| heartbeatInterval    | 心跳间隔时间（毫秒）     | number          | 30000  |
| heartbeatTimeout     | 心跳超时时间（毫秒）     | number          | 10000  |
| maxReconnectAttempts | 最大重连次数             | number          | 5      |
| maxHeartbeatTimeouts | 最大心跳超时次数         | number          | 3      |
| onOpen               | 连接已打开               | Function        |        |
| onMessage            | 收到消息                 | Function(event) |        |
| onClose              | 连接已关闭               | Function(event) |        |
| onError              | 连接错误                 | Function(event) |        |
npm package: @ianjdarrow/monotonic
Description: ### Always-incrementing unique IDs based on timestamps
Latest version: 1.0.2

# monotonic

### Always-incrementing unique IDs based on timestamps

`monotonic` is a simple package to generate unique IDs based on timestamps. We use it to differentiate websocket messages generated by a single server that clients could receive duplicatively over multiple subscriptions.

By default, `monotonic` generates strings like:

```
1650627455:000000
1650627455:000001
1650627455:000002
1650627456:000000
```

...et cetera. There's also an constructor option to return results as numbers.

## Usage

```js
import { Monotonic } from "@ianjdarrow/monotonic";

const mono = new Monotonic({
  maxEventsPerBase: number, // default 1_000_000
  resolution: "seconds" | "ms", // default "seconds"
  outputFormat: "string" | "number", // default "string"
});
// 1 million distinct IDs generated
for (let i = 0; i < 1e6; i++) {
  mono.get();
}
```

You can also split the timestamp and nonce back out. This is mostly useful with `outputFormat: 'number'`.

```js
const mono = new Monotonic({ outputFormat: "number" });
const ts = mono.get();
// later...
const { timestamp, nonce } = mono.split(ts); // something like { 1650627455, 0 }
```

`monotonic` will throw an error if you try to generate more than `maxEventsPerBase` per `resolution`. By default this is 1,000,000 events per second.

Be aware: with `outputFormat: 'number'` and `resolution: 'ms'`, `maxEventsPerBase` can't exceed 1,000 (to avoid exceeding `Number.MAX_SAFE_INTEGER`).