MissPlete
This repository is forked from the original to quickly integrate with out styling.
MissPlete is a misspelling-tolerant autocomplete written in ECMAScript 2015, aka
ECMAScript 6 (ES6).
It supports synonyms and it can be customized with any algorithm to select and
sort the completions. By default it uses a
Jaro–Winkler distance
algorithm, which allows for
better sloppy interaction
than the usual completion based on exact substring matches.
Less than 220 lines of code. No dependencies.
Demo
http://xavi.github.io/miss-plete
Installation
npm install miss-plete-js --save
The library is published to the npm registry transpiled to ES5 and UMD, so it can be used in ES5 (examples/es5/
) and ES6 (examples/es6/
).
Usage
import MissPlete from './MissPlete.js';
import './miss-plete-example.css';
new MissPlete({
input: document.querySelector('input[name="city"]'),
options: [["Barcelona", "BCN"], ["San Francisco", "SF"]],
className: 'miss-plete',
scoreFn: (inputValue, optionSynonyms) => {
const score = Math.random();
return { score: score, displayValue: `${optionSynonyms[0]} (${score})` };
},
listItemFn: (scoredOption, itemIndex) => {
const li = scoredOption.score < 0.5 ? null : document.createElement("li");
li && li.appendChild(document.createTextNode(scoredOption.displayValue));
return li;
}
});
License
Copyright © 2015 Xavi Caballé
Licensed under the MIT License.