An open API service indexing awesome lists of open source software.

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)

Awesome Lists containing this project

README

          

calculate-size [![Build Status](https://travis-ci.org/schickling/calculate-size.svg?branch=master)](https://travis-ci.org/schickling/calculate-size) [![npm version](https://badge.fury.io/js/calculate-size.svg)](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
```