char-size

0.0.0 • Public • Published

char-size

return the size in pixels of a single character

browser support

This is useful for writing column-sensitive wrapping code, particularly for fixed-width fonts.

example

var charSize = require('char-size');
var size = charSize(document.body);
console.log(size.width + 'x' + size.height);

compile the example and open it in a browser:

$ echo '<html><body><script src="bundle.js"></script></body></html>' > index.html
$ browserify size.js > bundle.js
$ xdg-open index.html

in the browser console you'll see:

8x20

methods

var charSize = require('char-size')

var size = charSize(opts)

Return the size of the opts.chr or 'x' character at opts.target or document.body. The size.width and size.height will be integers in pixels.

If opts is a dom element, use it as the opts.target value.

install

With npm do:

npm install char-size

license

MIT

Dependents (2)

Package Sidebar

Install

npm i char-size

Weekly Downloads

1

Version

0.0.0

License

MIT

Last publish

Collaborators

  • nopersonsmodules