Plainfuse was a fork of Fuse.js by Kiro Risk due to concerns I had with difficulties auditing the minified Javascript (which at the time was the only output version available), combined with a desire for ES5 / IE11 support, which was not present at the time.
As such I converted Fuse.js to ‘plain’ ES5. The source code for plainfuse is still available with
git clone https://git.danielfdickinson.ca/webdev/plainfuse.git
however I consider the project archived and unmaintained.
Old README
DEPRECATED: Have figured out how to benefit from krisk/Fuse while taking care of the concerns that led to forking and a new project.
Overview
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
.
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
NB: This no longer works as repo has moved to https://git.danielfdickinson.ca/webdev/plainfuse.git and is no longer maintained.
hugo mod get git.danielfdickinson/webdev/plainfuse.git
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"
}]
}
}]