Git Product home page Git Product logo

luce-filter's Introduction

luce-filter

Customizable data filter for Lucene queries

Inspired by lucene-filter. Uses lucene parser.

Install

npm i luce-filter

Usage

const filter = require('luce-filter')

const data = [
  { /* 0 */ name: 'C-3PO', species: 'Droid', height: 1.7526, misc: {} },
  { /* 1 */ name: 'R2-D2', species: 'Droid', height: 1.1, misc: {} },
  { /* 2 */ name: 'Anakin Skywalker', species: 'Human', height: 1.9, family: ['Queen Amidala'], misc: { eye_color: 'yellow' } },
  { /* 3 */ name: 'Obi-Wan Kenobi', species: 'Human', height: 1.8, misc: {} },
  { /* 4 */ name: 'Han Solo', species: 'Human', height: 1.8, misc: {} },
  { /* 5 */ name: 'Princess Leia', species: 'Human', height: 1.5, misc: {} },
]

filter(data, 'name:Anakin')
// => [{ /* 2 */ name: 'Anakin Skywalker', ... }]

/* Ranges */
filter(data, 'height:[1.4 TO 1.6]')
// => [{ /* 5 */ name: 'Princess Leia', height: 1.5, ... }]

/* Arrays */
filter(data, 'family:amidala')
// => [{ /* 2 */ name: 'Anakin Skywalker', family: [ 'Queen Amidala' ], ... }]

/* Object properties with dot notation */
filter(data, 'misc.eye_color:yellow')
// => [{ /* 2 */ name: 'Anakin Skywalker', misc: { eye_color: 'yellow' }, ... }]

/* See test.js for more */

You may also wrap the default walker with your own:

filter(data, 'size:>1k', (row, { term, ...rest }) => {
  /* do something custom */
  term = term.replace('k', '000');
  /* then revert to default callback */
  return filter.default(row, { term, ...rest });
  /* or return a boolean that determines whether the current row should be included in final result */
})

luce-filter's People

Contributors

laggingreflex avatar

Watchers

 avatar

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.