import path from "path";
import Canvas, { Font } from "canvas";

// Reference: https://github.com/badges/shields
const element = new Canvas(0, 0);
const ctx = element.getContext("2d");
try {
  const fontFile = path.join(__dirname, "..", "Verdana.ttf");
  const font = new Font("Verdana", fontFile);
  ctx.addFont(font);
} catch(err) {
  console.warn(`Failed to add font: ${err}`);
}
ctx.font = "11px Verdana, \"DejaVu Sans\"";

export default function measureTextWidth(text) {
  return ctx.measureText(text).width | 0;
}

@@ -510,12 +510,247 @@
 idth %7C 0;%0A%7D%0A
+%0Aif (require.main === module) %7B%0A  const TEST_STRINGS = %5B%0A    %22FF%22,%0A    %22Google Chrome%22,%0A    %22Microsoft Internet Explorer%22,%0A    %22Safari%22%0A  %5D;%0A  TEST_STRINGS.forEach(str =%3E %7B%0A    console.log(%60$%7Bstr%7D %5B$%7BmeasureTextWidth(str)%7D%5D%60);%0A  %7D);%0A%7D%0A

Add text width tester