Encoding scheme to encode any Unicode string with only [0-9a-zA-Z_]. Similar to URL percent-encoding. Especially useful for GraphQL ID generation.
ISC License
Encoding scheme to encode any Unicode string
with only characters from [0-9a-zA-Z_]
.
Therefore it's quite similar to URL percent-encoding.
It's especially useful for GraphQL ID generation.
Constraints for the encoding scheme:
file_format
, fileFormat
, FileFormat
,FILE_FORMAT
, __file_format__
, … must not be altered1_file_format
)Input | Output |
---|---|
camelCaseId |
camelCaseId |
snake_case_id |
snake_case_id |
__Schema |
__Schema |
doxxing |
doxxing |
DOXXING |
DOXXXXXXING |
id with spaces |
idXX0withXX0spaces |
id-with.special$chars! |
idXXDwithXXEspecialXX4charsXX1 |
id_with_ümläutß |
id_with_XXaaapmmlXXaaaoeutXXaaanp |
Emoji: 😅 |
EmojiXXGXX0XXbpgaf |
Multi Byte Emoji: 👨🦲 |
MultiXX0ByteXX0EmojiXXGXX0XXbpegiXXacaanXXbpjlc |
\u{100000} |
XXYbaaaaa |
\u{10ffff} |
XXYbapppp |
With encoding of leading digit and double underscore activated (necessary for GraphQL ID generation):
Input | Output |
---|---|
1FileFormat |
XXZ1FileFormat |
__index__ |
XXRXXRindexXXRXXR |
The encoding scheme is based on the following rules:
[0-9A-Za-z_]
except for XX
are encoded as isXX
is encoded as XXXXXX
XX[0-9A-W]
U+fffff
(e.g. Emojis)XX[a-p]{5}
, where the 5 characters are the hexadecimal representationa
to p
instead of 0
to f
.U+100000
to U+10ffff
) are encoded as a sequence of 9 characters:XXY[a-p]{6}
If the optional leading digit encoding is enabled,
a leading digit is encoded as XXZ[0-9]
.
If the optional double underscore encoding is enabled,
double underscores are encoded as XXRXXR
.