How to use sift - 10 common examples

To help you get started, we’ve selected a few sift examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github QurateInc / vue-pouch-db / src / utils / index.js View on Github external
get: function getterComputedQueries() {
          // If dbsetup does not exist, throw Error!
          if (!this.$dbsetup) throw new Error('[VuePouchDB] dbsetup does not exist!');
          // Setting up the Queries
          // TODO: memoize/cache this function
          return (this.$bucket.state[this.$dbsetup.name] || []).filter(
            sift(expand(queries[name], this) || {})
          );
        },
        // When setting wait 500ms before executing the function
github redgeoff / mson-react / src / mson / component / validator.js View on Github external
_validateWithRule(rule) {
    // Clone where as we will be modifying the leaf nodes
    let where = _.cloneDeep(rule.where);

    // Fill the props
    this._fillWhere(where);

    // Validation failed?
    let sifted = sift(where, [this._props]);
    if (sifted.length > 0) {
      return this._fillErrorProps(rule.error);
    }
  }
github Automattic / mongoose / lib / helpers / populate / assignVals.js View on Github external
}
    return valueFilter(val, options, populateOptions);
  }

  for (let i = 0; i < docs.length; ++i) {
    const existingVal = utils.getValue(o.path, docs[i]);
    if (existingVal == null && !getVirtual(o.originalModel.schema, o.path)) {
      continue;
    }

    let valueToSet;
    if (count) {
      valueToSet = numDocs(rawIds[i]);
    } else if (Array.isArray(o.match)) {
      valueToSet = Array.isArray(rawIds[i]) ?
        sift(o.match[i], rawIds[i]) :
        sift(o.match[i], [rawIds[i]])[0];
    } else {
      valueToSet = rawIds[i];
    }

    // If we're populating a map, the existing value will be an object, so
    // we need to transform again
    const originalSchema = o.originalModel.schema;
    const isDoc = get(docs[i], '$__', null) != null;
    let isMap = isDoc ?
      existingVal instanceof Map :
      utils.isPOJO(existingVal);
    // If we pass the first check, also make sure the local field's schematype
    // is map (re: gh-6460)
    isMap = isMap && get(originalSchema._getSchema(o.path), '$isSchemaMap');
    if (!o.isVirtual && isMap) {
github Automattic / mongoose / lib / helpers / populate / assignVals.js View on Github external
return valueFilter(val, options, populateOptions);
  }

  for (let i = 0; i < docs.length; ++i) {
    const existingVal = utils.getValue(o.path, docs[i]);
    if (existingVal == null && !getVirtual(o.originalModel.schema, o.path)) {
      continue;
    }

    let valueToSet;
    if (count) {
      valueToSet = numDocs(rawIds[i]);
    } else if (Array.isArray(o.match)) {
      valueToSet = Array.isArray(rawIds[i]) ?
        sift(o.match[i], rawIds[i]) :
        sift(o.match[i], [rawIds[i]])[0];
    } else {
      valueToSet = rawIds[i];
    }

    // If we're populating a map, the existing value will be an object, so
    // we need to transform again
    const originalSchema = o.originalModel.schema;
    const isDoc = get(docs[i], '$__', null) != null;
    let isMap = isDoc ?
      existingVal instanceof Map :
      utils.isPOJO(existingVal);
    // If we pass the first check, also make sure the local field's schematype
    // is map (re: gh-6460)
    isMap = isMap && get(originalSchema._getSchema(o.path), '$isSchemaMap');
    if (!o.isVirtual && isMap) {
      const _keys = existingVal instanceof Map ?
github LearningLocker / learninglocker / lib / helpers / mongoFilteringInMemory.js View on Github external
/* eslint-disable no-use-before-define */
import sift from 'sift';

sift.use({
  $comment: () => true
});

const match = filter => actual => sift(filter, [actual]).length > 0;

export default match;
github joakimbeng / relae / src / store.js View on Github external
import update from 'react/lib/update';
import sift from 'sift';
import eventEmitter from 'event-emitter';

let idProperty = 'id';

sift.useOperator('id', (a, b) => a === b[idProperty]);
sift.useOperator('limit', () => true);
sift.useOperator('skip', () => true);

const ee = eventEmitter();

let storage = {};

function setState(state) {
  storage = update(storage, {$merge: state});
  Object.keys(state).forEach(key => ee.emit('change', key));
}

function getRequestData(request, params) {
  const collection = storage[request.collection] || [];
  let data = sift(params, collection);
  if (request.params.$id) {
github joakimbeng / relae / src / store.js View on Github external
import update from 'react/lib/update';
import sift from 'sift';
import eventEmitter from 'event-emitter';

let idProperty = 'id';

sift.useOperator('id', (a, b) => a === b[idProperty]);
sift.useOperator('limit', () => true);
sift.useOperator('skip', () => true);

const ee = eventEmitter();

let storage = {};

function setState(state) {
  storage = update(storage, {$merge: state});
  Object.keys(state).forEach(key => ee.emit('change', key));
}

function getRequestData(request, params) {
  const collection = storage[request.collection] || [];
  let data = sift(params, collection);
  if (request.params.$id) {
    return data && data[0];
github joakimbeng / relae / src / store.js View on Github external
import update from 'react/lib/update';
import sift from 'sift';
import eventEmitter from 'event-emitter';

let idProperty = 'id';

sift.useOperator('id', (a, b) => a === b[idProperty]);
sift.useOperator('limit', () => true);
sift.useOperator('skip', () => true);

const ee = eventEmitter();

let storage = {};

function setState(state) {
  storage = update(storage, {$merge: state});
  Object.keys(state).forEach(key => ee.emit('change', key));
}

function getRequestData(request, params) {
  const collection = storage[request.collection] || [];
  let data = sift(params, collection);
  if (request.params.$id) {
    return data && data[0];
  }
github gadicc / gongo / gongo-client / src / gongo.js View on Github external
constructor(collection, query, options) {
    this.collection = collection;

    if (!query)
      query = {};
    if (!options)
      options = {};

    if (!options.includePendingDeletes)
      query.__pendingDelete = { $exists: false };

    this._query = query;
    this.query = sift(query);
  }

sift

MongoDB query filtering in JavaScript

MIT
Latest version published 7 months ago

Package Health Score

79 / 100
Full package analysis