Socket
Socket
Sign inDemoInstall

css

Package Overview
Dependencies
2
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    css

CSS parser / stringifier using css-parse and css-stringify


Version published
Maintainers
1
Install size
17.6 kB
Created

Package description

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

Readme

Source

css

CSS parser / stringifier using css-parse and css-stringify.

Installation

$ npm install css

Example

js:

var css = require('css')
var obj = css.parse('tobi { name: "tobi" }')
css.stringify(obj);

object returned by .parse():

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

string returned by .stringify(ast):

tobi {
  name: tobi;
}

string returned by .stringify(ast, { compress: true }):

tobi{name:tobi}

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