Skip to content

Latest commit

 

History

History
130 lines (109 loc) · 2.54 KB

.README.md

File metadata and controls

130 lines (109 loc) · 2.54 KB

{% macro section(data) %} {{ data.comments | toc }}

{% for name, comment in data.comments %} {{ comment | docEntry }} {% endfor %} {% endmacro %}

node-expression

npm install @orioro/expression

Framework of expression interpreters.

Use cases

Data querying

Main modules: comparison and object

const person = {
  givenName: 'João',
  middleName: 'Cruz',
  familyName: 'Silva',
  age: 32,
  interests: ['sport', 'music', 'books'],
  mother: {
    givenName: 'Maria',
    familyName: 'Cruz',
    age: 57
  },
  father: {
    givenName: 'Pedro',
    familyName: 'Silva',
    age: 56
  }
}

const context = {
  interpreters,
  scope: { $$VALUE: person }
}

// Simple equality comparison
evaluate(context, ['$objectMatches', { givenName: 'João' }]) // true
evaluate(context, ['$objectMatches', { givenName: 'Maria' }]) // false

// Use dot (.) path notation to access nested properties
evaluate(context, ['$objectMatches', {
  'mother.age': { $gte: 20, $lte: 50 },
  'father.age': { $gte: 20, $lte: 50 }
}]) // false

Tree structure formatting

TODO

Conditional evaluation

TODO
// const context = {
//   interpreters,
//   scope: {
//     $$VALUE: {
//       name: 'João',
//       interests: ['music', 'sports']
//       age: 30
//     }
//   }
// }

// const cases = [
//   [['$objectMatches', {
//     interests: {
//       $arrayIncludes: 'music'
//     }
//   }]]
// ]

API

Built-in expressions:

External expression modules:

Array

{{ section(files['src/expressions/array.ts']) }}

Boolean

{{ section(files['src/expressions/boolean.ts']) }}

Comparison

{{ section(files['src/expressions/comparison.ts']) }}

Functional

{{ section(files['src/expressions/functional.ts']) }}

Logical

{{ section(files['src/expressions/logical.ts']) }}

Math

{{ section(files['src/expressions/math.ts']) }}

Number

{{ section(files['src/expressions/number.ts']) }}

Object

{{ section(files['src/expressions/object.ts']) }}

String

{{ section(files['src/expressions/string.ts']) }}

Type

{{ section(files['src/expressions/type.ts']) }}

Value

{{ section(files['src/expressions/value.ts']) }}