Derived from visualwidth-js this package identifies the size of one characterCode in terminals
Last updated 5 years ago by leichtgewicht .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install wcsize 
SYNC missed versions from official npm registry.

ISC License js-standard-style npm version


wcsize is a JavaScript CommonJS package that deals with the fact that some characters in monospace font environments (like terminals) are displayed with the size of two characters while others occupy the space of one character.

It is derived (forked) from wcwidth which is a derivate of wcwidth.c which is custom implemented and seems better tested with japanese than the similar package visualwidth-js. It differes from both of those packages by only returning the width of one character (as integer!) which is important for performance reasons.

This is a sister-package of monospace-char-width whis is based on visualwidth-js.

Installation & Usage

Install the package with npm i wcsize --save and pass the character you want to test like this:

var wcsize = require('wcsize')

function charSize(string, pos) {
    wcsize(string.charCodeAt(pos), pos > 0 ? string.charCodeAt(pos-1) : 0)

charSize('abcd', 0) // 1

Surrogates or Why two character codes?

The size of some characters depends on surrogates which means that depending on the character before their size changes. For it to work appropriately you need to pass-in both the current character code and the one before that.

Current Tags

  • 1.0.0                                ...           latest (5 years ago)

1 Versions

  • 1.0.0                                ...           5 years ago
Maintainers (1)
Today 1
This Week 33
This Month 148
Last Day 3
Last Week 31
Last Month 144
Dependencies (0)
Dev Dependencies (2)

Copyright 2014 - 2017 © taobao.org |