Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started
Generated on Apr 16, 2024 via pnpm

sift 16.0.1

MongoDB query filtering in JavaScript
Package summary
Share
0
issues
1
license
1
MIT
Package created
4 Jan 2012
Version published
31 Oct 2022
Maintainers
2
Total deps
1
Direct deps
0
License
MIT

Issues

0
This package has no issues

Licenses

MIT License

Permissive
OSI Approved
This is a human-readable summary of (and not a substitute for) the license. Disclaimer.
Can
commercial-use
modify
distribute
sublicense
private-use
Cannot
hold-liable
Must
include-copyright
include-license
1 Packages, Including:
sift@16.0.1
Disclaimer

This deed highlights only some of the key features and terms of the actual license. It is not a license and has no legal value. You should carefully review all of the terms and conditions of the actual license before using the licensed material.

Sandworm is not a law firm and does not provide legal services. Distributing, displaying, or linking to this deed or the license that it summarizes does not create a lawyer-client or any other relationship.

Direct Dependencies

0
All Dependencies CSV
β“˜ This is a list of sift 's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.
NameVersionSizeLicenseTypeVulnerabilities

Visualizations

Frequently Asked Questions

What does sift do?

Sift is a small yet powerful JavaScript library that brings the power of MongoDB querying into JavaScript. Sifting through data to find specific elements can be complex, but Sift makes it easy by providing a range of query filters and operators that you can use, ranging from simple ones like $in and $nin, through to advanced ones such as $elemMatch and $regex. By using these, you can efficiently filter arrays, check regular expressions, test individual values against custom filters and much more.

How do you use sift?

Utilizing Sift is straightforward. First, install it via npm using npm install sift or yarn using yarn add sift. Then, import it into your JavaScript file with import sift from 'sift';. The primary function of Sift is to create filters based on MongoDB query operations. Below are a couple of examples demonstrating its usage:

const result = ["hello", "sifted", "array!"].filter(sift({ $in: ["hello", "world"] })); 
// result is ['hello']

const regexResult = ["craig", "john", "jake"].filter(sift(/^j/)); 
// regexResult is ['john','jake']

const customFilter = sift({
  name: function(value) {
    return value.length == 5;
  }
});
const functionResult = [
  {
    name: "craig"
  },
  {
    name: "john"
  },
  {
    name: "jake"
  }
].filter(customFilter); 
// functionResult is [{ name: 'craig' }]

// Test single values against your custom filter
console.log(customFilter({ name: "sarah" })); // Outputs: true
console.log(customFilter({ name: "tim" }));   // Outputs: false

Where are the sift docs?

For the details and more comprehensive examples of using operators and certain functionalities of Sift, the complete documentation can be accessed at the MongoDB official documentation site: http://docs.mongodb.org/manual/reference/operator/query/. This documentation provides extensive details about the different query operators and how you can utilize them in your JavaScript applications.