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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@glypht/core

v0.0.8

Published

Library for subsetting and (de)compressing font files

Readme

@glypht/core

A JavaScript library for subsetting and compressing font files. This library powers the Glypht web application and provides a programmatic API for font processing tasks. It mainly wraps the HarfBuzz and woff2 libraries; the former for subsetting and the latter for compression.

Care has been taken to ensure compatibility across platforms and JS runtimes. Browsers, Node.js, Bun, and Deno should all function. Because this library makes heavy use of WebAssembly and Web Workers, if you want to bundle Glypht, you'll need a bundler that recognizes and transforms the new URL('...', import.meta.url) and new Worker(new URL('...', import.meta.url), {type: 'module'}) patterns (such as Vite).

For higher-level functionality (such as sorting fonts into groups, instancing multiple output fonts from one input font, and CSS generation), see @glypht/bundler-utils.

Installation

npm install @glypht/core

Quick Start

For an example of using all this functionality end-to-end, see the Glypht CLI's code.

Subsetting

import { GlyphtContext } from '@glypht/core';

// Create a context for font processing
const context = new GlyphtContext();

try {
    // Load font file(s)
    const fontData = new Uint8Array(/* your font file data */);
    const fonts = await context.loadFonts(
        [fontData],
        {transfer: true} /* Transfer the font data to the worker thread */
    );

    // Subset the font
    const subsettedFont = await fonts[0].subset({
        axisValues: [
            {type: 'single', tag: 'wdth', value: 100}, // Pin the width axis to 100
            {type: 'variable', tag: 'wght', value: {min: 400, max: 700}} // Clamp the weight axis between 400 and 700
        ],
        unicodeRanges: {
            named: ['latin', 'latin-ext'], // Include Latin character sets, as defined by Google Fonts
            custom: [] // No custom Unicode ranges
        }
    });

    console.log('Original size:', fontData.length);
    console.log('Subsetted size:', subsettedFont.data.length);

    // If the context is long-lived, you can free individual fonts from it
    for (const font of fonts) {
        font.destroy();
    }
} finally {
    // Clean up. When running in non-browser environments, this terminates
    // worker threads, allowing the process to exit.
    context.destroy();
}

Compression

import { WoffCompressionContext } from '@glypht/core';

// Create a compression context
const compressor = new WoffCompressionContext();

try {
    // Compress TTF to WOFF2
    const ttfData = [
        new Uint8Array(/* your TTF font data */),
        new Uint8Array(/* your TTF font data */),
        new Uint8Array(/* your TTF font data */),
    ];
    // This will compress the fonts in parallel using 3 worker threads (or fewer, if there are fewer than 3 cores)
    const woff2Data = await Promise.all(ttfData.map(fileData => compressor.compressFromTTF(fileData, {
        algorithm: 'woff2',
        level: 11,
        transfer: true // Transfer the font data to the worker thread
    })));

    // Decompress back to TTF
    const decompressed = await Promise.all(woff2Data.map(fileData =>
        compressor.decompressToTTF(fileData, {transfer: true})));
} finally {
    // Clean up. When running in non-browser environments, this terminates
    // worker threads, allowing the process to exit.
    compressor.destroy();
}

Technical Details

This library uses WebAssembly-compiled versions of: