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 🙏

© 2024 – Pkg Stats / Ryan Hefner

font-ligatures

v1.4.1

Published

Find ligature replacements for any system font

Downloads

8,474

Readme

font-ligatures

GitHub Actions codecov npm version

Find ligature replacements for any system font. Useful for determining glyph substitutions and ranges where ligatures exist within a string of input text.

npm install font-ligatures

Usage

const fontLigatures = require('font-ligatures');

(async () => {
  const font = await fontLigatures.load('Iosevka');
  console.log(font.findLigatures('in --> out'));
  // {
  //   inputGlyphs:   [ 76, 81, 3, 16,   16,   33, 3, 82, 88, 87 ],
  //   outputGlyphs:  [ 76, 81, 3, 3140, 3128, 33, 3, 82, 88, 87 ],
  //   contextRanges: [ [ 3, 6 ] ]
  // }
})();

API

load(name, [options])

Loads the font with the given name, returning a Promise with a Font that can be used to find ligature information.

Params

  • name [string] - The font family of the font to load
  • options [object] - Optional configuration object containing the following keys:
    • cacheSize [number] - The amount of data from previous results to cache within the parser. The size is measured by the length of the input text for each call. Turned off by default.

loadFile(path, [options])

Loads the font at the given path, returning a Promise with a Font that can be used to find ligature information.

Params

  • path [string] - Path to the file containing the font
  • options [object] - Optional configuration object containing the following keys:
    • cacheSize [number] - The amount of data from previous results to cache within the parser. The size is measured by the length of the input text for each call. Turned off by default.

loadBuffer(buffer, [options])

Loads the font from it's binary data, returning a Font that can be used to find ligature information.

Params

  • buffer [ArryaBuffer] - Binary data of the font file as an ArrayBuffer
  • options [object] - Optional configuration object containing the following keys:
    • cacheSize [number] - The amount of data from previous results to cache within the parser. The size is measured by the length of the input text for each call. Turned off by default.

Font

Object returned by load(). Includes the following methods:

findLigatures(text)

Scans the provided text for font ligatures, returning an object with the following keys:

  • inputGlyphs [number[]] - The list of font glyphs in the input text.
  • outputGlyphs [number[]] - The list of font glyphs after performing replacements for font ligatures.
  • contextRanges [[number, number][]] - Sorted array of ranges that must be rendered together to produce the ligatures in the output sequence. The ranges are inclusive on the left and exclusive on the right

findLigatureRanges(text)

Scans the provided text for font ligatures, returning an array of ranges where ligatures are located.

Params

  • text [string] - text to search for ligatures

Font Support

This library is designed to support fonts that make use of programming ligatures. As a result, it is tested against all of the ligatures produced by the following fonts:

If there is another font that you use which doesn't seem to be working, please open an issue with the font information and where to get it. The most likely cause is that the font uses a type of substitution which is not yet supported.

Contributing

Want to contribute to the project? Go check out the Contribution Guide for instructions to set up your development environment, open an issue and create a pull request.