Socket
Socket
Sign inDemoInstall

substring-trie

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    substring-trie

Minimalistic trie implementation for prefix searches


Version published
Weekly downloads
1.1K
decreased by-4.26%
Maintainers
1
Install size
42.5 kB
Created
Weekly downloads
 

Readme

Source

substring-trie

Minimalistic trie implementation for prefix searches. It finds the longest string from the dictionary that matches the beginning of the input string, or undefined if no matching string can be found.

npm install substring-trie
var Trie = require('substring-trie');

var trie = new Trie(['banana', 'grape', 'grapefruit'])

trie.search('banana'); // 'banana'
trie.search('banan'); // undefined
trie.search('bananas'); // 'banana'
trie.search('grape'); // 'grape'
trie.search('grapefruit'); // 'grapefruit'
trie.search('grapefruit and other fruit'); // 'grapefruit'

Note this is not designed for autosuggestions. Instead this is designed as a replacement for regex-based prefix searching:

var regex = /^(banana|grapefruit|grape)/

'banana'.match(regex); // ['banana']
'banan'.match(regex); // null
'bananas'.match(regex); // ['banana']
'grape'.match(regex); // ['grapefruit']
'grapefruit'.match(regex); // ['grapefruit']
'grapefruit and other fruit'.match(regex); // ['grapefruit']

Keywords

FAQs

Last updated on 03 Oct 2017

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc