mjethani / domaintoascii

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

License:ISC License


Languages

Language:C 90.1%Language:JavaScript 9.1%Language:HTML 0.6%Language:Makefile 0.2%