Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

comparify

mimobaby31.6kMIT0.2.0

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

compare, search, criteria

readme

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

  • <input checked="" disabled="" type="checkbox"> Add support for arrays (any / all matching)
  • <input checked="" disabled="" type="checkbox"> Add support for regex comparison
  • <input disabled="" type="checkbox"> Add support for more types of comparison
    • <input disabled="" type="checkbox"> Greater than / less than
    • <input disabled="" type="checkbox"> Range