0.2.0 • Published 11 years ago
versus v0.2.0
versus.js

Compare two variables with the comparison operator specified as a string.
(This is really just a silly-simple switch-case abstracted into a reusable module.)
Usage
versus(1, '==' , 2); //=> false
versus(1, '===', 2); //=> false
versus(1, '!=' , 2); //=> true
versus(1, '!==', 2); //=> true
versus(1, '<' , 2); //=> true
versus(1, '>' , 2); //=> false
versus(1, '<=' , 2); //=> true
versus(1, '>=' , 2); //=> falseVersus uses deep-equal for the == and != comparisons. So we can do:
versus({ foo: 1 }, '==', { foo: 1 }); //=> true
versus({ foo: 1 }, '!=', { foo: 1 }); //=> falseRead the tests.
API
versus(a, op, b)
Returns a boolean, the result of comparing a and b using the comparison operator op specified as a string. Throws an error if op is not a valid comparison operator.
a,b— The two variables to be compared.op— One of==,===,!=,!==,<,>,<=, or>=.
Installation
Install via npm:
$ npm i --save versusChangelog
- 0.2.0
- Use deep-equal for
==and!=
- Use deep-equal for
- 0.1.0
- Initial release