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

base65537

v65538.0.0

Published

Like Base65536, but one better

Downloads

11

Readme

base65537

No, YOU shut up!

Base65537 is a binary encoding optimised for UTF-32-encoded text and Twitter. It is one better than Base65536.

The output makes the most efficient possible usage of the 65,537-character repertoire available to it, outputting a string whose length is, on average, the minimum necessary to express all of the input binary data. Notably, no padding characters are needed or used.

Installation

npm install base65537

Usage

import { encode, decode } from 'base65537'

const uint8Array = Uint8Array.from([
  0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
  0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0xf1, 0x1f
])

const str = encode(uint8Array)
console.log(str) // "䯕傺檸𥴏髌𡎱𦸜💩"

const uint8Array2 = decode(str)
console.log(uint8Array2) // same as `uint8Array`

How does it work?

A Uint8Array is a string over a 256-character alphabet of bytes. Strings over any alphabet can be enumerated by placing them in order of length and then sorting strings of equal length lexicographically. So:

  • Uint8Array.from([]) ↔ 0
  • Uint8Array.from([0]) ↔ 1
  • Uint8Array.from([1]) ↔ 2
  • ...
  • Uint8Array.from([255]) ↔ 256
  • Uint8Array.from([0, 0]) ↔ 257
  • Uint8Array.from([0, 1]) ↔ 258
  • etc.

For the Base65537 encoding we use an encoding alphabet of 65,537 Unicode characters. These characters have all the same attributes as those used for Base65536; no whitespace, no control characters, immune to Unicode normalization procedures, and generally completely inert and safe to transmit through any "Unicode-clean" text interface. Applying the same enumeration:

  • "" ↔ 0
  • "㐀" ↔ 1
  • "㔀" ↔ 2
  • ...
  • "💩" ↔ 65537
  • "㐀㐀" ↔ 65538
  • "㐀㔀" ↔ 65539
  • etc.

base65537 encodes a Uint8Array by converting it to a single number as above, then converting the number to a string. Decoding is accomplished by reversing this process. Simple!

How does Base65537 compare with Base65536?

Horribly. The conversion described above takes O(n2) time in the length of the input. Even apart from this, the code is mostly appalling. Plus, it's like 200 kilobytes!

Furthermore, Base65536 uses 256 padding characters for a total repertoire of 65,792, whereas Base65537 uses strictly 65,537 characters, making it less efficient in terms of space usage as well. In particular, the "largest" byte sequence which Base65537 can store in a 140-character Tweet is the 280-byte sequence [0xFF, 0x8C, 0x25, ... 0x8B], which encodes to "💩💩💩...💩" (140 poops long). So, unlike Base65536, Base65537 cannot store all possible 280-byte sequences in a Tweet, only most of them.

These shortcomings are expected to be fixed in Base65538.