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

trieste

v0.2.0

Published

Trie generator.

Downloads

55

Readme

trieste

NPM

NPM version Build Status Coverage Status

Trie generator.

Installation

NPM:

$ npm install trieste --save

Yarn:

$ yarn add trieste

CDN:

<script src="https://unpkg.com/trieste@latest/dist/trieste.min.js"></script>

Usage

Module

Import the module:

// CommonJS
const trieste = require('trieste');

// ES Modules
import trieste from 'trieste';

Trie

Create a trie instance:

const trie = trieste();

This can also be done by instantiating the constructor:

const Trie = require('trieste/lib/trie');
const trie = new Trie();

Options

Options can be set for each instance:

const options = {
  endKey: 'END_OF_STRING_KEY',
  endValue: 'END_OF_STRING_VALUE'
};
const trie = trieste(options);

This can also be achieved with the constructor:

const Trie = require('trieste/lib/trie');

const trie = new Trie({
  endKey: 'END_OF_STRING_KEY',
  endValue: 'END_OF_STRING_VALUE'
});

Options are found on the instance's options property:

trie.options;

The default options are:

{
  endKey: '$$',
  endValue: 1
}

Options have a direct effect on the trie's data and methods like add and get.

Data

Data can be found on the instance's data property:

trie.data;

Data is a POJO (Plain Old JavaScript Object), which means it can be converted to JSON:

JSON.stringify(trie.data);

As an example, the following is the output of trieste().add('a').data:

{ a: { '$$': 1 } }

Methods

Add

Add a string to the trie:

trie.add('foo');

Add multiple strings to the trie:

trie.add('foo', 'bar');

Add an array of strings to the trie:

trie.add.apply(trie, ['foo', 'bar']);

Add a string with a value to the trie:

trie.add({ answer: 42 });

This is useful if you want to store value(s) other than the default. See method get on how to retrieve a string value.

Since the method returns its own instance, method chaining is possible:

trie.add('foo').add('bar');

Arguments that are not type string will be skipped.

Contains

Check if a string is found in the trie:

trie.contains('foo');

The method returns a boolean value.

Arguments that are not type string will return false.

Get

Get a string value from the trie:

trie.get('foo');

The value comes from options.endValue, which is 1 by default:

trie.add('foo').get('foo'); // 1

The value can be set using the add method:

trie.add({ foo: 'bar' }).get('foo'); // 'bar'

The value can also be set in options:

const trie = trieste({ endValue: null });
trie.add('foo').get('foo'); // null

Arguments that are not type string will return undefined.

Remove

Remove a string from the trie:

trie.remove('foo');

Remove multiple strings from the trie:

trie.remove('foo', 'bar');

Remove an array of strings from the trie:

trie.remove.apply(trie, ['foo', 'bar']);

Since the method returns its own instance, method chaining is possible:

trie.remove('foo').remove('bar');

Arguments that are not type string will be skipped.

Testing

Run tests:

$ npm test

Run tests in watch mode:

$ npm run test:watch

Run tests with coverage:

$ npm run test:coverage

View coverage in browser:

$ npm run test:coverage:report
$ open coverage/index.html

Lint files:

$ npm run lint

Fix lint errors:

$ npm run lint:fix

Release

Only collaborators with credentials can release and publish:

$ npm run release
$ git push --follow-tags && npm publish

License

MIT