https://github.com/schickling/calculate-size
Calculate the pixel size (width/height) of a string (with integrated caching)
https://github.com/schickling/calculate-size
Last synced: over 1 year ago
JSON representation
Calculate the pixel size (width/height) of a string (with integrated caching)
- Host: GitHub
- URL: https://github.com/schickling/calculate-size
- Owner: schickling
- License: mit
- Created: 2014-02-15T14:42:10.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2018-05-27T19:06:50.000Z (about 8 years ago)
- Last Synced: 2025-03-28T20:07:07.640Z (over 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 81.1 KB
- Stars: 121
- Watchers: 4
- Forks: 19
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
calculate-size [](https://travis-ci.org/schickling/calculate-size) [](https://badge.fury.io/js/calculate-size)
==============
Calculate the pixel size (width/height) of a string (with integrated caching)
## Install
> This package supports Typescript out-of-the-box
```sh
$ npm install calculate-size
```
## Usage
```js
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
```