1.1.0 • Published 9 years ago

valid-sift v1.1.0

Weekly downloads
44
License
MIT
Repository
github
Last release
9 years ago

valid-sift Build Status Coverage Status

Check if something is a valid sift filter.

NPM

Install

$ npm install --save valid-sift

Usage

Importing

import isValid from 'valid-sift';

or

var isValid = require('valid-sift');

Checking a sift filter

If the filter is valid the function returns true.

const siftFilter = {
  name: {
    $or: [{$eq: 'Max'}, {$eq: 'Moritz', age: 13}]
  }
};

const allowedAttributes = ['name', 'age'];

valid(siftFilter, ...allowedAttributes); // => true

If you pass a filter with a not allowed attribute it returns false.

const siftFilter = {
  id: {
    $or: [{$eq: 12}, {$eq: 13}]
  }
};
valid(siftFilter, ...allowedAttributes); // => false

If you pass a filter with an invalid operator it returns false.

const siftFilter = {
  id: {
    $or: [{$eq: 12}, {$nope: 13}]
  }
};
valid(siftFilter); // => false

API

isValid(filter, [attribute, ...]) => boolean

  • filter - the filter to check.
  • attribute - Allowed attributes in the filter.

or pass the attributes as an array.

isValid(filter, attributes) => boolean

  • attributes - Allowed attributes in the filter as an array.

License

MIT © Stoeffel

1.1.0

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago