1.0.5 • Published 4 years ago

plainfuse v1.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 years ago

Introduction

plainfuse is a javascript standalone fuzzy-search, with zero dependencies. It is forked from Fuse.js to create a plain javascript build with no babel, webpack or typescript (build-time) dependencies, as well as convert to ES5 as the JS version.

The only build dependency is 'concat' and that is for a lack of other good (and simple) cross-platform options for combining files.

For testing there are more dependencies because we use Jest tests (from upstream) to verify operation of dist/plainfuse.js.

Build Status

See plainfuse STATUS for the current build status.

Apache-2.0 Modified Notice

This is the notice required by the Apache 2.0 license that this README.md is modified by Daniel F. Dickinson compared to the upstream version. In fact most files have been modified, removed, or are Daniel F. Dickinson's new work. The 'LICENSE' file has been replaced with a copy of https://www.apache.org/licenses/LICENSE-2.0 which is the original license text, which one is not supposed to modify (one puts the boilerplate in one's own files, not modifying the LICENSE file).

Installation

As a Hugo Module

hugo mod get github.com/cshoredaniel/plainfuse

NPM

plainfuse can be installed using NPM

$ npm install plainfuse

Examples

Searching by ID

var books = [{
  'ISBN': 'A',
  'title': "Old Man's War",
  'author': 'John Scalzi'
}, {
  'ISBN': 'B',
  'title': 'The Lock Artist',
  'author': 'Steve Hamilton'
}]

var options = {
  keys: ['title', 'author'],
  id: 'ISBN'
}
var plainfuse = new PlainFuse(books, options)

plainfuse.search('old')

Weighted search

var books = [{
  title: "Old Man's War fiction",
  author: 'John X',
  tags: ['war']
}, {
  title: 'Right Ho Jeeves',
  author: 'P.D. Mans',
  tags: ['fiction', 'war']
}]

var options = {
  keys: [{
    name: 'title',
    weight: 0.3
  }, {
    name: 'author',
    weight: 0.7
  }]
};
var plainfuse = new PlainFuse(books, options)

plainfuse.search('Man')
[{
  "title": "Right Ho Jeeves",
  "author": "P.D. Mans",
  "tags": ["fiction", "war"]
}, {
  "title": "Old Man's War fiction",
  "author": "John X",
  "tags": ["war"]
}]

Searching in arrays of strings

var books = [{
  'title': "Old Man's War",
  'author': 'John Scalzi',
  'tags': ['fiction']
}, {
  'title': 'The Lock Artist',
  'author': 'Steve',
  'tags': ['thriller']
}]

var options = {
  keys: ['author', 'tags']
};
var plainfuse = new PlainFuse(books, options)

fuse.search('tion')
[{
  "title": "Old Man's War",
  "author": "John Scalzi",
  "tags": ["fiction"]
}]

Searching in arrays of objects

var books = [{
  'title': "Old Man's War",
  'author': {
    'name': 'John Scalzi',
    'tags': [{
      value: 'American'
    }]
  }
}, {
  'title': 'The Lock Artist',
  'author': {
    'name': 'Steve Hamilton',
    'tags': [{
      value: 'English'
    }]
  }
}]

var options = {
  keys: ['author.tags.value'],
};
var plainfuse = new PlainFuse(books, options)

fuse.search('engsh')
[{
  "title": "The Lock Artist",
  "author": {
    "tags": [{
      "value": "English"
    }]
  }
}]
1.0.5

4 years ago

1.0.4

4 years ago

1.0.2

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago