Socket
Socket
Sign inDemoInstall

css-stringify

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

css-stringify

CSS compiler


Version published
Weekly downloads
176K
decreased by-2.19%
Maintainers
1
Weekly downloads
 
Created

What is css-stringify?

The css-stringify npm package is used to convert a CSS Abstract Syntax Tree (AST) into a CSS string. This is useful for scenarios where you need to programmatically generate or manipulate CSS styles and then convert them back into a string format for use in stylesheets or inline styles.

What are css-stringify's main functionalities?

Basic CSS Stringification

This feature allows you to convert a CSS AST into a CSS string. The example demonstrates how to create a simple AST for a CSS rule and then convert it into a string.

const stringify = require('css-stringify');
const ast = {
  type: 'stylesheet',
  stylesheet: {
    rules: [
      {
        type: 'rule',
        selectors: ['.example'],
        declarations: [
          {
            type: 'declaration',
            property: 'color',
            value: 'red'
          }
        ]
      }
    ]
  }
};
const cssString = stringify(ast);
console.log(cssString); // Outputs: .example {\n  color: red;\n}

Handling Multiple Rules

This feature demonstrates how to handle multiple CSS rules within a single AST and convert them into a CSS string. The example shows two different CSS rules being stringified.

const stringify = require('css-stringify');
const ast = {
  type: 'stylesheet',
  stylesheet: {
    rules: [
      {
        type: 'rule',
        selectors: ['.example1'],
        declarations: [
          {
            type: 'declaration',
            property: 'color',
            value: 'blue'
          }
        ]
      },
      {
        type: 'rule',
        selectors: ['.example2'],
        declarations: [
          {
            type: 'declaration',
            property: 'background',
            value: 'yellow'
          }
        ]
      }
    ]
  }
};
const cssString = stringify(ast);
console.log(cssString); // Outputs: .example1 {\n  color: blue;\n}\n.example2 {\n  background: yellow;\n}

Other packages similar to css-stringify

Keywords

FAQs

Package last updated on 15 Mar 2013

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