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

@glitchybyte/zappy

v1.2.1

Published

Lightweight library for compressing and encoding web-related text (json, URLs, UUIDs, etc.) into a URL-safe format for efficient transport.

Downloads

11

Readme

Zappy

Version Spec

Lightweight library for compressing and encoding web-related text (json, URLs, UUIDs, etc.) into a URL-safe format for efficient transport.

Read the spec here!

Goals

  • Capable of encoding any valid utf-8 string.
  • Transportable as URL-safe plain text.
  • Produce smaller encoded string than vanilla base64 on ASCII payloads.
  • Fast encoding and decoding.

Non-Goals

  • Encryption. This ain't it. It's obfuscation at best.

Notes

To fully take advantage of Zappy, you as a dev should provide contraction tables specialized to your payloads.

Zappy strings should not be stored. They are designed for transport where one side encodes before transmitting and the other side decodes after receiving. If the contraction tables change between encoding and decoding, it's very possible the output will not be the same or even invalid. Keep this in mind when decoding and handle these cases accordingly. That is, always sanitize your (decoded) output and handle decoding error conditions.

API

// Constructor.
Zappy(source: Map<number, string[]> | null, throwOnDecodeErrors = false)

// Base64 string encode/decode.
base64StringEncode(str: string): string
base64StringDecode(str: string): string | null

// Zappy encode/decode.
encode(str: string): string
decode(str: string): string | null

How to use

Add to your project

npm install @glitchybyte/zappy

Define contraction tables

There are 17 contraction tables available for use.

Table 0 is called the fast lookup table, it gets the best compression gains, but only 16 entries are permitted. Entries in table 0 can have a minimum of 2 characters (or 2 bytes when converted to UTF-8) and still have a gain.

Tables 1-17 allow 256 entries each. Entries can have a minimum of 3 characters (or 3 bytes when converted to UTF-8).

Developer defined contraction tables are overlaid onto default tables. There is a default table 0 specialized in json, and a default table 16 with common strings.

Define your contraction tables like so:

const contractions = new Map<number, string[]>([
  [1, [
    "glitchybyte",
    "defenestration",
    "internationalization"
  ]]
])

Encode and decode

const zappy = new Zappy(contractions)
const json = '{' +
  '"codeUrl":"https://github.com/glitchybyte/zappy",' +
  '"msg":"When I deal with internationalization I think of defenestration."' +
  '}'
const encoded = zappy.encode(json)
console.log(`[${encoded.length}] ${encoded}`)
//  [90] 6mNvZGVVcmzm4GdpdGh1Yv8EL_ACL3phcHB5521zZ-ZXaGVuIEkgZGVhbCB3
//       aXRoIPAAIEkgdGhpbmsgb2Yg8AEu6w

// While vanilla base64 is:
const base64Encoded = zappy.base64StringEncode(json)
console.log(`[${base64Encoded.length}] ${base64Encoded}`)
// [164] eyJjb2RlVXJsIjoiaHR0cHM6Ly9naXRodWIuY29tL2dsaXRjaHlieXRlL3ph
//       cHB5IiwibXNnIjoiV2hlbiBJIGRlYWwgd2l0aCBpbnRlcm5hdGlvbmFsaXph
//       dGlvbiBJIHRoaW5rIG9mIGRlZmVuZXN0cmF0aW9uLiJ9

const decoded = zappy.decode(encoded)!
console.log(`[${decoded.length}] ${decoded}`)
// [123] {"codeUrl":"https://github.com/glitchybyte/zappy","msg":"Whe
//       n I deal with internationalization I think of defenestration
//       ."}