
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
get-text-width
Advanced tools
This helper function is intended to get the rendered width of text. It leverages canvas to simulate the rendered text and calculate the width using the font of your project.
It also has a backup height:width ratio number in case something goes wrong with the canvas.
Returns numeric value of width in pixels
Here is an example of how to implement this function.
import { getTextWidth } from 'get-text-width';
const width = getTextWidth("Hello world");
// The function also accepts as custom
// backup font height:width ratio like so:
const width = getTextWidth("Hello world", 0.5);
height:width aspect ratios| Font | Aspect ratio |
|---|---|
Arial | 0.52 |
Arial Black | 0.52 |
Calibri | 0.46 |
Candara | 0.47 |
Century Gothic | 0.53 |
Corbel | 0.46 |
DejaVu Sans | 0.55 |
DejaVu Sans Condensed | 0.55 |
DejaVu Sans Light | 0.55 |
Eurostile | 0.47 |
Franklin Gothic | 0.49 |
Futura | 0.51 |
Gadget | 0.55 |
Geneva | 0.55 |
Gill Sans | 0.45 |
GNU Free Sans | 0.53 |
Goudy Sans | 0.48 |
Helvetica | 0.52 |
Helvetica Neue | 0.52 |
Impact | 0.65 |
Liberation Sans | 0.53 |
Lucida Grande | 0.53 |
Lucida Sans Unicode | 0.53 |
Myriad | 0.48 |
Optima | 0.47 |
Serpentine BoldBold | 0.47 |
Stone Sans | 0.52 |
Tahoma | 0.55 |
Trebuchet MS | 0.52 |
Verdana | 0.55 |
| Font | Aspect ratio |
|---|---|
Baskerville | 0.45 |
Bernhard Modern | 0.34 |
Big Caslon | 0.47 |
Book Antiqua | 0.46 |
Bookman Old Style | 0.47 |
Calisto MT | 0.47 |
Cambria | 0.47 |
Century | 0.46 |
Century Schoolbook | 0.46 |
Cochin | 0.37 |
Constantia | 0.45 |
DejaVu Serif | 0.52 |
DejaVu Serif Condensed | 0.52 |
Didot | 0.43 |
Garamond | 0.38 |
Georgia | 0.48 |
GNU Free Serif | 0.45 |
Goudy Old Style | 0.40 |
Hoefler Text | 0.44 |
Humana Serif | 0.50 |
Janson Text | 0.43 |
Liberation Serif | 0.46 |
Minion | 0.45 |
New York | 0.55 |
Palatino | 0.46 |
Times New Roman | 0.45 |
| Font | Aspect ratio |
|---|---|
Andale Mono | 0.51 |
Consolas | 0.49 |
Courier New | 0.43 |
DejaVu Mono | 0.55 |
GNU Free Mono | 0.42 |
Liberation Mono | 0.53 |
Lucida Console | 0.53 |
| Font | Aspect ratio |
|---|---|
URW Alcuin SCT | 0.51 |
American Typewriter | 0.51 |
Barbedor | 0.49 |
Caflisch Script | 0.37 |
Chalkboard | 0.53 |
Charlemagne | 0.74 |
Comic Sans MS | 0.55 |
Copperplate | 0.44 |
Corsiva | 0.60 |
Flemish Script | 0.28 |
Herculanum | 0.61 |
Marker Felt | 0.62 |
Papyrus | 0.46 |
Sand | 0.69 |
Textile | 0.68 |
FAQs
This module helps calculate the rendered width of text.
The npm package get-text-width receives a total of 1,167 weekly downloads. As such, get-text-width popularity was classified as popular.
We found that get-text-width demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.