Skip to content

An implementation of Node.js's url.domainToASCII() in WebAssembly

License

Notifications You must be signed in to change notification settings

mjethani/domaintoascii

Repository files navigation

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.

Demo

See demo.html

API

domainToASCII(domain, { skipIDNA = false } = {})

Same as url.domainToASCII() except as noted below.

Performance

$ npm run benchmark

> domaintoascii@0.1.0 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

$ 

Development

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.


Tests

About

An implementation of Node.js's url.domainToASCII() in WebAssembly

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages