@cooklang/cooklang

中文文档
0.19.1发布于 2026/10/15MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 5888

Official Cooklang parser - Rust-powered WASM implementation for high performance recipe parsing

原始使用文档
文档目录14 节
  1. Installation
  2. Quick Start
  3. Why WASM?
  4. Migration from @cooklang/cooklang-ts
  5. API Reference
  6. Parser
  7. Recipe Structure
  8. Helper Functions
  9. Value Extraction
  10. Version Synchronization
  11. Browser Support
  12. Contributing
  13. License
  14. Links

@cooklang/cooklang

Official Cooklang parser for JavaScript and TypeScript.

This is a high-performance WASM implementation powered by the Rust cooklang-rs parser. It provides fast, reliable recipe parsing with full support for the Cooklang specification.

Installation

npm install @cooklang/cooklang

Quick Start

import { Parser } from '@cooklang/cooklang';

const parser = new Parser();
const recipe = parser.parse(`
>> servings: 4

Add @salt and @pepper to taste.
Cook for ~{10%minutes}.
`);

console.log(recipe.sections[0].content);

Why WASM?

This package uses WebAssembly for several key benefits:

  • Performance: Native-speed parsing, significantly faster than pure JavaScript
  • Reliability: Shared implementation with the official Rust parser means consistent behavior across platforms
  • Maintainability: Changes to the Cooklang spec are implemented once in Rust and automatically available here

Migration from @cooklang/cooklang-ts

If you're migrating from the previous TypeScript-native @cooklang/cooklang-ts package (v1.x), please see the Migration Guide.

Key differences:

  • Different package name: @cooklang/cooklang-ts → @cooklang/cooklang
  • API changes: The WASM implementation has a different API surface
  • Version numbering: This package tracks the Rust core version (currently 0.17.x)

API Reference

Parser

import { Parser } from '@cooklang/cooklang';

const parser = new Parser();
const recipe = parser.parse(recipeText);

Recipe Structure

The parsed recipe contains:

interface Recipe {
  sections: Section[];
  metadata: Record<string, string>;
  ingredients: Ingredient[];
  cookware: Cookware[];
  timers: Timer[];
}

Helper Functions

import {
  ingredient_should_be_listed,
  ingredient_display_name,
  cookware_should_be_listed,
  cookware_display_name,
  quantity_display,
  grouped_quantity_display,
  grouped_quantity_is_empty
} from '@cooklang/cooklang';

Value Extraction

Utility functions for working with quantities:

import { getNumericValue, extractNumericRange } from '@cooklang/cooklang';

const value = ingredient.quantity?.value;
const numeric = getNumericValue(value); // 2.5
const range = extractNumericRange(value); // { start: 2, end: 3 }

Version Synchronization

This package version tracks the Rust cooklang-rs version. For example:

We use 0.x versioning to match the Rust core library. The parser is production-ready and actively maintained. We'll bump to 1.0 when the Rust core reaches 1.0.

Browser Support

This package works in:

  • Node.js 16+
  • Modern browsers (Chrome, Firefox, Safari, Edge)
  • Bundlers (Webpack, Vite, Rollup, etc.)

Contributing

This package is part of the cooklang-rs monorepo. Contributions are welcome!

License

MIT - see LICENSE

版本与发布记录

@cooklang/cooklang 共发布 4 个版本,首次发布于 2025/11/24;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.19.1latest2026/10/1526 天前
0.19.02026/09/301 个月前
0.18.72026/06/095 个月前
0.17.22025/11/2411 个月前

关于 @cooklang/cooklang 的常见问题

@cooklang/cooklang 是什么?

Official Cooklang parser - Rust-powered WASM implementation for high performance recipe parsing

如何安装 @cooklang/cooklang?

在项目目录运行 npm install @cooklang/cooklang,或使用 pnpm add / yarn add / bun add。

@cooklang/cooklang 支持 TypeScript 吗?

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

@cooklang/cooklang 支持 ESM 还是 CommonJS?

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

@cooklang/cooklang 可以商用吗?

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

@cooklang/cooklang 的下载量有多少?

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

@cooklang/cooklang 还在维护吗?

最新版本 0.19.1 发布于 2026/10/15(26 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2025/11/24。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。