This library is a port of wcwidth to the D language.
It is very simple to use.
import wcwidth_compat;
assert(wcwidth(cast(uint)('A') == 2);
The generated WASM is not optimized, so you need to optimize it with a tool such as Binaryen.
wasm-opt -O -o wcwidth-compat.wasm wcwidth-compat.wasm
When run in Node.js, the code is as follows.
const fs = require('fs');
let bytes = new Uint8Array(fs.readFileSync('./wcwidth-compat.wasm'));
let instance = new WebAssembly.Instance(new WebAssembly.Module(bytes), {});
let input = 'A';
console.log(instance.exports.wcwidth(input.codePointAt(0)));