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

@csstools/css-parser-algorithms

Package Overview
Dependencies
Maintainers
3
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@csstools/css-parser-algorithms

Algorithms to help you parse CSS from an array of tokens.

  • 3.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created

What is @csstools/css-parser-algorithms?

@csstools/css-parser-algorithms is a library designed to help parse and manipulate CSS using various algorithms. It provides tools to work with CSS syntax trees, making it easier to analyze and transform CSS code programmatically.

What are @csstools/css-parser-algorithms's main functionalities?

Parsing CSS

This feature allows you to parse a CSS string into an Abstract Syntax Tree (AST). The AST can then be used for further analysis or transformation.

const { parse } = require('@csstools/css-parser-algorithms');
const css = 'body { color: red; }';
const ast = parse(css);
console.log(ast);

Traversing AST

This feature allows you to traverse the AST nodes. You can define enter and leave functions to perform actions when entering or leaving a node.

const { parse, traverse } = require('@csstools/css-parser-algorithms');
const css = 'body { color: red; }';
const ast = parse(css);
traverse(ast, {
  enter(node) {
    console.log('Entering:', node.type);
  },
  leave(node) {
    console.log('Leaving:', node.type);
  }
});

Transforming CSS

This feature allows you to transform the CSS AST. In this example, the color property is changed from red to blue.

const { parse, transform } = require('@csstools/css-parser-algorithms');
const css = 'body { color: red; }';
const ast = parse(css);
const newAst = transform(ast, {
  enter(node) {
    if (node.type === 'Declaration' && node.property === 'color') {
      node.value = 'blue';
    }
  }
});
console.log(newAst);

Other packages similar to @csstools/css-parser-algorithms

Keywords

FAQs

Package last updated on 01 Nov 2024

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