JS to JSONLogic
NOTICE: This module is still in beta!
npm install --save js-to-json-logic
const transformJS = ;;
How it Works
To parse input code, this module uses
|Object Expressions / Literals||full||
|Spread Operator in Arrays||full||
|Conditional (Ternary) Operator||full||
|Call Expressions with Callback||limited||
Regex Literals: are not supported by the JSON spec. To account for this, they are converted into an array of strings. The first element of the array is the pattern, the second one contains the flags. Example:
[ "\d\d\d\d", "gi" ]
If Statements: Multi-line consequentials (block statements in if statements) are not supported. Also, implicit return will always apply.
Call Expressions with Callback: Only arrow functions are allowed as callbacks in call expressions.
Arrow Functions: arrow functions can only be single-line expressions or have a one-line block statement
If a specific syntactic JS feature is not specified in the table above, it's likely that it isn't supported. If you have an idea on how to support said feature, feel free to file a GitHub Issue.
In Plans to Support
- Optional Chaining
- Nullish Coalescing
The following syntactic features are not supported by this module.
- Class Declarations
- Private name expressions
- Update Expressions (
- Assignment Expressions
- Tagged Template Expressions
- Function Declaration
- While Loops
- For Loops
- Multi-Line Block Statements
- Destructuring assignment
- Rest operator
- Spread operator (although it works within array expressions)
Bug Reports & Feature Requests
Something does not work as expected or perhaps you think this project needs a feature? Please open an issue using GitHub issue tracker.
Make sure that an issue pointing out your specific problem does not exist already. Please be as specific and straightforward as possible.
Pull Requests (PRs) are welcome! You should follow the same basic stylistic conventions as the original code.
Make sure that a pull request solving your specific problem does not exist already. Your changes must be concise and focus on solving a discrete problem.
Copyright (c) 2020 Kristian Muñiz