Skip to content

Commit 849908c

Browse files
docs: README update
1 parent a64040f commit 849908c

File tree

1 file changed

+38
-13
lines changed

1 file changed

+38
-13
lines changed

README.md

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,44 @@ A TypeScript binding for the Common Expression Language (CEL) using [cel-rust](h
66

77
[Common Expression Language (CEL)](https://github.com/google/cel-spec) is an expression language created by Google that implements common semantics for expression evaluation. It's a simple language for expressing boolean conditions, calculations, and variable substitutions. CEL is used in various Google products and open-source projects for policy enforcement, configuration validation, and business rule evaluation.
88

9+
## Usage
10+
11+
See the full [language definition][lang-def] for a complete overview of CEL.
12+
13+
[lang-def]: https://github.com/google/cel-spec/blob/master/doc/langdef.md
14+
15+
```typescript
16+
import { CelProgram } from 'cel-typescript';
17+
18+
// Basic string and numeric operations
19+
const program1 = await CelProgram.compile('size(message) > 5');
20+
await program1.execute({ message: 'Hello World' }); // true
21+
22+
// Complex object traversal and comparison
23+
const program2 = await CelProgram.compile('user.age >= 18 && user.preferences.notifications');
24+
await program2.execute({
25+
user: {
26+
age: 25,
27+
preferences: { notifications: true }
28+
}
29+
}); // true
30+
31+
// List operations and built-in functions
32+
const program3 = await CelProgram.compile('items.filter(i, i.price < 100).size() > 0');
33+
await program3.execute({
34+
items: [
35+
{ name: 'Book', price: 15 },
36+
{ name: 'Laptop', price: 1000 }
37+
]
38+
}); // true
39+
40+
// Date/time operations using timestamp() macro
41+
const program4 = await CelProgram.compile('timestamp(event_time) < timestamp("2025-01-01T00:00:00Z")');
42+
await program4.execute({
43+
event_time: '2024-12-31T23:59:59Z'
44+
}); // true
45+
```
46+
947
## Architecture
1048

1149
This project consists of three main components:
@@ -43,19 +81,6 @@ The build process creates several important files:
4381
- `index.js`: The compiled JavaScript wrapper around the native module
4482
- `index.d.ts`: TypeScript type definitions generated from the Rust code
4583

46-
## Usage
47-
48-
```typescript
49-
import { CelProgram } from 'cel-typescript';
50-
51-
// Compile a CEL expression
52-
const program = await CelProgram.compile('size(message) > 5');
53-
54-
// Execute the expression with a context
55-
const result = await program.execute({ message: 'Hello World' });
56-
console.log(result); // true
57-
```
58-
5984
## Building
6085

6186
```bash

0 commit comments

Comments
 (0)