Skip to content

adoyle-h/logic-string

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

logic-string

Node Version Npm Package Version License NodeJS Package Dependencies Build Status Code Climate Test Coverage

Calculate logical expressions in string.

TOC

Installation

npm install -S logic-string

Usage

const L = require('logic-string');

L.eval('true && false');  // false
L.eval('true || false');  // true

L.eval('a && b', {        // false
    a: true,
    b: false,
});
L.eval('a || b', {        // true
    a: true,
    b: false,
});

L.eval('!false');         // true
L.eval('!true');          // false

L.eval('(a && b) || c', { // true
    a: true,
    b: true,
    c: false,
});

L.eval('( a && b )||c', { // true
    a: true,
    b: true,
    c: false,
});

API

L.eval(pattern, variables)

/**
 * It is based on `eval` function. You should be in charge of the security with injection risks.
 *
 * @param {String} pattern
 * @param {Object} [variables]
 * @return {Boolean}
 */
(pattern, variables) => Boolean

Versioning

The versioning follows the rules of SemVer 2.0.0.

BUT, anything may have BREAKING CHANGES at ANY TIME when major version is zero (0.y.z), which is for initial development and the public API should not be considered stable.

For more information on SemVer, please visit http://semver.org/.

Copyright and License

Copyright (c) 2017 ADoyle. The project is licensed under the Apache License Version 2.0.

See the LICENSE file for the specific language governing permissions and limitations under the License.

See the NOTICE file distributed with this work for additional information regarding copyright ownership.