postcss-discard-font-face
Discard font faces by type, with PostCSS.
Last updated 5 years ago by beneb .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install postcss-discard-font-face 
SYNC missed versions from official npm registry.

postcss-discard-font-face Build Status NPM version Dependency Status

Discard font faces by type, with PostCSS.

Install

With npm do:

npm install postcss-discard-font-face --save

Example

When discarding TTF fonts:

Input

@font-face {
    src: url("webfont.ttf") format("truetype"),
         url("webfont.svg#svgFontName") format("svg");
}

Output

@font-face {
    src: url("webfont.svg#svgFontName") format("svg");
}

API

discardFonts([filter|options])

filter

Type: function|array Return: boolean|string Arguments: The function is passed the URL of the font as the first argument, and the format as the second.

For each font, return false to remove, or a new string if you would like to transform the URL.

// Remove fonts of an unknown type

discardFonts(function (url, format) {
    if (~url.indexOf('.exe')) {
        return false;
    }
});

Alternately, you can whitelist an array of types:

discardFonts(['ttf', 'svg']);

With this setting, all extensions that do not match will be removed.

options

font

Type: object

Each key in this object should correspond to a font name, which will then be discarded if its properties do not correspond to the whitelisted properties. For example, to only allow a font weight of 400 & a font style of normal, it would be configured like so:

discardFonts({
    font: {
        'Open Sans': {
            weight: [400],
            style: ['normal']
        }
    }
});

Usage

See the PostCSS documentation for examples for your environment.

Contributing

Pull requests are welcome. If you add functionality, then please add unit tests to cover it.

License

MIT © Ben Briggs

Current Tags

  • 3.0.0                                ...           latest (5 years ago)

6 Versions

  • 3.0.0                                ...           5 years ago
  • 2.1.0                                ...           5 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.0.1                                ...           6 years ago
  • 1.0.0                                ...           6 years ago
Downloads
Today 6
This Week 12
This Month 59
Last Day 6
Last Week 29
Last Month 141
Dependencies (2)
Dev Dependencies (4)

Copyright 2014 - 2017 © taobao.org |