Security News
Introducing the Socket Python SDK
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
An in-memory node.js autocomplete package based on the trie data structure, based off the autocomplete module
Modernized Trie-search based on Node Autocomplete is an autocomplete library for node.js.
TODO: Cleanup test suite, use chai. Add all them missing semi-colons...
npm install triesearch
var data = ['fruit', 'app', 'apple', 'banana']
// instatiate a new autocomplete object
var Autocomplete = require('autocomplete')
var auto = new Autocomplete()
auto.initialize(data)
// results will be an array with 0 or more elements
var results = auto.search('ap')
// here results will be an array of key-value pairs
console.dir(results)
The output of the search is an array of objects with key and value properties. In the example above, results
looks like
[
{
key: 'app',
value: 'app'
},
{
key: 'apple',
value: 'apple',
}
]
If you are just searching for strings you can get an array of matching strings by mapping the results and returning just the key
var data = ['fruit', 'app', 'apple', 'banana']
// instatiate a new autocomplete object
var Autocomplete = require('autocomplete')
var auto = new Autocomplete()
auto.initialize(data)
// results will be an array with 0 or more elements
var results = auto.search('ap')
// here results will be an array of key-value pairs
console.dir(results)
var stringMatches = results.map(function (result) {
return result.key
})
// stringMatches is ['app', 'apple']
console.dir(stringMatches)
You can add to the list of candidate elements after the autocomplete object has been initialized
var Autocomplete = require('autocomplete')
var auto = new Autocomplete()
var data = []
auto.initialize(data)
auto.addElement('cheeseburger')
You can remove from the list of candidate elements after the autocomplete object has been initialized
var Autocomplete = require('autocomplete')
var auto = new Autocomplete()
var data = ['app', 'apple', 'apples']
auto.initialize(data)
auto.removeElement('apple')
You can also add key value pairs as an array of 2 elements
var Autocomplete = require('autocomplete')
var auto = new Autocomplete()
var data = ['app', 'apple', ['apples', 'yummy'], 'banana' ]
auto.initialize(data)
var results = app.search('ap')
// in the results, there will be an element with the key *apples* and the value *yummy*
console.dir(results)
In the example above, results
looks like
[
{ key: 'app', value: 'app' },
{ key: 'apple', value: 'apple' },
{ key: 'apples', value: 'yummy' }
]
Install development dependencies:
npm install
Then:
npm test
Actively tested with node:
Original source code based on https://github.com/marccampbell/node-autocomplete
(The MIT License)
Copyright (c) 2011 Marc Campbell <marc.e.campbell@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
An in-memory node.js autocomplete package based on the trie data structure, based off the autocomplete module
We found that triesearch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The initial version of the Socket Python SDK is now on PyPI, enabling developers to more easily interact with the Socket REST API in Python projects.
Security News
Floating dependency ranges in npm can introduce instability and security risks into your project by allowing unverified or incompatible versions to be installed automatically, leading to unpredictable behavior and potential conflicts.
Security News
A new Rust RFC proposes "Trusted Publishing" for Crates.io, introducing short-lived access tokens via OIDC to improve security and reduce risks associated with long-lived API tokens.