Calculate the pixel size (width/height) of a string (with integrated caching)
TypeScript JavaScript HTML
Latest commit f934f07 Dec 8, 2016 @schickling fix module
Permalink
Failed to load latest commit information.
src added max width Dec 8, 2016
test added max width Dec 8, 2016
.editorconfig Casper Feb 22, 2014
.gitignore rewritten in typescript Dec 7, 2016
.travis.yml fix tests Dec 7, 2016
LICENSE Initial commit Feb 15, 2014
README.md docs Dec 8, 2016
package.json fix module Dec 8, 2016
tsconfig.json fix module Dec 8, 2016
yarn.lock Fixed deps Dec 7, 2016

README.md

calculate-size Build Status npm version

Calculate the pixel size (width/height) of a string (with integrated caching)

Install

This package supports Typescript out-of-the-box

$ npm install calculate-size

Usage

const size = calculateSize('Hello world!', {
   font: 'Arial',
   fontSize: '12px'
})

### Options

* `font: string`
* `fontSize: string`
* `fontWeight: string`
* `width: string` (Constraint width by a fixed value to calc height)

console.log(size.width) // 140
console.log(size.height) // 20