Socket
Socket
Sign inDemoInstall

css-parse

Package Overview
Dependencies
0
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css-parse

CSS parser


Version published
Weekly downloads
914K
increased by2.29%
Maintainers
1
Install size
7.27 kB
Created
Weekly downloads
 

Package description

What is css-parse?

The css-parse npm package is a utility for parsing CSS strings into an abstract syntax tree (AST). This can be useful for analyzing, transforming, or manipulating CSS code programmatically.

What are css-parse's main functionalities?

Parsing CSS to AST

This feature allows you to parse a CSS string into an abstract syntax tree (AST). The resulting AST can be used for further analysis or transformation of the CSS code.

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

Handling CSS Errors

This feature demonstrates how to handle errors that may occur during the parsing of CSS. The parser will throw an error if the CSS is not well-formed, which can be caught and handled appropriately.

const css = require('css-parse');
try {
  const stylesheet = css.parse('body { font-size: 12px;');
} catch (error) {
  console.error('CSS Parsing Error:', error.message);
}

Other packages similar to css-parse

Readme

Source

css-parse

CSS parser.

Example

js:

var parse = require('css-parse')
parse('tobi { name: "tobi" }')

object returned:

{
  "stylesheet": {
    "rules": [
      {
        "selectors": ["tobi"],
        "declarations": [
          {
            "property": "name",
            "value": "tobi"
          }
        ]
      }
    ]
  }
}

Performance

Parsed 15,000 lines of CSS (2mb) in 40ms on my macbook air.

License

(The MIT License)

Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Keywords

FAQs

Last updated on 17 Sep 2012

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc