@bufbuild/cel
v0.4.0
Published
A CEL evaluator for ECMAScript
Readme
@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`,
{name: "tacocat"},
{funcs: STRINGS_EXT_FUNCS },
); // trueThat's it!
For an example of creating resusable evaluator and more, refer to the example.ts.
Types
The table below maps JS types to CEL types.
Inputcolumn is any value that can be passed to the evaluator as input. (CelInput)CEL Typecolumn is the CEL type it will represent at runtime. (CelType)Outputcolumn is the type of values that are returned by the evaluator, either as returned fromevalor as arguments to function implementations. (CelValue)
| Input (JS Type) | CEL Type (runtime) | Output (JS Type) | | --- | --- | --- | | number, {Float,Double}Value | double | number | | bigint, all signed int wrappers | int | bigint | | CelUint, all unsigned int wrappers | uint | CelUint | | string, StringValue | string | string | | Uint8Array, BytesValue | bytes | Uint8Array | | Map, ReflectMap | map | CelMap | | any[], ReflectList | list | CelList | | boolean, BoolValue | bool | boolean | | null | null_type | null | | CelType | type | CelType | | Timestamp, ReflectMessage | timestamp | ReflectMessage | | Duration, ReflectMessage | duration | ReflectMessage | | Message, ReflectMessage, Any | <typeName> | ReflectMessage | | google.protobuf.Value and friends | double/bool/string/list/map/null | number/boolean/string/CelList/CelMap |
