publicodes
v1.6.0
Published
A declarative language for encoding public algorithm
Downloads
3,093
Keywords
Readme
Getting started
npm install publicodes
The library exports a default class Engine
which allows you to instantiate an publicodes interpreter with a set of publicodes rules.
import Engine from 'publicodes'
import { parse as parseYaml } from 'yaml'
// We define a list of publicodes rules
const rules = `
dépenses primeur:
somme:
- 1.5 kg * 2€/kg # carottes
- 500g * 6€/kg # champignons
- 3 avocats * 1.5€/avocats
`
const parsedRules = parseYaml(rules)
const engine = new Engine(parsedRules)
const result = engine.evaluate('dépenses primeur')