Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

trie-hard

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

trie-hard

Native JavaScript trie implementation

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

trie-hard

trie-hard is a JavaScript trie implementation.

Build Status

NPM

API

Trie

new Trie(matchCharacter = "\0")

The Trie constructor creates a brand new trie with no words in it. matchCharacter is the character used by the trie to mark word matches; this defaults to the null character, but can be any string that does not appear in any words in your trie's data set

Trie#add(word[, word[, word ...]])

Add one or more words to the trie. Returns the trie.

Trie#find(word)

Try to find the word in the trie. Returns a Match object, not a boolean.

Trie#isMatch(word)

Shortcut for Trie#find(word).isMatch()

Trie#isPrefix(word)

Shortcut for Trie#find(word).isPrefix()

Trie#isMatchOrPrefix(word)

Shortcut for Trie#find(word).isMatchOrPrefix()

Match

Match#isMatch()

Whether or not the search matched a complete word in the trie.

Match#isPrefix()

Whether or not the search matched a prefix in the trie (the word could also have been a full match).

Match#isMatchOrPrefix()

Whether or not the word was in the trie at all, either as an complete word or as a prefix.

Example

var trie = new Trie();
trie.put('cat');
trie.put('catsup');

trie.find('cat').isMatch() == true;
trie.find('cat').isPrefix() == false;
trie.find('cat').isMatchOrPrefix() == true;

trie.find('cats').isMatch() == false;
trie.find('cats').isPrefix() == true;
trie.find('cats').isMatchOrPrefix() == true;

trie.find('dog').isMatch() == false;
trie.find('dog').isPrefix() == false;
trie.find('dog').isMatchOrPrefix() == false;

var data = trie.toObject();
var serialized = JSON.stringify(data);

Keywords

FAQs

Package last updated on 03 Sep 2013

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc