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

filter-css

v1.0.0

Published

Filter CSS rules

Downloads

44,424

Readme

filter-css npm version Build Status dependencies Status devDependencies Status Status

Filter CSS rules

Install

npm install --save filter-css

Usage

const filterCss = require('filter-css');
const filtered = filterCss(<input>, <pattern>, <options>);

Input

  • Required
  • Type: String

Can be a path to the CSS file or a raw CSS string.

Pattern

  • Required
  • Type String,RegExp, Function or an Array containing it.

Patterns used to discard specific parts of the CSS. The function is invoked with three arguments (context, value, node).

  • context: Current matching context. Could be one of ['type', 'media', 'selector', 'declarationProperty', 'declarationValue'].
  • value: Current value.
  • node: The currently processed AST node generated by css.

Return true if the element should be discarded.

Options

Per default filter-css will be applied to all parts of the CSS. This behavior can be customized by disabling specific matchers.

| Name | Type | Description | | -------------------------- | --------- |-------------- | | matchSelectors | boolean | Enable / disable matching of CSS selectors. | | matchTypes | boolean | Enable / disable matching of AST Node types like font-face | | matchDeclarationProperties | boolean | Enable / disable matching of CSS properties like background-image | | matchDeclarationValues | boolean | Enable / disable matching of CSS values like url(...) | matchMedia | boolean | Enable / disable matching of media queries like min-device-pixel-ratio: 2 |

Examples

.bigBackground {
    width: 100%;
    height: 100%;
    background-image: url('some/big/image.png');
}

@font-face {
    font-family: 'My awesome font';
}

@media print {
    ...
}
const filterCss = require('filter-css');

filterCss('test/fixtures/test.css', [/url\(/,'@font-face',/print/]);
.bigBackground {
    width: 100%;
    height: 100%;
}

Remove all media queries

const filterCss = require('filter-css');

filterCss('test/fixtures/test.css', /.*/, {
    matchSelectors: false,
    matchTypes: false,
    matchDeclarationProperties: false,
    matchDeclarationValues: false,
    matchMedia: true
});

Using a function matcher

const filterCss = require('filter-css');

filterCss('test/fixtures/test.css', (context, value, node) => {
    return context === 'declarationValue' && value === "url('some/big/image.png')"
});

Complete Example

filterCss('test/fixtures/test.css', {
    types: ['@font-face'],
    selectors: ['.my-selector > p'],
    declarations: [/url/]
});

CLI

filter-css works well with standard input.

cat test/fixture/test.css | filtercss --ignore @font-face

You can also pass in the file as an option.

filtercss test/fixture/test.css --ignore @font-face

CLI options

See filtercss --help for a full list of options.

License

MIT © Ben Zörb