Socket
Socket
Sign inDemoInstall

text-dimensions

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

text-dimensions

Performant Calculation of the width and height of a text string using canvas (`OffscreenCanvas` if it is supported).


Version published
Weekly downloads
371
increased by19.29%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

text-dimensions

Performant Calculation of the width and height of a text string using canvas (OffscreenCanvas if it is supported).

Installation

npm install text-dimensions

or

yarn add text-dimensions

Usage

import TextDimensions from 'text-dimensions';

const dimensions = new TextDimensions('bold 12pt arial');

const { height, width } = dimensions.measureText('text-dimensions');

console.log('Width of text', width);
console.log('height of text', height);

// cleanup
dimensions.clean();

Methods

  • .measureText(text: string, font?: string): return an object having the height and width of the text string.
  • .clean(): removes the canvas from the DOM if it was added.

License

MIT

FAQs

Package last updated on 18 Oct 2022

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc