How to import jsonLogic into a Svelte component

115 views Asked by At

What is the syntax to import and use jsonLogic within Svelte?

1

There are 1 answers

0
w. Patrick Gale On

Using jsonLogic in Svelte requires no modifications to the jsonLogic javascript, simply import and use like so:

import jsonLogic from './logic.js';  // where logic.js is saved locally in your Svelte public folder
let objJL = jsonLogic;  // assign the jsonLogic instance to a Svelte component variable (I simply named mine objJL)
objJL.apply({"==" : [1,1] }); // try out jsonLogic (this is a true condition)

Here it is in action using the Svelte REPL: https://svelte.dev/repl/a208faeafa4a4615bb5100015d4b1f91