text-dimensions
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i text-dimensions

Weekly Downloads

6,223

Version

0.1.2

License

MIT

Unpacked Size

42.7 kB

Total Files

16

Last publish

Collaborators

  • ritz078