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

@nagman/sass-fontface

v1.1.1

Published

A package to easily load woff and woff2 fonts into your SASS with a @font-face mixin

Downloads

10

Readme

SASS @font-face mixin

A simple mixin to load your fonts without the @font-face boilerplate.

Install

  1. yarn add @nagman/sass-fontface

  2. Rename your fonts following this format: name-weight-style.woff, and put them in a folder in your project:

project
└── fonts
  ├── foobar-400-normal.woff
  ├── foobar-400-normal.woff2
  ├── foobar-400-italic.woff
  ├── foobar-400-italic.woff2
  ├── foobar-700-normal.woff
  └── foobar-700-normal.woff2
  1. Import the mixin into your SCSS code:
@import "@nagman/sass-fontface/mixin";
  1. Include fonts by providing every variant of it:
@include fontFace(
  $name: "foobar",
  $variants: (
    (weight: 400, style: normal),
    (weight: 400, style: italic),
    (weight: 700, style: normal)
  )
);
  1. Enjoy your webfonts:
html {
  font-family: "foobar", sans-serif;
}

strong {
  font-weight: 700;
}

em {
  font-style: italic;
}

Output

@font-face {
  font-family: "foobar";
  src: url("/fonts/foobar-400-normal.woff2") format("woff2"), url("/fonts/foobar-400-normal.woff")
      format("woff");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "foobar";
  src: url("/fonts/foobar-400-italic.woff2") format("woff2"), url("/fonts/foobar-400-italic.woff")
      format("woff");
  font-weight: 400;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "foobar";
  src: url("/fonts/foobar-700-normal.woff2") format("woff2"), url("/fonts/foobar-700-normal.woff")
      format("woff");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

Options

The mixin takes 4 parameters:

  • $name: a name for the font. Will be used in your font-family properties ;
  • $variants: a list of variants for this font. Each item is a map with two keys:
    • weight: 100, 200, 300, 400, 500, 600, 700, 800 or 900 ;
    • style: normal, italic or oblique ;
  • $dir: the path to your fonts' files. This is optional and the default value is /fonts. You can end it with or without a trailing slash (it will be trimmed) ;
  • $swap: true or false. If true, it will set the font-display property to true.

Weights in numbers

Most of the time, your font file will be named like this: FooBar Regular.woff.

You must convert the Regular to a number in order for this package to work.

Find out which font-weight number corresponds to your font: https://developer.mozilla.org/en-US/docs/Web/CSS/font-weight#Common_weight_name_mapping

Font optimization

I highly recommend you to subset your fonts before serving them. They will load faster because they will only contain the characters you need.

You can do this with Transfonter.

Here are my recommended settings for French (remove the accented characters if you only want English):

  • Family support: On
  • Add local() rule: Off
  • Fix vertical metrics: Off
  • Autohint font: Off
  • Base64 encode: Off
  • Formats: WOFF and WOFF2
  • Subsets: leave blank
  • Characters: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¢£¥¨©«®´¸»ÀÂÆÇÈÉÊËÎÏÔÙÛÜàâæçèéêëîïôùûüÿŒœŸˆ˚˜–—‘’‚“”„•…‹›€™
  • Unicode ranges: leave blank