Skip to content

dokutoku/wcwidth-compat

Repository files navigation

wcwidth-compat

Cross-Compiling

This library is a port of wcwidth to the D language.

Usage

D

It is very simple to use.

import wcwidth_compat;

assert(wcwidth(cast(uint)('') == 2);

wasm

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)));

Related project