1.0.9 • Published 5 years ago

clama v1.0.9

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

clama

Boolean expression evaluator for JS

Build Status npm.io npm.io npm.io

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

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago