feelers
v3.1.0
Published
FEELers templating language interpreter.
Readme
feelers
A templating solution built on top of DMN FEEL. Like mustache / handlebars but with FEEL.
Usage
import { evaluate } from 'feelers';A simple string will always be returned as-is.
evaluate("My simple string");
// "My simple string"If your string is prefixed with an =, it will be evaluated as a single FEEL expression wrapped in a string conversion function.
const context = { secondNumber: 12 };
evaluate("= 2 + secondNumber", context);
// "14"Finally, if your string features feelers language features, the templating engine takes over.
const context = { user: "Dave" };
evaluate("I'm sorry {{user}}, I'm afraid I can't do that.", context);
// I'm sorry Dave, I'm afraid I can't do that.Language features
Inserts
The simplest feature of feelers is inserting FEEL evaluations within your text.
const context = { user: "Dave", age: 24, hobbies: [ "surfing", "coding" ] };
evaluate(`Hey there {{user}}, welcome. {{if age >= 18 then "Have a beer!" else "Here's some apple juice."}}`, context);
// Hey there Dave. Have a beer!Conditional sections
const context = { users: [ "Bob", "Dave" ] };
evaluate(`{{#if count(users) > 1}}There are multiple users{{/if}}`, context);
// There are multiple usersLoops
const context = { user: "Dave", hobbies: [ "surfing", "coding" ] };
evaluate(`{{user}}'s hobbies:\n{{#loop hobbies}}\n- {{this}}\n{{/loop}}`, context);
// Dave's hobbies:
// - surfing
// - codingBuild and run
Prepare the project by installing all dependencies:
npm installThen, depending on your use-case you may run any of the following commands:
# build the library and run all tests
npm run all
# run the development setup
npm run devRelated
- feelers - FEELers monorepo
- @bpmn-io/lezer-feelers - FEELers parser definition
- @bpmn-io/lang-feelers - FEELers language support for CodeMirror 6
- @bpmn-io/feelers-lint - FEELers linting support for CodeMirror 6
- @bpmn-io/feelers-editor - FEELers editor component
- lezer-feel - FEEL language definition for the Lezer parser system
License
MIT
