Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

css-node-extract

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-node-extract

Extract certain nodes from CSS code

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
81K
increased by2.43%
Maintainers
1
Weekly downloads
 
Created
Source

css-node-extract

Build Status

Extract certain nodes from CSS code.

Filters

  • at-rules: @media, @supports, @mixin,...
  • declarations: $variable, @variable,...
  • functions: @function
  • mixins: @mixin and .less-mixin-selector()
  • rules: .class-selector, #id-selector,...
  • silent: Extract only nodes that do not compile to CSS code (mixins, placeholder selectors, variables,...)
  • variables: $sass-variable and @less-variable
  • custom: Define a custom filter

Demos

var cssNodeExtract = require('css-node-extract');
var postcssScssSyntax = require('postcss-scss');

var options = {
  // CSS source code as string.
  css: '$variable: "value"; .selector { } .other-selector { }',
  // Extract only variables.
  filters: ['variables'],
  // postcss syntax plugin to add support for SCSS code.
  postcssSyntax: postcssScssSyntax
};

// Asynchronous:
cssNodeExtract.process(options).then((extractedCss) => {
  console.log(extractedCss); // Outputs: '$variable: "value";'.
});

// Synchronous:
var extractedCss = cssNodeExtract.processSync(options);
console.log(extractedCss); // Outputs: '$variable: "value";'.

Custom filter

var cssNodeExtract = require('css-node-extract');

var options = {
  // CSS source code as string.
  css: '@keyframes { } .selector { } .other-selector { }',
  filters: ['custom'],
  customFilter: [
    [
      { property: 'type', value: 'atrule' },
      { property: 'name', value: 'keyframes' }
    ]
  ]
};

cssNodeExtract.process(options).then((extractedCss) => {
  console.log(extractedCss); // Outputs: '@keyframes { }'.
});

ES2015 named exports

import { process, processSync } from 'css-node-extract';
import postcssScssSyntax from 'postcss-scss';

const options = {
  // CSS source code as string.
  css: '$variable: "value"; .selector { } .other-selector { }',
  // Extract only variables.
  filters: ['variables'],
  // postcss syntax plugin to add support for SCSS code.
  postcssSyntax: postcssScssSyntax
};

// Asynchronous:
process(options).then((extractedCss) => {
  console.log(extractedCss); // Outputs: '$variable: "value";'.
});

// Synchronous:
processSync(options);
console.log(extractedCss); // Outputs: '$variable: "value";'.

Upgrade from 0.x.x to 1.x.x

With version 1.0.0 the filterNames option was renamed to filters.

// New
var options = {
  css: '$variable: "value"; .selector { } .other-selector { }',
  filters: ['variables'],
  postcssSyntax: postcssScssSyntax
};

// Old
var options = {
  css: '$variable: "value"; .selector { } .other-selector { }',
  filterNames: ['variables'],
  postcssSyntax: postcssScssSyntax
};

Development

See CONTRIBUTING.md

Testing

npm test

About

Author

Markus Oberlehner
Website: https://markus.oberlehner.net
Twitter: https://twitter.com/MaOberlehner
PayPal.me: https://paypal.me/maoberlehner

License

MIT

Keywords

FAQs

Package last updated on 06 Sep 2017

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