Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marcisbee/jsonlogic-formula
JsonLogic parser to and from spreadsheet formula syntax
https://github.com/marcisbee/jsonlogic-formula
Last synced: about 2 months ago
JSON representation
JsonLogic parser to and from spreadsheet formula syntax
- Host: GitHub
- URL: https://github.com/marcisbee/jsonlogic-formula
- Owner: Marcisbee
- License: mit
- Created: 2023-10-11T12:44:59.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-08T10:11:05.000Z (9 months ago)
- Last Synced: 2024-10-11T13:08:17.193Z (3 months ago)
- Language: TypeScript
- Size: 19.5 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jsonlogic-formula
JsonLogic parser to and from spreadsheet formula syntax;* **Small.** 1.6 kilobytes (minified and gzipped).
Zero dependencies.
* **Smart.** Understands & parses custom functions.
* It has good **TypeScript** support.```ts
import { formulaToJsonlogic } from "jsonlogic-formula"const formula = "AND(OR(some.value,false),or(TRUE,FALSE))"
formulaToJsonlogic(formula) // => {"and":[{"or":[{"var":"some.value"},false]},{"or":[true,false]}]}
```
[live demo](https://dune.land/dune/895e714b-feb2-47d7-9261-0413737c9c84)```ts
import { jsonlogicToFormula } from "jsonlogic-formula"const logic = {"and":[{"or":[{"var":"some.value"},false]},{"or":[true,false]}]}
jsonlogicToFormula(logic) // => "AND(OR(some.value,false),or(TRUE,FALSE))"
```
[live demo](https://dune.land/dune/895e714b-feb2-47d7-9261-0413737c9c84)## Install
```sh
npm install jsonlogic-formula
```## API
### formulaToJsonlogic
```ts
function formulaToJsonlogic(value: string): jsonlogic
```### jsonlogicToFormula
```ts
function jsonlogicToFormula(value: jsonlogic): string
```# Motivation
Jsonlogic is very powerful tool, but it is not easy for the end users to understand it. Since anyone with basic Excel/Spreadsheet knowledge can understand formula syntax (e.g. `SUM(A1,B1)`) it makese sense to have a parser that can transform formula to jsonlogic and jsonlogic to formula. This makes UX way better.# License
[MIT](LICENCE) © [Marcis Bergmanis](https://twitter.com/marcisbee)