Detalhes do pacote

loopback-filters

strongloop81.6kMIT1.1.1

Apply LoopBack filters to Arrays

LoopBack, filter, sort, sorting

readme (leia-me)

loopback-filters

⚠️ LoopBack 3 is in Maintenance LTS mode, only critical bugs and critical security fixes will be provided. (See Module Long Term Support Policy below.)

We urge all LoopBack 3 users to migrate their applications to LoopBack 4 as soon as possible. Refer to our Migration Guide for more information on how to upgrade.

Overview

This module implements LoopBack style filtering without any dependencies on LoopBack.

Install

$ npm install loopback-filters

Usage

Below is a basic example using the module

var applyFilter = require('loopback-filters');
var data = [{foo: 'bar'}, {bat: 'baz'}, {foo: 'bar'}];
var filter = {where: {foo: 'bar'}};

var filtered = applyFilter(data, filter);

console.log(filtered);

The output would be:

[{foo: 'bar'}, {foo: 'bar'}]

Features

Where

// return items where
applyFilter({
  where: {
    // the price > 10 && price < 100
    and: [
      {
        price: {
          gt: 10
        }
      },
      {
        price: {
          lt: 100
        }
      },
    ],

    // match Mens Shoes and Womens Shoes and any other type of Shoe
    category: {like: '.* Shoes'},

    // the status is either in-stock or available
    status: {inq: ['in-stock', 'available']}
  }
})

Only include objects that match the specified where clause. See full list of supported operators.

Geo Filter / Near

applyFilter(data, {
  where: {
    location: {near: '153.536,-28'}
  },
  limit: 10
})

Sort objects by distance to a specified GeoPoint.

Order

Sort objects by one or more properties.

Limit / Skip

Limit the results to a specified number. Skip a specified number of results.

Fields

Include or exclude a set of fields in the result.

Note: Inclusion from loopback is not supported!

Docs

See the LoopBack docs for the filter syntax.

Module Long Term Support Policy

This module adopts the Module Long Term Support (LTS) policy, with the following End Of Life (EOL) dates:

Version Status Published EOL
1.x Maintenance LTS Dec 2017 Dec 2020

Learn more about our LTS plan in docs.

changelog (log de mudanças)

2020-09-01, Version 1.1.1

  • fix: filter correctly array property (Matteo Padovano)

2020-03-06, Version 1.1.0

  • Update LTS status in README (Miroslav Bajtoš)

  • chore: update copyrights year (Diana Lau)

  • Implement insensitive filtering (Jee Mok)

  • chore: improve issue and PR templates (Nora)

  • chore: exclude "good first issues" from stalebot (Miroslav Bajtoš)

  • chore: update CODEOWNERS (Diana Lau)

  • chore: add stalebot (Diana Lau)

  • update eslint dependency (Nora)

  • chore: update copyrights years (Agnes Lin)

  • Implement regexp and nin filtering (Y.Shing)

2017-12-05, Version 1.0.0

  • Upgrade deps + fix linting issues (Miroslav Bajtoš)

  • Drop support for legacy Node.js versions (0.x) (Miroslav Bajtoš)

  • chore: update license (Diana Lau)

  • Add npm script to start tests in watch mode (Bram Borggreve)

  • Add tests for 'and' and 'or' filters (Bram Borggreve)

  • Create Issue and PR Templates (#19) (Sakib Hasan)

  • Add CODEOWNER file (Diana Lau)

  • Corrected a typo in the filter.order error message (Hannu Kärkkäinen)

  • Removed unnecessary logging (Hannu Kärkkäinen)

  • Update where filter in readme (#15) (Sakib Hasan)

  • Add travis CI (#16) (Sakib Hasan)

  • Replicate new issue_template from loopback (Siddhi Pai)

  • Replicate issue_template from loopback repo (Siddhi Pai)

  • Update paid support URL (Siddhi Pai)

  • Fix ESLint errors for CI (Siddhi Pai)

2016-10-13, Version 0.1.3

  • update eslint infrastructure (Amir Jafarian)

2016-05-06, Version 0.1.2

  • update copyright notices and license (Ryan Graham)

  • Fix linting errors (Amir Jafarian)

  • Auto-update by eslint --fix (Amir Jafarian)

  • Add eslint infrastructure (Amir Jafarian)

  • Refer to licenses with a link (Sam Roberts)

  • Use strongloop conventions for licensing (Sam Roberts)

  • Improve readme with details about features (Ritchie Martori)

2015-06-23, Version 0.1.1

  • Rename (Ritchie Martori)

2015-06-23, Version 0.1.0

  • First release!