Skip to content

This is a basic project to convert plain JavaScript to json-logic notation. PRs welcome.

License

Notifications You must be signed in to change notification settings

lucas2595/js2jl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

js2jl

This is a basic project to convert plain javaScript to json-logic notation.

Installation:

npm install js2jl

or with yarn

yarn add js2jl

Usage:

import js2jl from 'js2jl'

const infix = "A + B - 2"

const logic = js2jl(infix) 
//  logic contains:
//  {
//      "-": [
//          {
//              "+": [
//                  {
//                      "var": "A"
//                  },
//                  {
//                      "var": "B"
//                  }
//              ]
//          },
//          2
//      ]
//  }

Currently supported operators (ordered by precedency):

  • *, /, %;
  • +, -, cat, in, substr;
  • ===, !==, ==, !=, <, >, <=, >=, or, and;
  • ? followed by :, filter, map, reduce followed by initial, method followed by arguments.

Only if, reduce and method are currently supporting three arguments; the rest uses only two.

Arrays, objects, and strings are being parsed (but only strings that don't contain any spaces for now); anything else is treated as a variable.

Important:

  1. Operators and operands must be separated by a space.
  2. to make {"var": ""} use two spaces one after another.

Here's a sandbox with this project running

About

This is a basic project to convert plain JavaScript to json-logic notation. PRs welcome.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published