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

css

Package Overview
Dependencies
Maintainers
11
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css

CSS parser / stringifier

  • 3.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4.7M
decreased by-4.13%
Maintainers
11
Weekly downloads
 
Created

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

Keywords

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

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