You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

calculate-text-size

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calculate-text-size

Calculate the pixel size of a string

3.0.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

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

Keywords

font

FAQs

Package last updated on 25 Jul 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts