mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
* Introduce `Bun.stringWidth` * [autofix.ci] apply automated fixes * Update utils.md --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
45 lines
1.3 KiB
JavaScript
45 lines
1.3 KiB
JavaScript
import { bench, run } from "./runner.mjs";
|
|
import npmStringWidth from "string-width";
|
|
|
|
const bunStringWidth = globalThis?.Bun?.stringWidth;
|
|
|
|
bench("npm/string-width (ansi + emoji + ascii)", () => {
|
|
npmStringWidth("hello there! 😀\u001b[31m😀😀");
|
|
});
|
|
|
|
bench("npm/string-width (ansi + emoji)", () => {
|
|
npmStringWidth("😀\u001b[31m😀😀");
|
|
});
|
|
|
|
bench("npm/string-width (ansi + ascii)", () => {
|
|
npmStringWidth("\u001b[31mhello there!");
|
|
});
|
|
|
|
if (bunStringWidth) {
|
|
bench("Bun.stringWidth (ansi + emoji + ascii)", () => {
|
|
bunStringWidth("hello there! 😀\u001b[31m😀😀");
|
|
});
|
|
|
|
bench("Bun.stringWidth (ansi + emoji)", () => {
|
|
bunStringWidth("😀\u001b[31m😀😀");
|
|
});
|
|
|
|
bench("Bun.stringWidth (ansi + ascii)", () => {
|
|
bunStringWidth("\u001b[31mhello there!");
|
|
});
|
|
|
|
if (npmStringWidth("😀\u001b[31m😀😀") !== bunStringWidth("😀\u001b[31m😀😀")) {
|
|
console.error("string-width mismatch");
|
|
}
|
|
|
|
if (npmStringWidth("hello there! 😀\u001b[31m😀😀") !== bunStringWidth("hello there! 😀\u001b[31m😀😀")) {
|
|
console.error("string-width mismatch");
|
|
}
|
|
|
|
if (npmStringWidth("\u001b[31mhello there!") !== bunStringWidth("\u001b[31mhello there!")) {
|
|
console.error("string-width mismatch");
|
|
}
|
|
}
|
|
|
|
await run();
|