fuse-operators

0.1.2 • Public • Published

Fuse-Operators

This library is based on fusejs.

It was inspired on adding logic operators to be able to apply different conditions on a string search just like would normally do on the SQL Language. No back-end database is needed, just javascript objects.

Installation

$ npm i fuse-operators

How to use

// Data example
const mockData = [
  {
    "title": "Old Man's War",
    "author": {
      "firstName": "John",
      "lastName": "Scalzi"
    }
  },
  {
    "title": "The Lock Artist",
    "author": {
      "firstName": "John",
      "lastName": "Hamilton"
    }
  }
];

Available arguments

import fuseWithOperators from 'fuse-operators';
const options = {}; // Here you can add all options from http://fusejs.io/ package
 
const result = fuseWithOperators(query, mockData, options);

AND Operator

import fuseWithOperators from 'fuse-operators';
const query = 'old man && scalzi';
const result = fuseWithOperators(query, mockData);
// → [{"title": "Old Man's War", "author": {"firstName": "John", "lastName": "Scalzi"}}]

OR Operator

import fuseWithOperators from 'fuse-operators';
const query = 'old man || artist';
const result = fuseWithOperators(query, mockData);
// → [{"title": "Old Man's War", "author": {"firstName": "John", "lastName": "Scalzi"}}, {"title": "The Lock Artist", "author": {"firstName": "John", "lastName": "Hamilton"}}]

SUBSET Operator

import fuseWithOperators from 'fuse-operators';
const query = 'old man || the lock artist > scalzi';
const result = fuseWithOperators(query, mockData);
// → [{"title": "Old Man's War", "author": {"firstName": "John", "lastName": "Scalzi"}}]

Available operators

Operator Description
|| OR operator
&& AND operator
> SUBSET operator. Applies a second search on the left side result

Tests

$ npm run test:watch

Contributors

All PRs are welcome :) just make sure you pass all tests.

License

MIT License

Package Sidebar

Install

npm i fuse-operators

Weekly Downloads

0

Version

0.1.2

License

MIT

Unpacked Size

14.9 kB

Total Files

11

Last publish

Collaborators

  • ldmarz