Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

font-details

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

font-details

This package allows for easy testing of what size a string from a font will be when it is rendered

  • 0.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

font-details

About

This package allows for easy testing of what size a string from a font will be when it is rendered

Usage

import { getFontDetails } from "font-details";
function main(): TextMetrics {
 const details = getFontDetails(10, "monospace");
 //Gets the details of "10px monospace" with the character 'a'
 return details;
}
// Returns
{
  "actualBoundingBoxAscent": 5,
  "actualBoundingBoxDescent": 0,
  "actualBoundingBoxLeft": 0,
  "actualBoundingBoxRight": 5,
  "fontBoundingBoxAscent": 9,
  "fontBoundingBoxDescent": 3,
  "width": 5.498046875
}

Properties can just be directly returned

function getWidthExample(): number {
 const details = getFontDetails(10, "monospace");
 //Gets the details of "10px monospace" with the character 'a'
 return details.width; // 5.498046875, in this case
}

Custom strings can also be used

The default string used for measuring text is simply "a"

function customStringExample(): number {
 const details = getFontDetails(10, "monospace", "ab");
 //Gets the details of "10px monospace" with the character 'a'
 return details.width; // 10.99609375, in this case
}

As this font is monospace, the width of "ab" is double the width of "a", as each glyph has the same width. This isn't the case for most fonts, where different letters have different widths

If you like this package, leave it a star on github:

Tommypop2 - font-details stars - font-details

FAQs

Package last updated on 08 Mar 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

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc