Namecode
Encode arbitrary Unicode strings into valid programming language identifiers. Think "Punycode for variable names."
Output is a valid UAX 31 identifier, compatible with Rust, Go, JavaScript, and Python.
Usage
use ;
// Valid XID identifiers pass through unchanged
assert_eq!;
assert_eq!;
assert_eq!;
// Non-XID characters get encoded
let encoded = encode;
assert!;
assert_eq!;
Properties
| Property | Definition |
|---|---|
| Roundtrip | decode(encode(s)) == s for all encoded strings |
| Passthrough | Valid XID identifiers pass through unchanged |
| Idempotent | encode(encode(x)) == encode(x) |
| Identity | encode(decode(s)) == s for valid encodings |
| O(n) | Linear time encode and decode |
CLI
# _N_helloworld__fa0b
# hello world
|
# _N_foobar__da1d
Specification
See SPEC.md for the full encoding format, algorithm details, and test vectors.
License
Apache-2.0