@bufbuild/cel

中文文档
0.6.2发布于 2026/11/04Apache-2.0TypeScriptESM + CJS构建来源已验证近 30 天下载 367.7万

A CEL evaluator for ECMAScript

原始使用文档

@bufbuild/cel

This package provides a CEL evaluator for ECMAScript.

Example

Let's evaluate a CEL expression that has the variable name and uses the strings extension functions:

import { run } from "@bufbuild/cel";
import { strings } from "@bufbuild/cel/ext";

run(
  `name.indexOf('taco') == 0`, // CEL expression to run
  { name: "tacocat" }, // Bind a value to the variable `name`
  { funcs: strings }, // Register `indexOf` and other string extensions
); // true

That's it!

For an example of creating a reusable evaluator and more, refer to example.ts.

Types

The table below maps JS types to CEL types.

  • Input column is any value that can be passed to the evaluator as input. (CelInput)
  • CEL Type column is the CEL type it will represent at runtime. (CelType)
  • Output column is the type of values that are returned by the evaluator, either as returned from eval or as arguments to function implementations. (CelValue)
Input (JS Type)CEL Type (runtime)Output (JS Type)
number, {Float,Double}Valuedoublenumber
bigint, all signed int wrappersintbigint
CelUint, all unsigned int wrappersuintCelUint
string, StringValuestringstring
Uint8Array, BytesValuebytesUint8Array
Map, ReflectMapmapCelMap
any[], ReflectListlistCelList
boolean, BoolValueboolboolean
nullnull_typenull
CelTypetypeCelType
Timestamp, ReflectMessagetimestampReflectMessage
Duration, ReflectMessagedurationReflectMessage
Message, ReflectMessage, Any<typeName>ReflectMessage
google.protobuf.Value and friendsdouble/bool/string/list/map/nullnumber/boolean/string/CelList/CelMap

版本与发布记录

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

版本发布日期距今
0.6.2latest2026/11/044 天前
0.6.12026/08/272 个月前
0.6.02026/06/015 个月前
0.5.02026/05/076 个月前
0.4.02026/01/219 个月前
0.3.02025/07/281.3 年前

关于 @bufbuild/cel 的常见问题

@bufbuild/cel 是什么?

A CEL evaluator for ECMAScript

如何安装 @bufbuild/cel?

在项目目录运行 npm install @bufbuild/cel,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@bufbuild/protobuf(^2.6.2)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@bufbuild/cel 支持 TypeScript 吗?

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

@bufbuild/cel 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@bufbuild/cel 可以商用吗?

@bufbuild/cel 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bufbuild/cel 的下载量有多少?

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

@bufbuild/cel 还在维护吗?

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