Comparing version 0.9.5 to 1.0.0
{ | ||
"name": "ael", | ||
"version": "0.9.5", | ||
"version": "1.0.0", | ||
"description": "Advanced Expression Language", | ||
@@ -24,3 +24,3 @@ "keywords": [ "expression", "language", "parser", "evaluator" ], | ||
"pegjs-util": "1.4.20", | ||
"asty": "1.8.11", | ||
"asty": "1.8.13", | ||
"cache-lru": "1.1.11", | ||
@@ -27,0 +27,0 @@ "source-code-error": "1.0.2" |
@@ -5,3 +5,3 @@ | ||
Advanced Expression Language (AEL) | ||
**Advanced Expression Language (AEL)** | ||
@@ -59,5 +59,5 @@ <p/> | ||
const expr = ` | ||
grant =~ /^login:(.+)$/ ? session.user.login =~ $1 : | ||
grant =~ /^email:(.+)$/ ? session.user.email =~ $1 : | ||
grant =~ /^token:(.+)$/ ? session.tokens >= $1 : false | ||
grant =~ /^login:(.+)$/ ? session?.user?.login =~ $1 : | ||
grant =~ /^email:(.+)$/ ? session?.user?.email =~ $1 : | ||
grant =~ /^token:(.+)$/ ? session?.tokens >= $1 : false | ||
` | ||
@@ -89,7 +89,7 @@ | ||
compile: | | ||
compile: | grant =~ /^login:(.+)$/ ? session.user.login =~ $1 : | ||
compile: | grant =~ /^email:(.+)$/ ? session.user.email =~ $1 : | ||
compile: | grant =~ /^token:(.+)$/ ? session.tokens >= $1 : false | ||
compile: | grant =~ /^login:(.+)$/ ? session?.user?.login =~ $1 : | ||
compile: | grant =~ /^email:(.+)$/ ? session?.user?.email =~ $1 : | ||
compile: | grant =~ /^token:(.+)$/ ? session?.tokens >= $1 : false | ||
compile: +---(abstract syntax tree)------------------------------------------------------------------------------ | ||
compile: | ConditionalTernary (expr: "\n grant =~ /^login:(.+)$/ ? session.user.login =~ $1 :\n grant =~ /^email:(.+)$/ ? session.user.email =~ $1 :\n grant =~ /^token:(.+)$/ ? session.tokens >= $1 : false\n") [2,5] | ||
compile: | ConditionalTernary [2,5] | ||
compile: | ├── Relational (op: "=~") [2,5] | ||
@@ -101,7 +101,7 @@ compile: | │ ├── Variable (id: "grant") [2,5] | ||
compile: | │ │ ├── Variable (id: "session") [2,31] | ||
compile: | │ │ ├── SelectItem [2,38] | ||
compile: | │ │ │ └── Identifier (id: "user") [2,39] | ||
compile: | │ │ └── SelectItem [2,43] | ||
compile: | │ │ └── Identifier (id: "login") [2,44] | ||
compile: | │ └── Variable (id: "$1") [2,53] | ||
compile: | │ │ ├── SelectItem (optional: true) [2,38] | ||
compile: | │ │ │ └── Identifier (id: "user") [2,40] | ||
compile: | │ │ └── SelectItem (optional: true) [2,44] | ||
compile: | │ │ └── Identifier (id: "login") [2,46] | ||
compile: | │ └── Variable (id: "$1") [2,55] | ||
compile: | └── ConditionalTernary [3,5] | ||
@@ -114,7 +114,7 @@ compile: | ├── Relational (op: "=~") [3,5] | ||
compile: | │ │ ├── Variable (id: "session") [3,31] | ||
compile: | │ │ ├── SelectItem [3,38] | ||
compile: | │ │ │ └── Identifier (id: "user") [3,39] | ||
compile: | │ │ └── SelectItem [3,43] | ||
compile: | │ │ └── Identifier (id: "email") [3,44] | ||
compile: | │ └── Variable (id: "$1") [3,53] | ||
compile: | │ │ ├── SelectItem (optional: true) [3,38] | ||
compile: | │ │ │ └── Identifier (id: "user") [3,40] | ||
compile: | │ │ └── SelectItem (optional: true) [3,44] | ||
compile: | │ │ └── Identifier (id: "email") [3,46] | ||
compile: | │ └── Variable (id: "$1") [3,55] | ||
compile: | └── ConditionalTernary [4,5] | ||
@@ -127,6 +127,6 @@ compile: | ├── Relational (op: "=~") [4,5] | ||
compile: | │ │ ├── Variable (id: "session") [4,31] | ||
compile: | │ │ └── SelectItem [4,38] | ||
compile: | │ │ └── Identifier (id: "tokens") [4,39] | ||
compile: | │ └── Variable (id: "$1") [4,53] | ||
compile: | └── LiteralValue (value: false) [4,58] | ||
compile: | │ │ └── SelectItem (optional: true) [4,38] | ||
compile: | │ │ └── Identifier (id: "tokens") [4,40] | ||
compile: | │ └── Variable (id: "$1") [4,55] | ||
compile: | └── LiteralValue (value: false) [4,60] | ||
execute: +---(evaluation recursion tree)------------------------------------------------------------------------- | ||
@@ -133,0 +133,0 @@ execute: | ConditionalTernary { |
{ | ||
"name": "astq-sample", | ||
"name": "sample", | ||
"version": "0.0.0", | ||
"dependencies": { | ||
"acorn": "7.3.1", | ||
"parse5": "6.0.1", | ||
"xmldom": "0.3.0", | ||
"less": "3.12.2", | ||
"cheerio": "1.0.0-rc.3", | ||
"unified": "9.1.0", | ||
"remark-parse": "8.0.3" | ||
}, | ||
@@ -17,4 +10,4 @@ "scripts": { | ||
"engines": { | ||
"node": ">=8.0.0" | ||
"node": ">=10.0.0" | ||
} | ||
} |
@@ -22,5 +22,5 @@ | ||
const expr = ` | ||
grant =~ /^login:(.+)$/ ? session.user.login =~ $1 : | ||
grant =~ /^email:(.+)$/ ? session.user.email =~ $1 : | ||
grant =~ /^token:(.+)$/ ? session.tokens >= $1 : false | ||
grant =~ /^login:(.+)$/ ? session?.user?.login =~ $1 : | ||
grant =~ /^email:(.+)$/ ? session?.user?.email =~ $1 : | ||
grant =~ /^token:(.+)$/ ? session?.tokens >= $1 : false | ||
` | ||
@@ -27,0 +27,0 @@ |
@@ -95,3 +95,3 @@ /* | ||
ast = result.ast | ||
ast.set("expr", expr) | ||
ast.set("__expr", expr) | ||
@@ -131,3 +131,3 @@ /* cache AST for subsequent usages */ | ||
/* evaluate the AST */ | ||
const expr = ast.get("expr") | ||
const expr = ast.get("__expr") | ||
const evaluator = new AELEval(expr, vars, state, this.options.trace) | ||
@@ -134,0 +134,0 @@ return evaluator.eval(ast) |
@@ -25,7 +25,2 @@ /* | ||
/* global describe: false */ | ||
/* global it: false */ | ||
/* jshint -W030 */ | ||
/* eslint no-unused-expressions: 0 */ | ||
const chai = require("chai") | ||
@@ -38,3 +33,12 @@ const expect = chai.expect | ||
describe("AEL Library", () => { | ||
const ael = new AEL() | ||
const ael = new AEL({ | ||
trace: (msg) => console.log(msg) | ||
}) | ||
const data = { | ||
foo: 42, | ||
bar: { baz: { quux: "quux" } }, | ||
quux: [ undefined, true, false, null, NaN, 0b11, 7, 0o7, 0xF, "quux", "quux", "quux" ] | ||
} | ||
const expectEvaluate = (expr) => | ||
expect(ael.evaluate(expr, data)) | ||
it("API availability", () => { | ||
@@ -46,14 +50,27 @@ expect(ael).to.respondTo("compile") | ||
it("literal expressions", () => { | ||
expect(ael.evaluate("true")).to.be.equal(true) | ||
expect(ael.evaluate("42")).to.be.equal(42) | ||
expect(ael.evaluate("42 + 7")).to.be.equal(49) | ||
expectEvaluate("quux[0]").to.be.equal(undefined) | ||
expectEvaluate("quux") | ||
.to.be.deep.equal(data.quux) | ||
expectEvaluate("quux == [ undefined, true, false, null, NaN, 0b11, 7, 0o7, 0xF, \"quux\", 'quux', `quux` ]") | ||
.to.be.equal(true) | ||
expectEvaluate("`foo${\"bar\"}quux`") | ||
.to.be.equal("foobarquux") | ||
}) | ||
it("conditional expressions", () => { | ||
expect(ael.evaluate("a > 0 ? b : c", { a: 1, b: 2, c: 3 })).to.be.equal(2) | ||
expect(ael.evaluate("a > 0 ? b > 1 ? true : false : c", { a: 1, b: 2, c: 3 })).to.be.equal(true) | ||
expectEvaluate("42 > 7 ? 'foo' : 'bar'") | ||
.to.be.equal("foo") | ||
}) | ||
it("boolean expressions", () => { | ||
expect(ael.evaluate("a && b || c && d", { a: true, b: true, c: false, d: false })).to.be.equal(true) | ||
expectEvaluate("true && true || false && false") | ||
.to.be.equal(true) | ||
}) | ||
it("arithmentical expressions", () => { | ||
expectEvaluate("1 + 2 + 3 - 4 * 5 - 6 / 8 + 9") | ||
.to.be.equal(-5.75) | ||
}) | ||
it("relational expressions", () => { | ||
expectEvaluate("'foo' =~ /^fo/") | ||
.to.be.equal(true) | ||
}) | ||
}) | ||
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
433632
7990
1
+ Addedasty@1.8.13(transitive)
- Removedasty@1.8.11(transitive)
Updatedasty@1.8.13