npm i mjethani/domaintoascii
<script type="module">
import { domainToASCII } from 'https://mjethani.github.io/domaintoascii/index.js';
let ascii = domainToASCII('i❤️.ws');
console.log(ascii); // xn--i-7iq.ws
</script>This is an implementation of Node.js's url.domainToASCII() in WebAssembly.
The current version is based on Unicode 13.0.0.
It implements the algorithm described in UTS #46, with non-transitional processing and UseSTD3ASCIIRules=false.
See demo.html
Same as url.domainToASCII() except as noted below.
skipIDNA: Iftrue, skips IDNA mapping and validation and jumps straight to Punycode encoding. Default:false.
$ npm run benchmark
> [email protected] benchmark
> node scripts/benchmark.js
native: 87.021ms
Generated 1,024,580 characters
domaintoascii: 64.457ms
Generated 1,024,580 characters
punycode.js: 145.172ms
Generated 1,024,580 characters
domaintoascii { skipIDNA=true }: 33.507ms
Generated 1,024,580 characters
$ Run npm run build-idna-tables to regenerate the IDNA tables in idna_tables-generated.h.
Make sure Emscripten is installed and set up and then run make clean all to rebuild encoder.wasm.
Ideas are welcome.