1.0.9 • Published 5 years ago
clama v1.0.9
clama
Boolean expression evaluator for JS
Installation
NPM
npm i clama
YARN
yarn add clama
Usage
const clama = require('clama'); // Requiring the module.
const boolEvaluator = clama(); // Creating a clama object.
boolEvaluator.eval('true && true'); // { output: true }
API
new clama( clamaConfig? )
Clama object constructor, which can be invoked without the need of using the new
operator, it takes a configuration object as a parameter.
Configuration object schema
// Avoid using operators with overlapping characters.
{
and: '&&', // Defaults to '&&', and will be trimmed.
or: '||', // Defaults to '||', and will be trimmed.
not: '!', // Defaults to '!', and will be trimmed
true: 'true' // Defaults to 'true' if not provided, and if it is provided the string is trimmed.
false: 'false' // Defaults to 'false' if not provided, and if it is provided the string is trimmed.
groupingEntry: '(', // Defaults to '(' and can only be one character long.
groupingClosing: ')' // Defaults to ')' and can only be one character long.
}
- Note : all clamaConfig properties are optional.
eval( input: string ): { output: boolean, error?: string }
- input : The string to be evaluated.
Returns an object which contains the result of the evaluation or an error in case there is any (Note the error property will not be put on the object unless an error actually happened during evaluation).
License
MIT