Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ngryman/compare-properties
Get functions to compare two object properties given an operator.
https://github.com/ngryman/compare-properties
Last synced: 20 days ago
JSON representation
Get functions to compare two object properties given an operator.
- Host: GitHub
- URL: https://github.com/ngryman/compare-properties
- Owner: ngryman
- License: mit
- Created: 2015-06-01T17:24:52.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-11T18:07:08.000Z (over 7 years ago)
- Last Synced: 2024-09-20T05:19:16.035Z (about 1 month ago)
- Language: JavaScript
- Size: 10.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# compare-properties [![npm][npm-image]][npm-url] [![travis][travis-image]][travis-url]
[npm-image]: https://img.shields.io/npm/v/compare-properties.svg?style=flat
[npm-url]: https://npmjs.org/package/compare-properties
[travis-image]: https://img.shields.io/travis/ngryman/compare-properties.svg?style=flat
[travis-url]: https://travis-ci.org/ngryman/compare-properties> Get functions to compare two values given an operator.
## Install
```
$ npm install —save compare-properties
```## Usage
```js
var compareFactory = require('compare-properties');var equal = compareFactory('=', 'foo');
equal({ foo: 42 }, { foo: 42 }); //=> true
equal({ foo: 42 }, { foo: 10 }); //=> false
equal({ foo: 42 }, { bar: 42 }); //=> falsevar equal = compareFactory('=', 'foo', 'bar');
equal({ foo: 42 }, { foo: 42 }); //=> false
equal({ foo: 42 }, { bar: 42 }); //=> truevar equal = compareFactory('<', 'foo');
equal({ foo: 'foo' }, { foo: 'foo' }); //=> true
equal({ foo: 'foo' }, { foo: 'fon' }); //=> true
equal({ foo: 1337 }, { bar: 42 }); //=> false
```## Operators
| = | < | > | <= | >= | != | %= |
| --------- | ------- | ------- | -------- | -------- | -------- | ------------- |
| `a === b` | `a < b` | `a > b` | `a <= b` | `a >= b` | `a != b` | `a % b === 0` |## License
MIT © [Nicolas Gryman](http://ngryman.sh)