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

postcss-fontify

v1.1.0

Published

PostCSS plugin for generating font-face declarations from font files in a directory.

Downloads

9

Readme

PostCSS Fontify npm version

PostCSS plugin for generating font-face declarations from font files in a directory.

Usage

Only font files with extensions woff2, woff, ttf, and otf will be recognized and used by the plugin. Any other files with different extensions in the same directory will not be considered. Additionally, the files in the directory must be named in accordance with a specific convention.

Filename convetion

The filename should have two parts. The first part should consist of the font name or font names written without any spaces and with the first letter of each word capitalized. The second part should be separated by a hyphen sign (-) and should contain the font weight and font style. The font style should only be included when the font is italic. The font weight can be one of the following: Thin, ExtraLight, Light, Regular, Medium, SemiBold, Bold, ExtraBold and Black. The two parts should be separated again by a capital letter. For example: PragueSpecial-SemiBoldItalic.woff2.

Variable fonts

Fontify supports Variable Fonts, a new font technology that enables designers and developers to create a single font file with multiple variations of the font, including different weights, styles, and other properties. This technology allows for a more efficient and flexible way of delivering fonts to websites and other digital applications, reducing the file size and allowing for a more customized user experience.

The Variable Fonts page on the Adobe Type team's official website provides a more detailed explanation and examples: https://typekit.com/variablefonts.

To correctly define the @font-face, Variable Fonts are only supported in the woff2 format and require additional information about the font-weight range, which is expressed as number values. The name convention for Variable Fonts requires the keyword 'Var' followed by the font-weight start and end value, separated by an underscore.

If you need to determine which weights your Variable Fonts support or convert Variable font ttf to woff2, here are some helpful links:

Input

From the font files in the specified folder:

`PragueSpecial-SemiBoldItalic.woff2.`
├── public
│   ├── fonts
│   │   ├── PragueSpecial-SemiBoldItalic.woff2
│   │   ├── PragueSpecial-SemiBoldItalic.woff
│   │   ├── PragueSpecial-SemiBoldItalic.ttf
│   │   ├── PragueSpecial-SemiBold.woff2
│   │   ├── PragueSpecial-SemiBold.woff
│   │   ├── PragueVariable-Var100_900.woff2

Output

The following @font-face declaration is created:

@font-face {
  family-name: "Prague Special";
  src: local("Prague Special"),
       url("/fonts/PragueSpecial-SemiBoldItalic.woff2") format("woff2"),
       url("/fonts/PragueSpecial-SemiBoldItalic.woff") format("woff"),
       url("/fonts/PragueSpecial-SemiBoldItalic.ttf") format("ttf");
  font-style: italic;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  family-name: "Prague Special";
  src: local("Prague Special"),
       url("/fonts/PragueSpecial-SemiBold.woff2") format("woff2"),
       url("/fonts/PragueSpecial-SemiBold.woff") format("woff");
  font-style: normal;
  font-weight: 600;
  font-display: swap;
}

@font-face {
  family-name: "Prague Variable";
  src: local("Prague Variable"),
       url("/fonts/PragueVariable-SemiBold.woff2") format("woff2-variations");
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

The font folder can contain multiple font files with the same name and different formats. They will be all used in the src property.

Install

Step 1: Install plugin:

npm install --save-dev postcss postcss-fontify

Step 2: Check you project for existed PostCSS config: postcss.config.js in the project root, "postcss" section in package.json or postcss in bundle config.

Step 3: Add the plugin to plugins list:

module.exports = {
  plugins: [
+   require('postcss-font-face-generator')({
+     fontsDir: './public/fonts/',
+     fontPath: '/fonts/'
+   }),
    require('autoprefixer')
  ]
}

Options

  • fontsDir: The path to the directory containing the font files. Defaults to './fonts/'.
  • fontPath: The path for the @font-face.url declaration. Defaults to '/fonts/'.
  • local: A boolean value indicating if a local font reference should be used. Defaults to true.
  • swap: A boolean value indicating if the font-display property should be set to 'swap'. Defaults to true.