Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

char-tree

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

char-tree

A trie structure

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
1
-80%
Maintainers
1
Weekly downloads
 
Created
Source

char-tree

Install

npm install char-tree

Usage

import { CharTree } from 'char-tree';
let data = [
    'The Thing',
    'The Terminator',
    'Super man',
    'Legend of Sleepy Hollow',
    'The Shining',
    'Fifty Shades of Grey'
];

const ct = new CharTree();
//Add the array with .push()
ct.push(...data);

console.log(ct.findAll('t'));
//[ 'The Thing', 'The Terminator', 'The Shining' ]
console.log(ct.match('t'));
/*
{ tree:
   { branches: { h: [Object] },
     items: [ 'The Thing', 'The Terminator', 'The Shining' ],
     value: 'T' },
  string: 'T',
  value: 't' }
*/
//The second argument is a separator for words/phrases
console.log(ct.nextPhrase('t', /[ ]+/));
//The

Give CharTree to a prototype

import { charTreeMixin } from 'char-tree';

class MyClass {
    constructor(){
        //Create the charTree property
        this.initCharTree();
    }
}

//Give MyClass all the methods of CharTree
charTreeMixin(MyClass.prototype);

About

A CharTree instance is a trie structure for finding one, or any phrases in an array that match a string prefix of any length.

Keywords

trie

FAQs

Package last updated on 08 Nov 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