Gathering detailed insights and metrics for js-to-json-logic
Gathering detailed insights and metrics for js-to-json-logic
Gathering detailed insights and metrics for js-to-json-logic
Gathering detailed insights and metrics for js-to-json-logic
json-rules-engine-to-json-logic
A minimal Typescript library for converting a json-rules-engine condition to a JsonLogic rule specification.
json-logic-to-js
Serialise JsonLogic objects into JavaScript syntax.
picklogic
A JS engine to pick among JSON objects based on simple logic conditions
@omegion1npm/eos-officiis-non
A way to separate business logic from application view.
npm install js-to-json-logic
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
43 Stars
29 Commits
11 Forks
4 Watchers
11 Branches
1 Contributors
Updated on Jul 04, 2024
Latest Version
0.1.3
Package Id
js-to-json-logic@0.1.3
Unpacked Size
15.43 kB
Size
5.60 kB
File Count
6
NPM Version
6.14.5
Node Version
12.18.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Transform JavaScript expressions into JSONLogic objects. For Node.js.
NOTICE: This module is still in beta!
1npm install --save js-to-json-logic
1const transformJS = require("js-to-json-logic"); 2 3transformJS('temp < 110 && pie.filling === "apple"');
The transformJS
function returns a JavaScript object, which can be stringified as a JSON and look like this:
1{ 2 "and": [ 3 { 4 "<": [ 5 { 6 "var": "temp" 7 }, 8 110 9 ] 10 }, 11 { 12 "===": [ 13 { 14 "var": "pie.filling" 15 }, 16 "apple" 17 ] 18 } 19 ] 20}
To parse input code, this module uses @babel/parser
to parse JavaScript code into an Abstract Syntax Tree (AST). The tree is then transformed into a JSONLogic object.
Said object is can then be used with the json-logic-js
module to apply the interpreted rules to any type of data. Learn More
expression | support | examples |
---|---|---|
Boolean Literals | full | true , false |
String Literals | full | "banana" , "hello world" |
Template Literals | full | `hello, ${first_name}` |
Numeric Literals | full | 1 , 2.04 , -10292.64 , 0b01011010 , 0xFF00FF , etc. |
Object Expressions / Literals | full | ({ a: [1, false, 'string'], b: false, d: 'hello' }) |
Array Expressions | full | [1, 2, 3] |
Spread Operator in Arrays | full | [1, 2, ...myArr] |
Null Literals | full | null |
Identifiers (variables) | full | myVar , deep.property |
Comparison Expressions | full | a > b , a < b , a <= b , a === b , a !== b , etc. |
Arithmetic Operators | full | a + b , a * b , a - b , a / b , a % b |
Call Expressions | full | myFunction(a, b, c) |
Unary Expressions | full | !cond , !!cond , -var , +var |
Conditional (Ternary) Operator | full | condition ? a : b |
Regex Literal | limited | /[^@]+@[^\.]+\..+/gi |
If Statements | limited | if (condA) { a } else if (condB) { b } else { c } |
Call Expressions with Callback | limited | map(arr, x => x + 1) |
Arrow Functions | limited | x => x + 1 , (a, b) => a + b |
Notes:
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.
The following syntactic features are not supported by this module.
#myPrivateProperty
i++
, i--
, etc.)new
operatorSomething 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
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/27 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
26 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More