Back to packages list

Vals using punycode

Description from the NPM package:
A robust Punycode converter that fully complies to RFC 3492 and RFC 5891, and works on nearly all JavaScript platforms.

Normalize a domain. Handles trailing . and IDN.

1
2
3
import punycode from "npm:punycode@2.3.1";
export const normalizeDomain = (domain: string): string =>
punycode.toASCII(punycode.toUnicode(domain.replace(/^\.+|\.+$/, "")));

punycode

punycode is so cool. It's esoteric, but like, it's amazing what ingenuity can do.

It's an encoding of UTF-8 - the kind of text with easy representations for unicode sequences like ñ - in ASCII - the one that just supports English. It does this in a way that's reversible, and lets us use UTF8 text in ASCII places, because you can also detect when something is written in punycode. Do you need this, probably not – but someday you will, and you will remember.

1
2
3
4
export let punycodeExample = (async () => {
const { default: punycode } = await import("npm:punycode");
return punycode.encode("mañana");
})();
1
Next