Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mikeibberson/comparisons
String expressions for comparing object properties
https://github.com/mikeibberson/comparisons
node-js string-matching
Last synced: 19 days ago
JSON representation
String expressions for comparing object properties
- Host: GitHub
- URL: https://github.com/mikeibberson/comparisons
- Owner: MikeIbberson
- License: mit
- Created: 2019-11-30T17:56:49.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-01-22T20:37:27.000Z (10 months ago)
- Last Synced: 2024-10-12T12:16:01.589Z (about 1 month ago)
- Topics: node-js, string-matching
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/comparisons
- Size: 485 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
🧮 Comparisons
Currently, expressions support
=
,>=
,<=
,>
,<
and!=
operators. Optionally, you can include a second constructor argument for changing the locale (the default is "en"). Any expressions that do not match a recognized operation get stripped out and are assumed to pass.For simply matching if a property exists, use the
=*
expression. Likewise, use the!
flag on the key name to check for missing/empty values.Don't worry about type casting—we'll handle that for you.
Example usage
```Bash
# Or use npm install
yarn add comparisons
``````Javascript
const Comparison = require('comparisons');const tests = ['foo=bar', 'num>=2', '!quuz'];
const stub = { foo: 'bar', num: 3 };
const runner = new Comparison(tests);
runner.eval(stub); // returns true or false
runner.query(); // returns a Mongo friendly query
```