https://github.com/mixmaxhq/mongo-comparison-ops-description
This library will create a Mongo comparison operator from a "description" (see readme for supported descriptions), and vice versa. Useful for building "Rules" UX on top of Mongo or Sift
https://github.com/mixmaxhq/mongo-comparison-ops-description
corgi-tag
Last synced: 28 days ago
JSON representation
This library will create a Mongo comparison operator from a "description" (see readme for supported descriptions), and vice versa. Useful for building "Rules" UX on top of Mongo or Sift
- Host: GitHub
- URL: https://github.com/mixmaxhq/mongo-comparison-ops-description
- Owner: mixmaxhq
- License: mit
- Created: 2017-05-12T00:17:50.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-11-22T16:05:47.000Z (over 1 year ago)
- Last Synced: 2025-04-15T17:02:51.734Z (about 1 month ago)
- Topics: corgi-tag
- Language: JavaScript
- Homepage: https://www.mixmax.com/careers
- Size: 110 KB
- Stars: 3
- Watchers: 20
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
## mongo-comparison-ops-description
This library will create a Mongo-style regex from a "description" (a tuple of an operator and a value). This is useful for building UIs on top of Mongo or [Sift](https://www.npmjs.com/package/sift) `$regex` operators.
Also see https://github.com/mixmaxhq/mongo-regex-description for the text counterpart to the library.
Example:
```js
var comparisonDescription = require('mongo-comparison-ops-description');var regex = regExpDescription.create({
operator: 'equal to',
value: 1
});
// { $not: { $regex: '^my value$', $options: 'i' } }var description = regExpDescription.parse({
$not: {
$regex: '^my value$',
$options: 'i'
}
});
// { operator: 'is not', value: 'my value' }```
### Supported Operators
* `equal to`
* `greater than`
* `greater than or equal to`
* `less than`
* `less than or equal to`
* `not equal to`## Changelog
* 1.2.2 Fixed bug where values were hardcoded :)
* 1.2.1 Fix bug where passing a falsy value didn't parse properly.
* 1.2.0 Can be used in the browser (use `npm build` and consume the file `dist/browser/index.js`)
* 1.1.1 Reordered `supportedOperators` to put more commonly used `contains` first.
* 1.1.0 Added `require('mongo-regex-description').supportedOperators` array as a convenience.
* 1.0.1 `parse()` returns null if it can't parse the query.
* 1.0.0 Initial release