Skip to main content

Encoder/decoder for UTF-64, a URL-safe encoding for JSONish strings

Project description

utf-64

A terse, human-readable, URL-safe encoding for JSONish strings.

Test JS Test Python Test Go

Overview

Use this when you need to encode a string to make it URL-safe, but you also want to keep it as small and readable as possible (unlike base64). For example:

Input string base64 utf64
Hello SGVsbG8= YHello
"Hello!" IkhlbGxvISI= AYHelloGA
{"Hello":"world"} eyJIZWxsbyI6IndvcmxkIn0= MAYHelloAFAworldAN

I made this because I wanted to build a web API with a nice JSON schema that could also be cached by a CDN. To make it cacheable, I had to use the GET method; but GET can't (portably) have a request body, so this means all the API parameters need to be packed into the URL. utf64 is a fire-and-forget way to solve this problem.

Installation & usage

JavaScript

npm install utf64
import * as utf64 from "utf64";

console.log(utf64.encode("Hello!"));
console.log(utf64.decode("YHelloG"));

Python

pip install utf64
import utf64

print(utf64.encode("Hello!"))
print(utf64.decode("YHelloG"))

Go

go get utf64.moreplease.com
package main

import (
	"fmt"
	"utf64.moreplease.com"
)

func main() {
	fmt.Println(utf64.Encode("Hello!"))
	result, err := utf64.Decode("YHelloG")
	if err != nil {
		panic(err)
	}
	fmt.Println(result)
}

Command-line tool

The JS package includes a utf64 command-line tool:

npm install -g utf64
utf64 "Hello\!"
utf64 -d YHelloG

Specification

Output is encoded using base64url-compatible characters: _ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-

utf64 Decoded as
_ As-is
a to z As-is
0 to 9 As-is
ABCDEFGHIJKLMNOPQRSTU Mapped to: "',.;:!?()[]{}#=+-*/\
V Newline
W Space
X Prefix for Unicode 0-63. For example, "Xk" is "%" (U+0025)
Y Prefix for Unicode 64-127. For example, "Y_" is "@" (U+0040)
Z Prefix for Unicode 128+. The following characters are interpreted as UTF-8, reduced to 6-bit bytes by stripping the redundant top two bits. For example, "ZhBr" is "" (UTF-8 [11]100010 [10]000010 [10]101100)

See test.json for tests that (hopefully) cover all the edge cases, for both valid and invalid encodings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

utf64-0.0.10.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

utf64-0.0.10-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file utf64-0.0.10.tar.gz.

File metadata

  • Download URL: utf64-0.0.10.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for utf64-0.0.10.tar.gz
Algorithm Hash digest
SHA256 9eb14603ad2e4eccaaece9851933c05654e334958d7144dd71a6091d664b89ee
MD5 d30e24dc4876f7200fbda699a5901d02
BLAKE2b-256 2250b23ba627d7d6416fc07bca5b942ad7dd31a775654cfb452b93e711c5a560

See more details on using hashes here.

File details

Details for the file utf64-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: utf64-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for utf64-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 b149d80b11b8364dfbfdff3b35a47cda6eafa76423e3d6f97fad080a11759c83
MD5 dc7870193ae6a13474727956043414d5
BLAKE2b-256 23aab4a2c461ee3fc175fdb193e133b855cf4cd910b1642fbeaa112d3c6d1ae1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page