versus

0.2.0 • Public • Published

versus.js npm Version Build Status Coverage Status

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); //=> false

Versus uses deep-equal for the == and != comparisons. So we can do:

versus({ foo: 1 }, '==', { foo: 1 }); //=> true
versus({ foo: 1 }, '!=', { foo: 1 }); //=> false

Read 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 versus

Changelog

  • 0.2.0
  • 0.1.0
    • Initial release

License

MIT license

Package Sidebar

Install

npm i versus

Weekly Downloads

1

Version

0.2.0

License

MIT

Last publish

Collaborators

  • yuanqing