Calculate the pixel size (width/height) of a string (with integrated caching)
Switch branches/tags
Nothing to show
Clone or download
schickling Merge pull request #6 from rockon404/master
Added lineHeight option and test
Latest commit 019bc48 May 27, 2018
Permalink
Failed to load latest commit information.
src added lineHeight option and test May 27, 2018
test added lineHeight option and test May 27, 2018
.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 added lineHeight option to README.md May 27, 2018
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`
* `lineHeight: string`
* `width: string` (Constraint width by a fixed value to calc height)

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