# @e280/stz 中文文档

规范地址：https://npmcn.com/package/%40e280/stz/

版本：0\.4\.18
npm 元数据更新时间：2026-11-12T01:35:56.626Z
中文译文更新时间：2026-11-13T03:14:17.749Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40e280/stz
原文对照：https://npmcn.com/package/%40e280/stz/?lang=original
项目主页：https://github.com/e280/stz#readme
源码仓库：https://github.com/e280/stz

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：390 kB，459 个文件
- 模块格式：ES Module
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2025-04-12T22:10:10.272Z
- 最新版本发布：2026-11-12T01:35:56.190Z
- 近 30 天下载量：6365（2026-10-13 至 2026-11-11，npm 官方下载统计）
- 已发布版本数：120（近 12 个月 56 个）

## 中文简介

每件事物的日常费用

## 安装

```sh
npm install @e280/stz
```

也可以使用：`pnpm add @e280/stz`、`yarn add @e280/stz`、`bun add @e280/stz`

## README

# 🏂 `@e280/stz`

> _我每天的打字员_

环境不可知的零依赖工具和公用事业。 以 [https://e280.org/ (中文(简体) )](https://e280.org/)

🍴 [**器具**](https://npmcn.com/package/%40e280/stz/#readme-utensils)  
⏳ [**aync/fns 图像**](https://npmcn.com/package/%40e280/stz/#readme-async)  
📣 [**子键**](https://npmcn.com/package/%40e280/stz/#readme-subby)  
🧹 [**家务**](https://npmcn.com/package/%40e280/stz/#readme-housekeeping)  
🎲 [**兰德**](https://npmcn.com/package/%40e280/stz/#readme-rand)  
✅ [**好吧,错误,结果**](https://npmcn.com/package/%40e280/stz/#readme-ok)  
🧬 [**十六进制及更多**](https://npmcn.com/package/%40e280/stz/#readme-hex)

  

```sh
npm install @e280/stz
```

```ts
import {got} from "@e280/stz"
```

  

## 餐具

-   **已经** ——如果值为无效或未定义,则抛出错误.
    
    ```ts
    const value = got(nullableValue)
    ```
    
-   **需求** ——返回地图值,如果缺少,则丢出错误.
    
    ```ts
    const value = need(map, "my_key")
    ```
    
-   **保证** ——获得-或创建地图值.
    
    ```ts
    const value = guarantee(map, "my_key", () => 123)
    ```
    
-   **设置** ——同时设置许多地图条目.
    
    ```ts
    setEntries(map, [["my_key1", 123], ["my_key2", 234]])
    ```
    
-   **双图** - 就像普通地图,但是.. `keyOf` 让它双侧.
    
    ```ts
    const labels = new Bimap<number, string>()
    labels.set(1, "alpha")
    labels.set(2, "bravo")
    
    // it's a normal map.
    labels.get(1) // "alpha"
    
    // but it also has this 'keyOf' method.
    labels.keyOf("alpha") // 1
    ```
    
-   **何时** - 做一些事情 当事情是真实的.
    
    ```ts
    when(map.size > 10, () => console.log(map))
    ```
    
-   **给定** 当事物不是无效的,也不是没有定义时,做点什么.
    
    ```ts
    given(map.get(id), item => console.log(item))
    ```
    
-   **计数** - 绝对数字.
    
    ```ts
    for (const i of count(4))
      console.log(i)
    ```
    
-   **网格** ——斜列和行.
    
    ```ts
    for (const [x, y] of grid(2, 4))
      console.log(x, y)
    ```
    
-   **数组限制** ——以倒放最老来限制数组长度.
    
    ```ts
    const trimmed = arraylimit(["a", "b", "c", "d"], 2)
      // ["c", "d"]
      // returns new array if trimming happens,
      // otherwise returns the same array unchanged.
    ```
    
-   **烟斗** ——通过数fns运行数据.
    
    ```ts
    const result = pipe(rawData)
      .to(parse)
      .to(validate)
      .to(normalize)
      .done()
    ```
    
-   **缩写** ——在对象条目上映射.
    
    ```ts
    const alpha = {alpha: 1, bravo: 2, charlie: 3}
    ```
    
    ```ts
    obmap(alpha, n => n * 10)
      // {alpha: 10, bravo: 20, charlie: 30}
    ```
    
-   **过滤器** ——过滤对象条目.
    
    ```ts
    obfilter(alpha, n => n > 1)
      // {bravo: 2, charlie: 3}
    ```
    
-   **深冻** ——递归对象. 冻结对象树.
    
    ```ts
    const freezie = deepFreeze({alpha: 123})
    
    freezie.alpha = 5 // throws error
    ```
    
-   **深等号** ——检查两个对象树是否有相同的原始值.
    
    ```ts
    deepEqual({alpha: 123}, {alpha: 123})
      // true
    ```
    
-   **是快乐** ——用合适的类型警卫检查物品的身份.
    
    ```ts
    isHappy(0) // true if not null nor undefined.
    isSad(undefined) // true if null or undefined.
    isBoolean(true) // true
    isNumber(123) // true
    isString("hello") // true
    isBigint(123n) // true
    isArray([]) // true
    isObject({}) // true
    isFn(() => {}) // true
    isSymbol(Symbol()) // true
    ```
    
-   **秒数** ——持续时间和时间戳.  
    持续时间 :
    
    ```ts
    seconds(1) // 1000
    minutes(1)
    hours(1)
    days(1)
    ```
    
    日期后的时间戳。 现在 :
    
    ```ts
    futureSeconds(1)
    futureMinutes(1)
    futureHours(1)
    futureDays(1)
    ```
    
    日期前的时间戳。 现在:
    
    ```ts
    pastSeconds(1)
    pastMinutes(1)
    pastHours(1)
    pastDays(1)
    ```
    

  

## \*

-   **睡觉** ——归还一个以后会解决的承诺.
    
    ```ts
    await nap(1000) // sleep for one second.
    ```
    
-   **周期** ——再三调用fn回放.
    
    ```ts
    const stop = cycle(async() => {
      console.log("hello!", Date.now())
      await nap(1000) // once per second.
    })
    ```
    
    ```ts
    stop() // cancel the cycle.
    ```
    
-   **并行** ——等待一批出名的承诺.
    
    ```ts
    const {user, settings} = await concurrent({
      user: myFetchUser(),
      settings: myFetchSettings(),
    })
    ```
    
-   **推迟** ——一个承诺,你可以解决/从外部拒绝.
    
    ```ts
    const ready = defer<string>()
    
    ready.resolve("hello")
    
    await ready
      // "hello"
    ```
    
    ```ts
    ready.reject(new Error("rejected"))
    ```
    
-   **收集** ——能同步到阵列.
    
    ```ts
    const entries = await collect(kv.entries())
    ```
    
-   **一次** - 只执行一次fn.
    
    ```ts
    const init = once(() => connect())
    init()
    init() // doesn't initialize twice.
    ```
    
-   **队列** 使async fn呼叫一次工作.
    
    ```ts
    const save = queue(async(myData: string) => myWriteData(myData))
    
    await Promise.all([save("a"), save("b"), save("c")])
      // actually executes sequentially.
    ```
    
-   **车道** ——制造一台能执行任意aync fn的一时一机.
    
    ```ts
    const mutex = lane()
    
    await Promise.all([
      mutex(async() => writeMyData("a")),
      mutex(async() => writeMyData("b")),
      mutex(async() => writeMyData("c")),
    ]) // executes jobs sequentially.
    ```
    
-   **截止日期** ——增加过期超时.
    
    ```ts
    const connection = await deadline(10_000, connect)
      // throw DeadlineError after 10s unless connect resolves.
      // connect can be a promise or an async fn.
    ```
    
-   **弹跳** - 一段时间后调用dudupe.
    
    ```ts
    const search = debounce(250, async(s: string) => query(s))
    
    search("l")
    search("lo")
    await search("lol") // last one actually runs.
    ```
    
-   **微弹跳** - 调试这个微工作.
    
    ```ts
    let count = 0
    const run = microbounce(() => count++)
    
    const done = run()
    run()
    run()
    
    await done
    count // 1
    ```
    

  

## {\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}你是谁

-   **子键** ——创建订阅者fn.
    
    ```ts
    const on = subby<[number]>()
    ```
    
    ```ts
    const off = on(x => console.log(x))
    ```
    
    ```ts
    on.publish(123)
      // 123
    ```
    
    ```ts
    off() // stop listening.
    ```
    
-   **阴道** ——创建出版社fn.
    
    ```ts
    const publish = pubby<[number]>()
    ```
    
    ```ts
    const off = publish.on(x => console.log(x))
    ```
    
    ```ts
    publish(123)
      // 123
    ```
    
    ```ts
    off() // stop listening.
    ```
    
-   {\\fn黑体\\fs22\\bord1\\shad0\\3ahbe\\4ah00\\fscx67\\fscy66\\2chffffff\\3ch808080}"subby"和"pubby" 都给你一个好包.
    
    ```ts
    // limited 'on' and 'publish' fns without whole toolkit.
    const {on, publish} = subby()
    ```
    
    ```ts
    const {publishAsync} = subby()
    
    await publishAsync(123)
      // awaits every listener (they can be async).
    ```
    
    ```ts
    const [value] = await on.next() // wait for the next publish.
      // value is 123
    ```
    
    ```ts
    on.set.size // direct access to the set of listeners.
    ```
    

  

## 家居管理

-   **页:1** ——事件听众.
    
    ```ts
    import {ev} from "@e280/stz"
    
    const off = ev(window, {
        keydown: event => console.log(event),
        keyup: event => console.log(event),
    })
    
    off() // removes both listeners
    ```
    
-   **处置者** ——清理资源.
    
    ```ts
    const dispose = disposer()
    
    dispose.schedule(() => console.log("dispose 1"))
    dispose.schedule(() => console.log("dispose 2"))
    dispose.schedule(cycle(myGameloop))
    dispose.schedule(ev(window, {keydown: myKeydown}))
    
    dispose() // dispose everything backwards
      // *dispose ev*
      // *dispose cycle*
      // "dispose 2"
      // "dispose 1"
    ```
    
    更多的处置者诡计.
    
    ```ts
    const myThing = dispose.own(new MyThing(), t => t.dispose())
      // create a thing and schedule its dispose
    ```
    
    ```ts
    const myThing = dispose.disposable(new MyThing())
      // return and schedule a Disposable thing
    ```
    
    ```ts
    const {dispose, schedule, own, disposable} = disposer()
    
    schedule(cycle(myGameloop))
    const myThing = disposable(new MyThing)
    
    dispose()
    ```
    

  

## 兰德

-   **兰德** ——随机效用.
    
    ```ts
    const rand = new Rand(Math.random)
    ```
    
    ```ts
    const rand = new Rand(mulberry(123))
      // seeded pseudo-random number generator
    ```
    
    ```ts
    rand.u32() // get a random unsigned 32-bit integer.
      // 3286174905
    
    rand.roll(0.25) // 25% chance of true.
      // false
    
    rand.range(10, 20) // random float between two numbers.
      // 14.8591238
    
    rand.integerRange(1, 6) // inclusive integer range.
      // 4
    
    rand.index(7) // given array length, pick an array index.
      // 5
    
    rand.pick(["a", "b", "c"]) // pick your poison.
      // "c"
    
    rand.select(2, ["a", "b", "c"]) // pick multiple.
      // ["a", "c"]
    
    rand.yoink(["a", "b", "c"]) // remove and return one array element.
      // "a"
    
    rand.extract(2, ["a", "b", "c"]) // yoink multiple.
      // ["b", "c"]
    
    rand.shuffle(["a", "b", "c"]) // random-sort array in-place.
      // ["c", "a", "b"]
    ```
    
-   **浆果** ——种子假随机数生成器.
    
    ```ts
    const random = mulberry(123)
    
    random()
      // 0.7872516233474016
    
    random()
      // 0.1785435655619949
    ```
    
-   **兰德32** ——密码随机无符号32位整数.
    
    ```ts
    rand32()
      // 3948271056
    ```
    
-   **hash32 键盘** ——将 en混合为32位整数(快,非晶体).
    
    ```ts
    hash32(123, "hello", 234, "world")
      // 1012994381
    ```
    

  

## 好吧,错误,结果

-   **还好** —— 说 `Ok<Value>` 表明成功.
    
    ```ts
    ok(123)
      // {ok: true, value: 123}
    ```
    
-   **错误** —— 说 `Err<E>` - 表示失败.
    
    ```ts
    err("fail")
      // {ok: false, error: "fail"}
    ```
    
-   `Result<Value, E>` 表明某种东西可能成功或失败.
    
    ```ts
    let result: Result<number, "fail"> = ok(123)
    
    result = err("fail")
    ```
    
-   **获取 Ok/ Get Err** - 获得价值,或 `undefined`。 。 。 .
    
    ```ts
    getOk(ok(123)) // 123
    getOk(err("fail")) // undefined
    
    getErr(ok(123)) // undefined
    getErr(err("fail")) // "fail"
    ```
    
-   **获取 Ok/ gotErr** - 得到价值,或掷出.
    
    ```ts
    gotOk(ok(123)) // 123
    gotOk(err("fail")) // throws Error("fail")
    
    gotErr(ok(123)) // throws error
    gotErr(err("fail")) // "fail"
    ```
    

  

## 十六岁及以上

-   **六进制** ——编码/解码为十六进制数据.
    
    ```ts
    hex(bytes) // encode Uint8Array bytes to string.
    hex.toBytes(string) // decode string to bytes.
    hex.toInteger(string) // decode string as integer.
    hex.fromInteger(n) // encode integer as a string.
    hex.random(32) // generate random encoded string, 32 bytes.
    ```
    
    ```ts
    // we have more than just hex.
    hex(bytes) // string
    base2(bytes) // string
    base36(bytes) // string
    base58(bytes) // string
    base62(bytes) // string
    base64(bytes) // string
    base64url(bytes) // string
    ```
    
-   **txt 时** ——文本数据.
    
    ```ts
    txt(bytes) // convert utf8 bytes to string.
    txt.toBytes("hello") // convert string to utf8 bytes.
    ```
    
-   **字节** - 公用事业.
    
    ```ts
    bytes.eq(bytesA, bytesB) // true if they're equal.
    bytes.random(32) // get 32 crypto-random bytes.
    ```
    
-   **数据查看** ——制作一个匹配打入数组的偏移的 DataView .
    
    ```ts
    dataView(new Uint8Array([0, 1, 2, 3, 4]))
    ```
    

  
  

🧑‍💻 _[https://e280.org/ (中文(简体) )](https://e280.org/)_

## 常见问题

### @e280/stz 是什么？

每件事物的日常费用

### 如何安装 @e280/stz？

在项目目录运行 npm install @e280/stz，或使用 pnpm add / yarn add / bun add。

### @e280/stz 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @e280/stz 支持 ESM 还是 CommonJS？

以 ES Module 形式发布，推荐使用 import 引入。在 CommonJS 项目中，Node\.js 20\.19\+ / 22\.12\+ 可以直接 require\(\) 不含顶层 await 的 ES Module，更早的版本需要改用动态 import\(\)。

### @e280/stz 可以商用吗？

@e280/stz 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @e280/stz 的下载量有多少？

根据 npm 官方下载统计，@e280/stz 在 2026/10/13 – 2026/11/11 这 30 天内被下载 6,365 次，日均约 212 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @e280/stz 还在维护吗？

最新版本 0\.4\.18 发布于 2026/11/12（1 天前）；至今共发布 120 个版本，其中过去 12 个月发布了 56 个；首次发布于 2025/04/13。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

