npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

koka

v1.0.9

Published

Lightweight 3kB Effect-TS alternative library based on Algebraic Effects

Readme

Koka - 基于代数效应的轻量级 TypeScript 效果管理库

警告:此库处于早期开发阶段,可能会发生重大变化。请勿在生产环境中使用。

Koka 是一个基于代数效应的轻量级 TypeScript 效果管理库,提供结构化错误处理、上下文管理和异步操作,具有可组合性和类型安全性。

📚 文档导航

📋 快速导航

🚀 快速开始

安装

npm install koka
# 或
yarn add koka
# 或
pnpm add koka

基本使用

import { Eff } from 'koka'

// 错误处理
function* getUser(id: string) {
    if (!id) {
        yield* Eff.err('ValidationError').throw('ID is required')
    }
    return { id, name: 'John Doe' }
}

// 上下文管理
function* calculateTotal() {
    const discount = yield* Eff.ctx('Discount').get<number>()
    return 100 * (1 - discount)
}

// 异步操作
async function* fetchData() {
    const response = yield* Eff.await(fetch('/api/data'))
    return response.json()
}

// 运行效果
const result = await Eff.run(
    Eff.try(getUser('123')).catch({
        ValidationError: (error) => ({ error }),
    }),
)

✨ 核心特性

  • 类型安全 - 完整的 TypeScript 支持
  • 轻量级 - 仅 ~3kB gzipped
  • 可组合 - 效果自然组合
  • 异步就绪 - 无缝 Promise 集成
  • 设计优先 - 支持预定义效果类型

🔄 与 Effect-TS 对比

| 特性 | Koka | Effect-TS | | ---------- | ---- | --------- | | 错误效果 | ✅ | ✅ | | 上下文效果 | ✅ | ✅ | | 异步效果 | ✅ | ✅ | | 可组合性 | ✅ | ✅ | | 类型安全 | ✅ | ✅ | | 最小 API | ✅ | ❌ | | 完整生态 | ❌ | ✅ | | 学习曲线 | 低 | 高 | | 包大小 | ~3kB | ~50kB |

Koka 是 Effect-TS 的轻量级替代方案,专注于提供核心的效果管理功能,而无需完整的生态系统。

📖 文档结构

教程 (Tutorials)

操作指南 (How-to Guides)

参考文档 (Reference)

解释文档 (Explanations)

🤝 贡献

欢迎提交 PR!请确保测试通过,新功能包含适当的测试覆盖。

📄 许可证

MIT