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

url-trie

v1.1.0

Published

splits URLs into useful hierarchical pieces.

Downloads

12

Readme

npm badge travis badge

url-trie

Because I couldn't find a better name.

install

npm install --save url-trie

how to use

the whole package is the function:

func trie (<list-of-urls>, <skip-empty>) <tree>

<list-of-urls> may be an array of strings or a collection of {url, count} objects. count defaults to 1, passing an array of strings is the same as passing a collection of {url, count} objects with count set to 1 always.

<tree> is an object with readable useful url prefixes as keys, each key has as value a {count, ?url, ?next} object, count being the sum of all URLs in this and in the deeper nested paths, url, if exists, being the full URL at the current path and next, if exists, being another <tree>.

see example below and tests for how it works exactly.

example

var trie = require('url-trie')

trie([
  'https://reddit.com/r/golang',
  'https://github.com/fiatjaf/module-linker/issues',
  {url: 'https://reddit.com/r/nim', count: 1},
  {url: 'https://twitter.com/fiatjaf', count: 23},
  'https://www.reddit.com/r/golang/comments/2xxx6m/lua_52_vm_in_go/',
  'https://github.com/fiatjaf',
  'https://github.com/fiatjaf/url-trie',
  'https://github.com/fiatjaf/module-linker'
], true)

// returns:
{
  'reddit.com/r': {
    count: 3,
    next: {
      'reddit.com/r/golang': {
        count: 2,
        url: 'https://reddit.com/r/golang',
        next: {
          count: 1,
          url: 'https://www.reddit.com/r/golang/comments/2xxx6m/lua_52_vm_in_go/'
        }
      },
      'reddit.com/r/nim': {
        count: 1,
        url: 'https://reddit.com/r/nim'
      }
    }
  },
  'twitter.com/fiatjaf': {
    count: 23,
    url: 'https://twitter.com/fiatjaf'
  },
  'github.com/fiatjaf': {
    count: 4,
    url: 'https://github.com/fiatjaf',
    next: {
      'github.com/fiatjaf/url-trie': {
        count: 1,
        url: 'https://github.com/fiatjaf/url-trie'
      }
      'github.com/fiatjaf/module-linker': {
        count: 2,
        url: 'https://github.com/fiatjaf/module-linker',
        next: {
          'github.com/fiatjaf/module-linker/issues': {
            count: 1,
            url: 'https://github.com/fiatjaf/module-linker/issues'
          }
        }
      }
    }
  }
}