B36
A custom base36 encoder for long strings of numbers.
Install / Use
/learn @AshKyd/B36README
Custom base36 encoder
This code implements a custom codec that lets you reduce the number of bytes used to store large numbers.
It only works on digits and was designed for the js13k game contest.
How it works
Normal base36 can be used on Javascript integers to convert numbers into alphanumeric strings like so:
var encoded = (1234).toString(36);
var decoded = parseInt(encoded, 36);
This is useful, but we're limited by the maximum safe integer size in Javascript. This codec chunks an infinitely* long string of numbers into groups of 8 bytes with the intention of staying under the safe integer size (around 15 digits). Each of these is encoded from base10 to base36, then concatenated into the output.
The result is a drastically smaller string with a corresponding compression ratio.
Example (what do you mean?!)
For instance, the following numeric string is encoded from 34 characters to 25 characters:
original 2134567355234523454657865432435465
encoded 1jqu2wy81psrshxd2dp313x6f
decoded 2134567355234523454657865432435465
As a case study, 8 levels from my js13k entry compressed from 752 bytes to 549 bytes, saving 203 bytes for magic that would otherwise not have been able to fit.
Why/how to do?!
To use it:
var codec = require('b36');
var myString = '12345678901234567890';
var encoded = codec.enc(myString);
var decoded = codec.dec(encoded);
console.log(myString === decoded);
// true
Alternatively if you're space constrained, the decoder is around 120 bytes so you may want to include it separately.
This seems complicated and…
Yeah, I guess it is. My use case is fairly narrow, so your mileage may vary.
Related Skills
node-connect
345.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
106.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
345.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
345.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
