DMN FEEL Parser and Interpreter
Feelin is a robust JavaScript library designed to parse and interpret FEEL (Friendly Enough Expression Language) expressions, a standard defined by DMN (Decision Model and Notation). It provides functions like `evaluate` and `unaryTest` for executing FEEL expressions against a given context. The current stable version is 6.2.0, with minor releases and dependency updates occurring regularly, indicating active maintenance. Key differentiators include its comprehensive recognition of the full FEEL grammar, context-sensitive evaluation (handling names with spaces), built-in FEEL functions, and a focus on error recovery with detailed warnings for issues such as `null` conversions. While not yet fully DMN TCK compliant, it aims for high fidelity to the standard, making it suitable for integrating DMN decision logic into JavaScript applications.
Common errors
-
TypeError: require is not a function
cause Attempting to import `feelin` using CommonJS `require()` syntax in an ES module context or without proper CommonJS fallback/transpilation.fixUse ES module import syntax: `import { evaluate } from 'feelin';` in your JavaScript/TypeScript files. Ensure your project is configured for ES modules (e.g., `"type": "module"` in `package.json`). -
Variable 'x' not found
cause An expression references a variable (e.g., 'x') that is not present in the provided context object.fixEnsure all variables referenced within your FEEL expression are provided as properties of the context object passed to `evaluate` or `unaryTest`. For example, `evaluate('x', { x: 10 })`.
Warnings
- breaking Starting with v6.0.0, the package explicitly reports `null` conversion errors in the `warnings` array. Previously, such errors might have been silently handled or returned `null` without explicit warning details. Developers should now inspect the `warnings` property of the result object to understand why a `null` value was produced.
- gotcha Feelin requires Node.js version 20.12.0 or higher. Using it with older Node.js versions may lead to compatibility issues, particularly with ESM imports or underlying dependencies.
- gotcha The package is primarily designed as an ES module (ESM). Attempting to use `require()` for imports in a CommonJS environment without proper transpilation or configuration will result in an error.
- gotcha While `feelin` recognizes the full FEEL grammar and includes many built-in functions, it is not yet fully compliant with the DMN TCK (Decision Model and Notation Test Compatibility Kit). This means certain complex or edge-case FEEL expressions might behave differently compared to a fully TCK-compliant engine.
Install
-
npm install feelin -
yarn add feelin -
pnpm add feelin
Imports
- evaluate
const { evaluate } = require('feelin');import { evaluate } from 'feelin'; - unaryTest
import unaryTest from 'feelin';
import { unaryTest } from 'feelin'; - *
import * as feelin from 'feelin';
Quickstart
import { evaluate, unaryTest } from 'feelin';
// Evaluate a simple expression with a context
const result1 = evaluate("Mike's daughter.name", {
'Mike\'s daughter.name': 'Lisa'
});
console.log('Expression evaluation:', result1.value); // Lisa
// Perform a unary test
const result2 = unaryTest('1', { '?': 1 });
console.log('Unary test 1:', result2.value); // true
const result3 = unaryTest('[1..end]', { '?': 1, end: 10 });
console.log('Unary test 2:', result3.value); // true
// Iterate and transform a list
const result4 = evaluate('for a in [1, 2, 3] return a * 2');
console.log('Loop evaluation:', result4.value); // [2, 4, 6]
// Check warnings for undefined variables or null conversions
const { value, warnings } = evaluate('x');
console.log('Undefined variable result:', value); // null
console.log('Warnings for undefined variable:', warnings);
/*
Output: [
{
message: "Variable 'x' not found",
type: 'NO_VARIABLE_FOUND',
position: { from: 0, to: 1 }
}
]
*/