All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Wcwidth-O1: TypeScript/JavaScript Implementation of Unicode Character Width Calculation

By

dawson0

8mo ago· 2 min readenCode

Summary

Wcwidth-O1 is a TypeScript/JavaScript implementation of Markus Kuhn's wcwidth and wcswidth functions, which determine how many terminal columns Unicode characters occupy. The library faithfully clones the original POSIX-standard implementation while optimizing performance to O(1) complexity. It handles character width calculations for both standard and CJK (Chinese, Japanese, Korean) characters, where East Asian ideographs typically occupy two columns instead of one.

Key quotes

· 4 pulled
A TypeScript/JavaScript port of Markus Kuhn's wcwidth and wcswidth implementations, optimized to O(1)
These functions are defined in IEEE Std 1003.1 (POSIX)
In fixed-width terminals, most Latin characters take up one column, while East Asian (CJK) ideographs usually take up two
The challenge is deciding how many 'cells' each Unicode character should occupy so that text aligns
Snippet from the RSS feed
A TypeScript/JavaScript port of Markus Kuhn’s wcwidth. Faithfully clones the original implementation. - dawsonhuang0/Wcwidth-O1

You might also wanna read