You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP

css

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
c

css

CSS parser / stringifier

3.0.0
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

84

Maintenance

100

License

Version published
Weekly downloads
4.2M
-23.12%
Maintainers
11
Weekly downloads
 
Created
Issues
90

What is css?

The 'css' npm package is a powerful library for parsing, manipulating, and generating CSS. It allows developers to programmatically work with CSS stylesheets, making it easier to handle dynamic styling in web applications.

What are css's main functionalities?

Parsing CSS

This feature allows you to parse a CSS string into a JavaScript object. The parsed result includes detailed information about styles, rules, and selectors, which can be manipulated or queried.

const css = require('css');
const stylesheet = css.parse('body { font-size: 12px; }');
console.log(stylesheet);

Stringifying CSS

This feature converts a JavaScript object representing a CSS stylesheet back into a CSS string. This is useful for generating CSS styles dynamically based on logic within your application.

const css = require('css');
const obj = {
  type: 'stylesheet',
  stylesheet: {
    rules: [{
      type: 'rule',
      selectors: ['body'],
      declarations: [{
        type: 'declaration',
        property: 'margin',
        value: '0 auto'
      }]
    }]
  }
};
const stringifiedCSS = css.stringify(obj);
console.log(stringifiedCSS);

Manipulating CSS

This feature allows you to manipulate an existing CSS stylesheet by adding, modifying, or removing rules and declarations. This example demonstrates adding a new declaration to an existing rule.

const css = require('css');
const stylesheet = css.parse('h1 { color: red; }');
stylesheet.stylesheet.rules[0].declarations.push({
  type: 'declaration',
  property: 'font-size',
  value: '20px'
});
const newCSS = css.stringify(stylesheet);
console.log(newCSS);

Other packages similar to css

FAQs

Package last updated on 02 Jul 2020

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