JSPM

comparify

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3083
  • Score
    100M100P100Q136340F
  • License MIT

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

Package Exports

  • comparify

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (comparify) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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

  • Add support for arrays (any / all matching)
  • Add support for regex comparison
  • Add support for more types of comparison
    • Greater than / less than
    • Range