New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

prefix-tree

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prefix-tree

Simle prefix tree aka trie

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

prefix-tree

Simple prefix-tree

NPM Status Travis Status Coverage Status Dependency Status

Class to work with prefix tree. API is similiar to native Map.

Installation

npm install --save prefix-tree

Usage

var Tree = require('prefix-tree');

var tree = new Tree([['hi', 42,] ['hello', 'world'], ['xo', 'xo']]);

tree.get('h');
// → [ 42, 'world']

tree.set('xxx', { '42': 42 });
tree.get('x');
// → [ 'xo', { '42': 42 }]

API

prefixTree(items)

ParameterTypeDescription
itemsarrayoptional Array of key-value pairs

Example:

var tree = new PrefixTree([ ['key', 'value'], ['key2', 'value2'] ]);
var tree2 = new PrefixTree();

set(key, value)

ParameterTypeDescription
keystringkey to search prefix in
valueanyAnything you want to store

Add value to prefix tree.

Example:

var tree = new PrefixTree();
tree.set('hello', 'world');

get(prefix)

ParameterTypeDescription
prefixstringprefix to search values

Get values for a prefix.

Example:

var tree = new PrefixTree();

tree
    .set('hell', 666);
    .set('hello', 'world');

tree.get('he');
// → [666, 'world']

toString()

For debug purpose you could use toString() method.

NB For perfomance module load inspection only with NODE_ENV === 'development'

NODE_ENV='development' node -e "console.log('' + new (require('prefix-tree'))([['hello', 'hello'], ['hi', 'hi'], ['hell', 'hell']]))"

[root]
└── h
    ├── e
    │   └── l
    │       └── l : hell
    │           └── o : hello
    └── i : hi

License

Code released under the MIT.

Keywords

prefix

FAQs

Package last updated on 09 Jul 2017

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