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

simplecoder

v3.1.0

Published

Encode values using simple dictionaries.

Downloads

13

Readme

simplecoder

simplecoder allows you to encode data using human-friendly dictionaries.

Think of it like base64, but instead of characters, you can use dictionaries comprised of simple words (the default dictionary is a curated set of some of the most common, easily distinguishable 4-letter words in English).

If you are capable of producing additional dictionaries, especially in other languages, please consider submitting a pull request, it would gladly be accepted.

Examples

You could encode a UUID using the default 4-letter word English dictionary:

c27c98fa-32fc-406e-a7ddebce44fe9e77

such mean pull wood
ever work flow like
rule trip wave that
free year rest main

Now, that's obviously longer than the UUID in string form, but imagine one of your customers trying to read you the UUID string over the phone, whereas this word-based encoding would be fairly easy.

Even a SHA256 isn't terrible:

2bd806c97f0e00af1a1fc3328fa763a9269723c8db8fac4f93af71db186d6e90

down tone band tall miss boat able ship
case cook suit ever page rule just salt
deal post cost talk town page seed hand
pick ship long town card lift like pair

The encoded version of the SHA256 might actually be easily verified by a human, whereas comparing two strings of base64 is much more error-prone.

You could use the emoji dictionary to encode, say a SHA256 of the latest LTS node.js release:

🍦🏑🐰🐥🐍🐯🐭🎡🐓🐭🍨🍴🐉🎡🌂🐧🐓🍳🐡🐓🐯🍤🐔🍺

🍪🎓🌀🐫🎱🌲🐙🏈⌛️🐭🐕🍺🐣🎷🐫🍸🍈🍕🍪🎧⌛️🍬🐓🐓

That's a little more fun than:

a8f679f595fd921305c28d126935ad59b4419ac8474a99997a31e01ab50acd3d

Installation

npm install simplecoder

Usage

const uuid = require( 'uuid' );
const simplecoder = require( 'simplecoder' );

// create a uuid in a buffer (avoid encoding as hex and doubling size)
const my_uuid = uuid.v4( null, Buffer.alloc( 16 ) );
const encoded = simplecoder.encode( guid );

// ->
// [ 'such', 'mean', 'pull', 'wood',
//   'ever', 'work', 'flow', 'like',
//   'rule', 'trip', 'wave', 'that',
//   'free', 'year', 'rest', 'main' ]

const decoded = simplecoder.decode( encoded );

// ->
// <Buffer c2 7c 98 fa 32 fc 40 6e a7 dd eb ce 44 fe 9e 77>

decoded.toString( 'hex' );

// ->
// 'c27c98fa32fc406ea7ddebce44fe9e77'

API

  • encode( buffer | array | string[, dictionary ] ) : array

Takes the given buffer, array or string and returns an encoded array from the given dictionary. If no dictionary is specified, simplecoder will use the default simple 4-letter word English dictionary.

Example:

simplecoder.encode( uuid.v4( null, Buffer.alloc( 16 ) ), 'en' );

// ->
// [ 'such', 'mean', 'pull', 'wood',
//   'ever', 'work', 'flow', 'like',
//   'rule', 'trip', 'wave', 'that',
//   'free', 'year', 'rest', 'main' ]

// Using webpack and want to ensure a certain dictionary is there? Require it
// directly so webpack will know to include it:

const DICTIONARIES = {
    en: require( 'simplecoder/dictionaries/en.js' ),
    es: require( 'simplecoder/dictionaries/es.js' )
};
  • decode( array[, dictionary ] ) : buffer

Take an array of simplecoder-encoded values and an optional dictionary and produce an output buffer. If the dictionary is not specified, the default simple 4-letter word English dictionary will be assumed.

Example:

simplecoder.decode( [
    'such', 'mean', 'pull', 'wood',
    'ever', 'work', 'flow', 'like',
    'rule', 'trip', 'wave', 'that',
    'free', 'year', 'rest', 'main'
], 'en' );

// ->
// <Buffer c2 7c 98 fa 32 fc 40 6e a7 dd eb ce 44 fe 9e 77>

Supported Dictionaries

  • emoji
  • en
  • es

Contributing

Pull requests are very welcome! Just make sure your code:

  1. Has no eslint warnings or errors
  2. Is beautified using jsbeautifier and the included .jsbeautifyrc
  3. Has tests and all tests pass

Why?

I was looking for a way to produce human-readable hashes and ids that could be more easily shared and verified via things like phone calls.

CHANGELOG

v3.0.0

  • Dynamic importing of dictionaries (can help with code size on the browser side)
  • Change encode/decode to take a dictionary name (eg: 'en') vs. a dictionary object
  • Add Spanish dictionary
  • Improve eslint configuration

v2.0.0

  • Convert CLI to support a REPL
  • Require Node v8+
  • Switch to eslint from jshint

v1.0.0

  • First stable release

v0.0.5

  • Update repo URLs

v0.0.4

  • Improved documentation

v0.0.3

  • Rename to 'simplecoder'
  • Improve code + testing

v0.0.2

  • Multiple dictionary support (emojis!)

v0.0.1

  • Prototyping