valid-sift

1.1.0 • Public • Published

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

/valid-sift/

    Package Sidebar

    Install

    npm i valid-sift

    Weekly Downloads

    11

    Version

    1.1.0

    License

    MIT

    Last publish

    Collaborators

    • schtoeffel