Skip to content

robocoder/formcalc-js

Repository files navigation

formcalc-js

formcalc-js is an open-source, clean-room JavaScript implementation of the XFA-FormCalc language. The lexer, parser, and interpreter were built using Chevrotain.

Why?

Inspired by htmx and the locality of behavior principle, I wanted to explore the adaptation of XFA-FormCalc for validation and calculated fields in HTML forms.

Usage

<script type="importmap">
{
  "imports": {
    "chevrotain": "https://unpkg.com/chevrotain@11.0.3/lib/chevrotain.min.mjs",
    "formcalc": "https://unpkg.com/formcalc@1.0.1/dist/formcalc.mjs"
  }
}
</script>

<script type="module">
    import { calculate } from "formcalc";

    const results = calculate('1 + 3')

    console.log(results.value);
    console.log(results.cst);
    console.log(results.errors);
</script>

References

Accompanying Documentation

Subject to the W3C Document Notice/License, the lexical and syntactical grammar as implemented by formcalc-js can be found in the same repository:

License

MIT License

About

JavaScript implementation of FormCalc language

Resources

License

Stars

Watchers

Forks