Socket
Socket
Sign inDemoInstall

filter-css

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

filter-css

Filter CSS rules


Version published
Maintainers
1
Created
Source

filter-css Build Status

Filter CSS rules

Install

$ npm install --save filter-css

Usage

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

var filtered = filterCss('test.css',{
    types: ['<type>'],
    selectors: ['.my-selector > p', /(some)|(regexp)/],
    declarations: ['url(myImage.png)', /url/],
});

When only filtering types and seletors you can use a shorthand. Types are identified by a leading @. Everything else (RegExp, String) is used for selector matching.

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

var filtered = filterCss('test.css',['@<type>','.my > complete-selector',/complete/]);

You can also pass in a filter function. The function receives the type as first and the AST Element / String as second argument. When the function returns true, the element will be discarded.

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

var filtered = filterCss('test.css',function(type, data){
	return type === 'type' && data === 'font-face' ||
		   type === 'selector' && data.match(/test/) ||
    	   type === 'declaration' && /background/.test(data.property) && /url/.test(data.value);
});

body {
	margin: 0;
	padding: 0;
}

@font-face {
	font-family: 'Glyphicons Halflings';
}
Match @type
var filterCss = require('filter-css');

filterCss('test/fixtures/test.css',['@font-face']);
//=> 
body {
	margin: 0;
	padding: 0;
}
Match RegExp
var filterCss = require('filter-css');

filterCss('test/fixtures/test.css',[/bod/]);
//=> 
@font-face {
	font-family: 'Glyphicons Halflings';
}
Filter Declaration
.bigBackground {
	width: 100%;
	height: 100%;
	background-image: url('some/big/image.png');
}
var filterCss = require('filter-css');

filterCss('test/fixtures/test.css',[/url\(/]);
//=> 
.bigBackground {
	width: 100%;
	height: 100%;
}

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

API

filterCss(input, [ignores])

input

Required
Type: string

CSS filepath or raw css string.

ignores

Type: array

List of RegExp, @type or selectors to remove

License

MIT © Ben Zörb

Keywords

FAQs

Package last updated on 02 May 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc