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

memorable-unique-identifier

v1.0.8

Published

Memorable Unique Identifier

Downloads

3

Readme

Memorable Unique Identifiers for Node.js/TypeScript

A implementation of Memorable Unique Identifiers (Muids) in Node.js/TypeScript

Installation

npm install memorable-unique-identifier

Usage

import { MemorableUniqueIdentifier } from "memorable-unique-identifier";

// Create a key of difficulty 6 this should
// not take long at all.
const result = MemorableUniqueIdentifier.create(6);

console.error(result);

// Example result output (your result will vary)
//
// {
//  length: 6,
//  pretty: 'Sma Eel',
//  key: '1ed2798ec3f5d61270629ab6ad14f7e8',
//  hash: '53aee16014b2829688c2907ae010f90b'
// }

API

MemorableUniqueIdentifier

MemorableUniqueIdentifier:

Static animal

animal(key: string): undefined | string

Return the animal name from the specified key.

Parameters:

| Name | Type | Description | | ----- | ------ | --------------------------------------------- | | key | string | The key to hash and retrieve the animal name. |

Returns: undefined | string

Static bhash

bhash(key: string): string

Return the first 32 bytes a hex encoded string

Parameters:

| Name | Type | Description | | ----- | ------ | ----------------------------------------- | | key | string | The key to hash (should be lowercase hex) |

Returns: string

string A 32 byte hash

Static create

create(difficulty: number): MinedKey

Create a new memorable unique identifier with the specified difficulty.

Parameters:

| Name | Type | Default | Description | | ------------ | ------ | ------- | ----------------------------------------------- | | difficulty | number | 8 | The difficulty or length of the Muid to create. |

Returns: MinedKey

Static difficulty

difficulty(key: string): number

The difficulty or length of the passed key

Parameters:

| Name | Type | Description | | ----- | ------ | ----------------- | | key | string | The candidate key |

Returns: number

number The difficulty of the key. 0 if the key is invalid.

Static mine_until

mine_until(difficulty: number, quota: number): MinedKey[]

Mine until the necessary number of keys are produced.

Parameters:

| Name | Type | | ------------ | ------ | | difficulty | number | | quota | number |

Returns: MinedKey[]

Static search

search(code: string): undefined | string

Return the spirit animal given the public identity

Parameters:

| Name | Type | Description | | ------ | ------ | ---------------------------------------- | | code | string | The code of which to extract the animal. |

Returns: undefined | string

Static shash

shash(source: Buffer): string

Hash a Buffer and return the first 16 bytes encoded in hex as a 32 byte string.

Parameters:

| Name | Type | Description | | -------- | ------ | ------------------- | | source | Buffer | The buffer to hash. |

Returns: string

Static validate

validate(key: string): boolean

Check to see if the key is a memorable unique identifier by extracting the animal name.

Parameters:

| Name | Type | Description | | ----- | ------ | ----------------- | | key | string | The candidate key |

Returns: boolean

boolean Indicate if the key is a valid Muid

MinedKey

MinedKey:

hash

hash: string

key

key: string

length

length: number

pretty

pretty: string

TODO

[ ] Use the WebCrypto API's to allow these identifiers to be generated in the browser.