Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
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.
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);
PostCSS is a tool for transforming CSS with JavaScript plugins. These plugins can lint your CSS, support variables and mixins, transpile future CSS syntax, inline images, and more. It is more plugin-driven compared to 'css', offering a broader range of transformations.
Sass (Syntactically Awesome Style Sheets) is a preprocessor scripting language that is interpreted or compiled into Cascading Style Sheets (CSS). It provides more features like variables, nested rules, and mixins compared to the basic CSS manipulations offered by 'css'.
Less is a backward-compatible language extension for CSS. This is very similar to Sass but uses a different syntax. It provides variables, mixins, and functions which allows you to make CSS that is more maintainable, themable, and extendable than the 'css' package.
CSS parser / stringifier using css-parse and css-stringify.
$ npm install css
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}
(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.
FAQs
CSS parser / stringifier
The npm package css receives a total of 834,567 weekly downloads. As such, css popularity was classified as popular.
We found that css demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 11 open source maintainers collaborating on the project.
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.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.