Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Simple criteria checking, so you can test a subset of an object's properties.
JavaScript
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
README.md
package.json

README.md

Comparify

Simple criteria checking, so you can test a subset of an object's properties.

var comparify = require('comparify');

var data = {
  timestamp: 1395877795067,
  deviceID: '765CBA',
  recipient: {
    name: 'Thomas'
  },
  uses: ['making pancakes', 'running', 'hugs']
};

comparify(data, {deviceID: '765CBA'}) === true;
comparify(data, {deviceID: 'ABC123'}) === false;

// Comparify also supports nested requirements
comparify(data, {'recipient.name': 'Thomas'}) === true;
comparify(data, {recipient: {name: 'Thomas'}}) === true;

// And you can look in arrays
comparify(data, {uses: 'running'}) === true;
comparify(data, {uses: 'skiing'}) === false;

// You can require that multiple values are present in an array
comparify(data, {uses: ['running', 'hugs']}) === true;
comparify(data, {uses: ['running', 'skiing']}) === false;

// And you can use a Regex for values
comparify(data, {'recipient.name': /omas/}) === true;


To Do

  • Add support for arrays (any / all matching)
  • Add support for regex comparison
  • Add support for more types of comparison
    • Greater than / less than
    • Range
Something went wrong with that request. Please try again.