UNPKG

autocomplete

Version:

An in-memory autocomplete package based on the trie data structure

26 lines (17 loc) 567 B
/** * Module dependencies. */ var Autocomplete = require('../'); var VEGETABLES = ['arugula', 'beet', 'broccoli', 'cauliflower', 'corn', 'cabbage', 'carrot']; // Create the autocomplete object var autocomplete = Autocomplete.connectAutocomplete(); // Initialize the autocopmlete object and define a // callback to populate it with data autocomplete.initialize(function(onReady) { onReady(VEGETABLES); }); // Later... When it's time to search: var matches = autocomplete.search('ca'); console.log(matches); // this will print: // ['cabbage', 'carrot']