npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

openfont

v1.0.0

Published

A library for extracting font information from font files

Downloads

81

Readme

OpenFont

A lightweight, TypeScript-based library for extracting detailed information from font files in the browser and Node.js.

npm version License: MIT

Features

  • 🔍 Extract comprehensive font metadata (weight, style, family name, etc.)
  • 🌐 Load fonts from URLs or ArrayBuffer
  • ⚡ Async/await API for seamless integration
  • 📦 Works in both browser and Node.js environments
  • 💪 Full TypeScript support with type definitions
  • 🎨 Perfect for font management tools, design systems, and typography applications

Installation

npm install openfont

Quick Start

Load from URL

import Font from 'openfont';

const font = new Font('https://example.com/path/to/font.ttf');
const info = await font.info();

console.log(info);
// {
//   familyName: "Roboto",
//   styleName: "Bold Italic",
//   weight: "Bold",
//   isItalic: true,
//   isBold: true,
//   fullName: "Roboto Bold Italic",
//   postScriptName: "Roboto-BoldItalic",
//   version: "Version 2.137",
//   ...
// }

Load from File Upload

import Font from 'openfont';

async function handleFileUpload(file: File) {
  const arrayBuffer = await file.arrayBuffer();
  const font = new Font(arrayBuffer);
  
  const weight = await font.getWeight();
  const isItalic = await font.isItalic();
  
  console.log(`Weight: ${weight}, Italic: ${isItalic}`);
}

API Reference

Constructor

new Font(fontSource: string | ArrayBuffer)

Creates a new Font instance.

  • fontSource: Either a URL string pointing to a font file, or an ArrayBuffer containing font data
// From URL
const font1 = new Font('https://fonts.example.com/myfont.ttf');

// From ArrayBuffer
const buffer = await fetch('/font.ttf').then(r => r.arrayBuffer());
const font2 = new Font(buffer);

Methods

info(): Promise<FontInfo>

Returns comprehensive information about the font.

const info = await font.info();

Returns:

{
  familyName: string;        // e.g., "Roboto"
  styleName: string;         // e.g., "Bold Italic"
  weight: number | string;   // e.g., 700 or "Bold"
  isItalic: boolean;
  isBold: boolean;
  fullName: string;          // e.g., "Roboto Bold Italic"
  postScriptName: string;    // e.g., "Roboto-BoldItalic"
  version: string;
  copyright: string;
  trademark: string;
  manufacturer: string;
  designer: string;
  description: string;
  unitsPerEm: number;
  ascender: number;
  descender: number;
}

getWeight(): Promise<number | string>

Returns the font weight. Returns a number (100-900) or a string name (e.g., "Bold", "Light").

const weight = await font.getWeight(); // 700 or "Bold"

isItalic(): Promise<boolean>

Checks if the font is italic or oblique.

const italic = await font.isItalic(); // true or false

isBold(): Promise<boolean>

Checks if the font is bold (weight >= 700).

const bold = await font.isBold(); // true or false

getFamilyName(): Promise<string>

Returns the font family name.

const family = await font.getFamilyName(); // "Roboto"

getStyleName(): Promise<string>

Returns the font style name.

const style = await font.getStyleName(); // "Bold Italic"

getFullName(): Promise<string>

Returns the full font name.

const fullName = await font.getFullName(); // "Roboto Bold Italic"

getPostScriptName(): Promise<string>

Returns the PostScript name.

const psName = await font.getPostScriptName(); // "Roboto-BoldItalic"

getVersion(): Promise<string>

Returns the font version string.

const version = await font.getVersion(); // "Version 2.137"

getCopyright(): Promise<string>

Returns the copyright notice.

const copyright = await font.getCopyright();

getDesigner(): Promise<string>

Returns the font designer's name.

const designer = await font.getDesigner();

getRawFont(): opentype.Font | null

Returns the underlying opentype.js Font object for advanced use cases.

const opentypeFont = font.getRawFont();

React Example

import React, { useState } from 'react';
import Font from 'openfont';

function FontAnalyzer() {
  const [fontInfo, setFontInfo] = useState(null);
  const [loading, setLoading] = useState(false);

  const handleFileUpload = async (e: React.ChangeEvent<HTMLInputElement>) => {
    const file = e.target.files?.[0];
    if (!file) return;

    setLoading(true);
    try {
      const arrayBuffer = await file.arrayBuffer();
      const font = new Font(arrayBuffer);
      const info = await font.info();
      setFontInfo(info);
    } catch (error) {
      console.error('Failed to analyze font:', error);
    } finally {
      setLoading(false);
    }
  };

  const analyzeWebFont = async () => {
    setLoading(true);
    try {
      const font = new Font('https://fonts.gstatic.com/s/roboto/v30/KFOmCnqEu92Fr1Mu4mxK.woff2');
      const info = await font.info();
      setFontInfo(info);
    } catch (error) {
      console.error('Failed to analyze font:', error);
    } finally {
      setLoading(false);
    }
  };

  return (
    <div>
      <h1>Font Analyzer</h1>
      
      <input
        type="file"
        onChange={handleFileUpload}
        accept=".ttf,.otf,.woff,.woff2"
        disabled={loading}
      />
      
      <button onClick={analyzeWebFont} disabled={loading}>
        Analyze Web Font
      </button>

      {loading && <p>Loading...</p>}

      {fontInfo && (
        <div>
          <h2>Font Information</h2>
          <table>
            <tbody>
              <tr>
                <td><strong>Family:</strong></td>
                <td>{fontInfo.familyName}</td>
              </tr>
              <tr>
                <td><strong>Style:</strong></td>
                <td>{fontInfo.styleName}</td>
              </tr>
              <tr>
                <td><strong>Weight:</strong></td>
                <td>{fontInfo.weight}</td>
              </tr>
              <tr>
                <td><strong>Italic:</strong></td>
                <td>{fontInfo.isItalic ? 'Yes' : 'No'}</td>
              </tr>
              <tr>
                <td><strong>Bold:</strong></td>
                <td>{fontInfo.isBold ? 'Yes' : 'No'}</td>
              </tr>
              <tr>
                <td><strong>Designer:</strong></td>
                <td>{fontInfo.designer}</td>
              </tr>
              <tr>
                <td><strong>Version:</strong></td>
                <td>{fontInfo.version}</td>
              </tr>
            </tbody>
          </table>
        </div>
      )}
    </div>
  );
}

export default FontAnalyzer;

Node.js Example

import Font from 'openfont';
import fs from 'fs/promises';

async function analyzeFontFile(filePath: string) {
  const buffer = await fs.readFile(filePath);
  const font = new Font(buffer.buffer);
  
  const info = await font.info();
  console.log('Font Family:', info.familyName);
  console.log('Weight:', info.weight);
  console.log('Is Italic:', info.isItalic);
  console.log('Designer:', info.designer);
}

analyzeFontFile('./fonts/MyFont.ttf');

Supported Font Formats

  • TrueType (.ttf)
  • OpenType (.otf)
  • WOFF (.woff)
  • WOFF2 (.woff2)

Browser Compatibility

OpenFont works in all modern browsers that support ES2020 and the Fetch API:

  • Chrome 80+
  • Firefox 75+
  • Safari 14+
  • Edge 80+

TypeScript Support

OpenFont is written in TypeScript and includes full type definitions out of the box. No need for @types packages.

import Font, { FontInfo } from 'openfont';

const font = new Font('path/to/font.ttf');
const info: FontInfo = await font.info();

Error Handling

All async methods can throw errors. Wrap them in try-catch blocks:

try {
  const font = new Font('https://example.com/font.ttf');
  const info = await font.info();
} catch (error) {
  console.error('Failed to load or parse font:', error);
}

Use Cases

  • Design Systems: Automatically catalog and validate fonts in your design system
  • Font Managers: Build font browsing and management applications
  • Typography Tools: Create tools for font analysis and comparison
  • Web Font Optimization: Analyze web fonts to optimize loading strategies
  • Font Validation: Verify font files meet specific requirements
  • Documentation: Auto-generate font specimen sheets

How It Works

OpenFont is built on top of opentype.js, a powerful font parser. It provides a simplified, promise-based API for common font analysis tasks.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT © Miles Low

Links

Acknowledgments

Built with opentype.js - a powerful JavaScript parser and writer for TrueType and OpenType fonts.