Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including versus with all npm packages installed. Try it out:

var versus = require("versus")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

versus v0.2.0

Compare two variables with the comparison operator specified as a string.

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

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free