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

firebase64

v0.0.1

Published

sortable base64 encoding of string, int32 and boolean

Downloads

816

Readme

Firebase64

Combines two closure library functions with the d64 module to encode/decode (array of) boolean, 32 bit integer, string to/from a ascii embeddable, lexicographic sortable value that can be used as firebase key.

The generated encoded strings can be used to create a firebase:

  • (multi-)field filter index
  • (multi-)field sort values

The implementation uses the following character set: ,PYFGCRLAOEUIDHTNSQJKXBMWVZ_pyfgcrlaoeuidhtnsqjkxbmwvz1234567890

Array items are separated by the character: ~

Example:

	const assert = require('assert');
    const {encode, decode} = require('./index');
    
    const sHello = encode('Hello');
    assert.equal(sHello, 'sH5KgQ5w');
    const sWorld = encode('World');
    assert.equal(sWorld, 'sKqxmQ5F');
    assert.deepEqual([sWorld, sHello].sort().map(decode), ['Hello', 'World']);
    
    const nSmall = encode(100000);
    assert.equal(nSmall, 'n,,55c,');
    const nBig = encode(100016);
    assert.equal(nBig, 'n,,55g,');
    assert.deepEqual([nBig, nSmall].sort().map(decode), [100000, 100016]);
    
    const bTrue = encode(true);
    assert.equal(bTrue, 'b1');
    assert.equal(decode(bTrue), true);
    const bFalse = encode(false);
    assert.equal(bFalse, 'b0');
    assert.equal(decode(bFalse), false);
    
    function multiFieldSort(low, high) {
        const encoded = [encode(high), encode(low)];
        assert.deepEqual(encoded.sort().map(decode), [low, high]);
    }
    
    multiFieldSort(['a', 0], ['a', 1]);
    multiFieldSort(['a', 0], ['b', 0]);
    multiFieldSort(['a', 1], ['aa', 0]);
    
    multiFieldSort(['a', 'a'], ['a', 'b']);
    multiFieldSort(['a', 'a'], ['b', 'a']);
    multiFieldSort(['a', 'b'], ['aa', 'a']);
    
    multiFieldSort(['a', false], ['a', true]);
    multiFieldSort(['a', false], ['b', false]);
    multiFieldSort(['a', true], ['aa', false]);

Api

encode(value: boolean|number|string|[boolean|number|string]) : string

Convert (array of) boolean or 32 bit integer or utf8 string to base64 string

decode(value: string) : boolean|number|string|[boolean|number|string]

Convert encoded base64 string to (array of) boolean or 32 bit integer or utf8 string

stringToByteArray(str: string) : array

Convert string to byte array

byteArrayToString(arr: array): string

Convert array of bytes to string

int32ToByteArray(int32: number) : array

Convert 32 bit integer number to 4 character byte array

byteArrayToInt32(arr: array): number

Convert 4 character byte array to 32 bit integer

encodeString(str: string): string

Convert utf8 string to base64 string

decodeString(str64: string): string

Convert base64 string to utf8 string

encodeInt32(int32: number) : string

Convert 32 bit integer to base64 string

decodeInt32(str64: string): number

Convert base64 string to 32 bit integer

encodeScalar(value: boolean|number|string): string

Convert boolean or 32 bit integer or utf8 string to base64 string

decodeScalar(value: string): boolean|number|string

Convert base64 string to boolean or 32 bit integer or utf8 string