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

easytries

v1.0.6

Published

a ~7kb, typed, zero-dependency trie library

Downloads

4

Readme

vhsconnect

Description

A ~7 kb, typed, zero-dependency Tries library.

easyTries is a Trie tree data structure implementation for lookaheads, autocompletes on strings or types that coerce to strings. It is most commonly used for quickly filtering a large set of strings down based on some user input. easyTries is able to filter down a tree of 1,000,000 words down in 0 to 3 ms on our machines. for a quick comparison and benchmark of easyTries, run npm run benchmark.

Structure

example Trie Tree for the words 'CAT', 'CAN' & 'CATHY':


   |Trie 'C'
   |_ children
     |_ Trie 'A'
       |_ children
         |_ Trie 'T'
         | |_ children
         | | |_ Trie 'H'
         | |   |_ children
         | |     |_ Trie 'Y'
         | |       |_ children
         | |       |_ word
         | |_ word
         |_ Trie 'N'
           |_ children
           |_ word

Usage

npm i easytries

Support for Both ES6 imports and CommonJS

import { easyTries } from "easytries";
const { easyTries } = require("easytries");
const trie = easyTries();
trie.set("adam");
trie.set("adam's apple");
trie.set("ads");
trie.set("abe");
trie.get("ad"); // expected [ 'ads', 'adam', 'adam\'s apple']

Options

By default,

  1. Strings are trimmed before being set into the tree
  2. Casing is preserved
  3. No minimum string length required on get operations

You can change One or all of these initial settings by initializing easyTries with options.

Trim

let trie = easyTries({ trim: false }); // default is true
trie.set("  rice");
trie.set("rinse   ");
trie.get("ri"); // expected []
trie.get("  "); // expected ["  rice"]

Casing

let trie = easyTries(); //default
trie.set("STEW");
trie.set("Stew");
trie.set("Stanley");
trie.get("ST"); // expected ["STEW"]
trie.get("st"); // expected []
let trie = easyTries({ casing: "upper" });
trie.set("STEW");
trie.set("Stew");
trie.set("Stanley");
trie.get("ST"); // expected ["STEW", "STANLEY"]
trie.get("st"); // expected ["STEW", "STANLEY"]
let trie = easyTries({ casing: "lower" });
trie.set("STEW");
trie.set("Stew");
trie.set("Stanley");
trie.get("ST"); // expected ["stew", "stanley"]
trie.get("st"); // expected ["stew", "stanley"]

Get Depth

Only return results after a certain string length is met. Probably only useful for extremely large sets, over-the-network operations, or if you want to filter out strings smaller than a particular length.

let trie = easyTries({ startAt: 3, casing: "lower" });
trie.set("I"); // will never get returned
trie.set("int");
trie.set("inert");
trie.set("infinity");
trie.get("i"); // expected []
trie.get("in"); // expected []
trie.get("inf"); // expected ["infinity"]