GithubHelp home page GithubHelp logo

loopback-filters's Introduction

loopback-filters

โš ๏ธ LoopBack 3 has reached end of life. We are no longer accepting pull requests or providing support for community users. The only exception is fixes for critical bugs and security vulnerabilities provided as part of support for IBM API Connect customers. (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 End-of-Life Dec 2017 Dec 2020

Learn more about our LTS plan in docs.

loopback-filters's People

Contributors

achrinza avatar agnes512 avatar amir-61 avatar b-admike avatar bajtos avatar beeman avatar dhmlau avatar jannyhou avatar mrbatista avatar nabdelgadir avatar ritch avatar rmg avatar sam-github avatar siddhipai avatar superkhau avatar yshing avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

loopback-filters's Issues

Query nested properties

I'm not sure it's a bug or a new feature, but the behavior is not same as loopback find/findOne.

=== Sample Code ===

var applyFilter = require('loopback-filters');
var data = [
    {foo: [{name: 'bar'}, {name: 'bar2'}]},
    {bat: [{name: 'baz'}]},
    {foo: [{name: 'bar'}]}
];
var filter = {where: {"foo.name": 'bar'}};
var filtered = applyFilter(data, filter);
console.log(filtered);

=== Expected result ===

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

=== Actual result ===

[]

but I use loopback model.find/findOne, I can get expected result.

Please help. Thanks.

Not working correctly

var applyFilter = require('loopback-filters');
datas = [];
for (var index = 0; index <= 10; index++) {
    datas.push({ id: index, title: 'hi ' + index});
}
var filter = {
    where: { id: { gt: 1, lt: 5 } },
    limit: 10,
    order: ['title DESC'],
    
};
var filtered = applyFilter(datas, filter);
console.log(filtered);

Results are WRONG!

The base case for pagination doesn't work properly

Description/Steps to reproduce

I've just created an array with 3 elements.

let input = [{index:0}, {index:1}, {index:2}]; 

Then I called the applyFilter function with the following parameters:

applyFilters(input, {skip:0, limit:1}); //It works properly. returns the element at index 0.
applyFilters(input, {skip:1, limit:1}); //Wrong response. It returns the element at index 1 and 2.
applyFilters(input, {skip:2, limit:1}); //It works properly. returns the element at index 2.

`Regexp` and `ilike` filter operators

Bug or feature request

  • Bug
  • Feature request

Description of feature (or steps to reproduce if bug)

Loopback currently supports regexp and ilike operators for where filters, but I don't see support for that in this repo. Are there plans to add these two filter operators to this repository?

Thanks.

Expected result

const filterNodes = require('loopback-filters');
const data = [ { name: 'asd' }, { name: 'fAgh' }, {name: 'qwe'}, { name: 'jkAl' }];

filterNodes(data, { where: { name: { regexp: '/\w*[aA]\w*/i' } } }) // asd, fAgh, jkAl
filterNodes(data, { where: { name: { ilike: '%a%' } } }) // same

Add browser / bower support

This module is probably most useful in the context of a browser where:

  • you have a loopback backend
  • you want to further filter data from the backend using the same syntax as the filter you are sending to the server.

We should support:

  • browserify require (almost certain this will just work)
  • standalone umd style with global fallback (we can use browserify stand-alone for this)
  • install via bower

/cc @bajtos @jtary @anthonyettinger @seanbrookes

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.