json-logic-to-js

0.4.0 • Public • Published

Serialise JSON Logic objects into JavaScript syntax.

Usage

import renderJsonLogic from "json-logic-to-js";

assert.equal(renderJsonLogic({"<=": [{var: "age"}, 65]}), "age <= 65")

See test.js for more examples.

Motivation

JSON Logic (JL) provides a mechanism for defining custom data rules. I had a need to let users define these rules within larger documents (think online spreadsheets) where a more concise and user friendly representation of these rules would be useful. The library js-to-json-logic generates JSON Logic objects from JavaScript syntax expressions which are more concise and user friendly (IMO). However, for my use case I'll need to also transform back to JS syntax from JL objects, e.g. from a visual editor that would need to manipulate the JL object. Hence I created this library.

Requirements

  1. serialise expressions that include all defined JL operators
  2. be compatible with js-to-json-logic

Useful

https://stackoverflow.com/questions/6003884/how-do-i-check-for-null-values-in-javascript

Readme

Keywords

none

Package Sidebar

Install

npm i json-logic-to-js

Weekly Downloads

1

Version

0.4.0

License

MIT

Unpacked Size

5.01 kB

Total Files

4

Last publish

Collaborators

  • mattsouth