npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mongodb-js/triejs

v0.2.1

Published

Customizable trie data structure built in JavaScript.

Downloads

13

Readme

:warning: This fork merely fixes devDependencies listed as dependencies and because the original project is no longer maintained, published as @mongodb-js/triejs on npm.


Triejs Build Status

A Javascript implementation of a trie data structure with an extensible data model to easily customize to any need. Visit the Triejs page for more info and technical details.

##Usage

You can choose to drop Triejs into your project several ways. You can download the raw source and add it via a script tag in your html. Or if you plan on using it in a node project you can install it via npm install triejs

###Basic Creating a trie is as easy as creating a new object:

> var Triejs = require('triejs');
> var trie = new Triejs();

To add a word with some data associated it call add:

> trie.add(<word>, <data>);

Now given any prefix of letters, you can return results possible words using find:

> trie.find(<word>);
  => <data>

###Advanced

To customize the data just pass optional data, including functions to support data manipulation. These include sort to sort data being entered, insert to customize how data is input, copy for moving data between nodes in the trie, and clip for removing data from the cache layer if it grows too big.

####Example

Options are passed via the constructor as a hash like so:

var trie = new Triejs({
  // sort the data in the context 'this'
  sort: function() {
    this.sort(function(a, b) {
      return b.rank - a.rank;
    });
  }
  // insert data into the target
  , insert: function(target, data) {
    // override for non array implementation
  }
  // clip the data in the context 'this' to length max
  , clip: function(max) {
    this.splice(0, this.length - max);
  }
  // return a copy of data
  , copy: function(data) {
    // override and return new data for non array implementation
  }
  // merge data into target and return target
  , merge: function(target, data) {
    // override and return target with data merged in
  }
});

##Testing

The test suite is built using Bob Remeika's foounit and can be tested in both the browser and in node. To test in node simple run the following command node tests/vendor/suite.js in the root directory or if Triejs was installed using npm then run npm test

To test in a browser you will need to npm install and then run foounit serve in the root directory. Then you can direct your browser to localhost:5057/tests/vendor/runner.html to see the test suite run

##License

Triejs is licensed under the MIT License copyright (c) 2012 Paul Thurlow