New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

fontace

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fontace

Extract useful information from font files

latest
Source
npmnpm
Version
0.4.1
Version published
Weekly downloads
1.2M
-12.17%
Maintainers
1
Weekly downloads
 
Created
Source

fontace

Extract useful information from font files

fontace on NPM CI status

Installation

npm install fontace

Import

import { fontace } from 'fontace';

Why fontace?

fontace is a small library, which intends to extract data specifically to help generate CSS @font-face declarations based on font files.

fontace returns the following CSS-compatible values intended for use with font-family, font-style, unicode-range, and font-weight:

  • family: The font family name as stored in the font file, e.g. "Inter".
  • style: The style of this font file, e.g. "normal" or "italic".
  • unicodeRange: The range of Unicode code points this font file contains, e.g. "U+0-10FFFF".
  • weight: The font weight(s) this file supports, which can be a range for variable fonts, e.g. "400" or "100 900".

In addition it returns:

  • format: The font file format for use in format(), e.g."woff2" or "truetype".
  • isVariable: true if the font file contains variable axes of some kind.
  • unicodeRangeArray: An array of the Unicode code point ranges this font file contains, e.g. ["U+0-10FFFF"], equivalent to unicodeRange.split(', '). Useful if you need to iterate through the available ranges instead of inlining them directly in CSS.

Usage

Pass a buffer containing font file data to fontace() and get useful information back.

Example: local font file

Use file-system APIs to read a local font file and then pass it to fontace():

import { fontace } from 'fontace';
import fs from 'node:fs';

const fontBuffer = fs.readFileSync('./Inter.woff2');
const metadata = fontace(fontBuffer);
// { family: "Inter", format: 'woff2', style: "normal", weight: "400", isVariable: false, unicodeRange: "U+0, U+20-7E...", unicodeRangeArray: ["U+0", "U+20-7E", ...] }

Example: remote font file

Fetch a font file over the network and then pass it to fontace():

import { fontace } from 'fontace';

const response = await fetch('https://example.com/Inter-Variable.woff2');
const fontBuffer = Buffer.from(await response.arrayBuffer());
const metadata = fontace(fontBuffer);
// { family: "Inter", format: 'woff2', style: "normal", weight: "100 900", isVariable: true, unicodeRange: "U+0, U+20-7E...", unicodeRangeArray: ["U+0", "U+20-7E", ...] }

Example: using fontace data to create CSS

const { family, format, isVariable, style, unicodeRange, weight } = fontace(fontBuffer);

let src = `url(/MyFont.woff2) format('${format}')`;
if (isVariable) src += ' tech(variations)';

const fontFaceDeclaration = `@font-face {
  font-family: ${family};
  font-style: ${style};
  font-weight: ${weight};
  font-display: swap;
  unicode-range: ${unicodeRange};
  src: ${src};
}`;

Acknowledgements

fontace uses the fontkitten package to extract data from font files.

License

MIT

Keywords

font

FAQs

Package last updated on 01 Feb 2026

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