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

firebase-humanhash

v0.0.2

Published

Human-readable representations of Firebase push() IDs for JavaScript

Downloads

5

Readme

firebase-humanhash

Human-readable representations of Firebase push() IDs for JavaScript

Why?

To borrow words from the project that inspired this one, the intent is to generate a human-readable (and, most importantly, memorable) representation of a Firebase push() ID, unique enough for display in a user interface, where a user may need to remember or verbally communicate the identity of a push()ed location, without having to remember a 20-character random sequence of uppercase/lowercase letters and numbers.

For example, if you're developing a ticket tracker, it's likely that you're using Firebase's push() to generate new tickets. However, -JJWYEO-S7K2HTDyeQvV is not very user-friendly if you need to display a ticket number in your app. You could generate ticket numbers through some other process but that's more code and data to you have to maintain, and you've stepped outside the realm of using Firebase as your sole server-side solution.

What if you could increase the chance of displaying a non-unique ID marginally (for all practical purposes), while increasing the the human-readability of the ID dramatically? That's where this library comes in. You still use a Firebase push() ID to store your tickets in Firebase, but at the moment of display, you "humanize" the ID.

What's unique enough?

This library maps each byte of a 20-byte Firebase push() ID to a smaller fixed-length representation (from 1 to 19 bytes, default: 4 bytes) using a user-provided dictionary of 256 "words." The number of words chosen corresponds to its statistical uniqueness:

  • 1 word: 1 in 256
  • 2 words: 1 in 65,536
  • 3 words: 1 in 16,777,216
  • 4 words: 1 in 4,294,967,300
  • etc.

As you can see, even with the default 4 byte compression, the uniqueness can be very high.

How?

Input

Node.js:

HH = require "firebase-humanhash"
DEFAULT_HASHER = new HH.HumanHasher()
NUMBER_HASHER = new HH.HumanHasher NUMBER_WORDLIST
id = "-JJWYEO-S7K2HTDyeQvV"
console.log DEFAULT_HASHER.humanize id
console.log DEFAULT_HASHER.humanize id, words=6
console.log DEFAULT_HASHER.humanize id, words=20
console.log NUMBER_HASHER.humanize id, 4, ""

Also works in the browser as a global or an AMD module.

Output

autumn-lactose-apart-louisiana
grey-georgia-floor-delaware-jersey-berlin
Words must be between 1 and 19
014116006125

Contributions

This library was made possible by:

  • https://github.com/zacharyvoase/humanhash
  • https://github.com/shabda/humanhash-coffeescript