Skip to content

Commit

Permalink
fix build, update demo and readme
Browse files Browse the repository at this point in the history
  • Loading branch information
ChromeGG committed Mar 14, 2024
1 parent cb247d7 commit f7b400e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 20 deletions.
4 changes: 4 additions & 0 deletions demo/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ import { evaluate, parse } from 'cel-js'
const arrayExpr = '[1, 2]'
console.log(`${arrayExpr} => ${evaluate(arrayExpr)}`) // => [1, 2]

// Map expressions
const mapExpr = '{"a": 1, "b": 2}'
console.log(`${mapExpr} => ${evaluate(mapExpr)}`) // => { a: 1, b: 2 }

// Macro expressions
const macroExpr = 'size([1, 2])'
console.log(`${arrayExpr} => ${evaluate(macroExpr)}`) // => 2
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@
"release": "release-it"
},
"dependencies": {
"chevrotain": "11.0.3"
"chevrotain": "11.0.3",
"ramda": "0.29.1"
},
"devDependencies": {
"@commitlint/cli": "18.4.3",
"@commitlint/config-conventional": "18.4.3",
"@types/ramda": "0.29.11",
"@types/lodash.get": "4.4.9",
"@types/node": "20.9.0",
"@typescript-eslint/eslint-plugin": "6.10.0",
Expand Down
26 changes: 26 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Try out `cel-js` in your browser with the [live demo](https://stackblitz.com/git
- [x] string
- [ ] bytes
- [x] list
- [ ] map
- [x] map
- [x] null
- [x] Conditional Operators
- [ ] Ternary (`condition ? true : false`)
Expand Down
21 changes: 3 additions & 18 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
IdentifierDotExpressionCstNode,
IndexExpressionCstNode,
} from './cst-definitions.js'
import { deepStrictEqual } from 'assert'
import { equals } from 'ramda'

export enum CelType {
int = 'int',
Expand Down Expand Up @@ -198,15 +198,6 @@ const logicalOrOperation = (left: unknown, right: unknown) => {
throw new CelTypeError(Operations.logicalOr, left, right)
}

const comparisonEqualForMap = (left: object, right: object): boolean => {
try {
deepStrictEqual(left, right)
return true
} catch {
return false
}
}

const comparisonInOperation = (left: unknown, right: unknown) => {
if (isArray(right)) {
return right.includes(left)
Expand Down Expand Up @@ -239,17 +230,11 @@ const comparisonOperation = (
}

if (operation === Operations.equals) {
if (isMap(left) && isMap(right)) {
return comparisonEqualForMap(left, right)
}
return left === right
return equals(left, right)
}

if (operation === Operations.notEquals) {
if (isMap(left) && isMap(right)) {
return !comparisonEqualForMap(left, right)
}
return left !== right
return !equals(left, right)
}

if (operation === Operations.in) {
Expand Down

0 comments on commit f7b400e

Please sign in to comment.