1.0.6 • Published 3 years ago

safe-filter v1.0.6

Weekly downloads
15
License
MIT
Repository
github
Last release
3 years ago

Safe filter

A small, simple and safe TypeScript library for evaluating a subset of the well-known, MongoDB query language. Designed to be safe for use in a database or on the client side without the need for eval.

Usage

Filter an array of documents

import { matches } from 'safe-filter'

const docs = [{
  id: 1,
  name: 'hello'
}, {
  id: 2,
  name: 'world'
}, {
  id: 3,
  name: 'wowza'
}]

console.log(docs.filter(d => matches({ id: 1 }, d)))          // [{ id: 1, name: 'hello' }]
console.log(docs.filter(d => matches({ id: { $gte: 2 } }, d)) // [{ id: 2, name: 'world' }, { id: 3, name: 'wowza' }]

Supported operators

$and, $or, $not, $eq, $neq, $gt, $lt, $gte, $lte, $in, $nin, $exists, $regex, $elemMatch

Additional documentation about these operators can be found in the MongoDB documentation.

1.0.6

3 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago