Security News
RubyGems.org Adds New Maintainer Role
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.
Rework is a plugin framework for CSS preprocessing. It allows you to manipulate CSS using JavaScript, providing a way to transform stylesheets with various plugins.
CSS Parsing
Rework can parse CSS strings into an Abstract Syntax Tree (AST), which can then be manipulated programmatically.
const rework = require('rework');
const css = 'body { color: red; }';
const ast = rework(css).toString();
console.log(ast);
CSS Transformation
Rework allows you to transform CSS using plugins. For example, the rework-npm plugin lets you import CSS from npm packages.
const rework = require('rework');
const reworkNPM = require('rework-npm');
const css = '@import "normalize.css";';
const output = rework(css).use(reworkNPM()).toString();
console.log(output);
Vendor Prefixing
Rework can automatically add vendor prefixes to CSS properties using plugins like rework-plugin-prefix.
const rework = require('rework');
const reworkPrefix = require('rework-plugin-prefix');
const css = 'body { display: flex; }';
const output = rework(css).use(reworkPrefix('webkit')).toString();
console.log(output);
PostCSS is a tool for transforming CSS with JavaScript plugins. It is more modern and widely used compared to Rework, offering a larger ecosystem of plugins and better performance.
Less is a CSS pre-processor that extends the CSS language, adding features like variables, mixins, and functions. Unlike Rework, Less is a full-fledged pre-processor rather than a plugin framework.
Sass is another CSS pre-processor that provides advanced features like variables, nested rules, and mixins. Sass is more feature-rich and has a larger community compared to Rework.
CSS manipulations built on node-css, allowing you to automate vendor prefixing, create your own properties, inline images, anything you can imagine!
with node:
$ npm install rework
or in the browser:
$ component install visionmedia/rework
Return a new Rework
instance for the given string of css
.
Define vendor prefixes
that plugins may utilize,
however most plugins do and should accept direct passing
of vendor prefixes as well.
Use the given plugin fn
. A rework "plugin" is simply
a function accepting the stylesheet object and Rework
instance,
view the definitions in ./lib/plugins
for examples.
Return the string representation of the manipulated css.
The following plugins are bundled with rework
:
Add retina support for images, with optional vendor
prefixes,
defaulting to .vendors()
.
logo {
background-image: url('/public/images/logo.png')
}
yields:
logo {
background-image: url('/public/images/logo.png')
}
@media all and (-webkit-min-device-pixel-ratio: 1.5) {
.logo {
background-image: url("/public/images/logo@2x.png")
}
}
Prefix property
with optional vendors
defaulting to .vendors()
.
.button {
border-radius: 5px;
}
yields:
.button {
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
}
Prefix value
with optional vendors
defaulting to .vendors()
.
button {
transition: height, transform 2s, width 0.3s linear;
}
yields:
button {
-webkit-transition: height, -webkit-transform 2s, width 0.3s linear;
-moz-transition: height, -moz-transform 2s, width 0.3s linear;
transition: height, transform 2s, width 0.3s linear
}
Prefix selectors with the given string
.
h1 {
font-weight: bold;
}
a {
text-decoration: none;
color: #ddd;
}
yields:
#dialog h1 {
font-weight: bold;
}
#dialog a {
text-decoration: none;
color: #ddd;
}
Add IE opacity support.
ul {
opacity: 1 !important;
}
yields:
ul {
opacity: 1 !important;
-ms-filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=100) !important;
filter: alpha(opacity=100) !important
}
Prefix @keyframes with vendors
defaulting to .vendors()
.
Ordering with .keyframes()
is important, as other plugins
may traverse into the newly generated rules, for example the
following will allow .prefix()
to prefix keyframe border-radius
property, .prefix()
is also smart about which keyframes definition
it is within, and will not add extraneous vendor definitions.
var css = rework(read('examples/keyframes.css', 'utf8'))
.vendors(['-webkit-', '-moz-'])
.use(rework.keyframes())
.use(rework.prefix('border-radius'))
.toString()
@keyframes animation {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
yields:
@keyframes animation {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@-webkit-keyframes animation {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
example.js:
var rework = require('rework')
, read = require('fs').readFileSync
, str = read('example.css', 'utf8');
var css = rework(str)
.vendors(['-webkit-', '-moz-'])
.use(rework.keyframes())
.use(rework.prefix('border-radius'))
.toString()
console.log(css);
example.css:
@keyframes animation {
from { opacity: 0; border-radius: 5px }
to { opacity: 1; border-radius: 5px }
}
stdout:
@keyframes animation {
from {
opacity: 0;
border-radius: 5px
}
to {
opacity: 1;
border-radius: 5px
}
}
@-webkit-keyframes animation {
from {
opacity: 0;
-webkit-border-radius: 5px;
border-radius: 5px
}
to {
opacity: 1;
-webkit-border-radius: 5px;
border-radius: 5px
}
}
@-moz-keyframes animation {
from {
opacity: 0;
-moz-border-radius: 5px;
border-radius: 5px
}
to {
opacity: 1;
-moz-border-radius: 5px;
border-radius: 5px
}
}
Suppose for example you wanted to create your own properties for positions, allowing you to write them as follows:
#logo {
absolute: top left;
}
#logo {
relative: top 5px left;
}
#logo {
fixed: top 5px left 10px;
}
yielding:
#logo {
position: absolute;
top: 0;
left: 0
}
#logo {
position: relative;
top: 5px;
left: 0
}
#logo {
position: fixed;
top: 5px;
left: 10px
}
This is how you could define the plugin:
var rework = require('rework')
, read = require('fs').readFileSync;
function positions() {
var positions = ['absolute', 'relative', 'fixed'];
return function(style){
style.rules.forEach(function(rule){
rule.declarations.forEach(function(decl, i){
if (!~positions.indexOf(decl.property)) return;
var args = decl.value.split(/\s+/);
var arg, n;
// remove original
rule.declarations.splice(i, 1);
// position prop
rule.declarations.push({
property: 'position',
value: decl.property
});
// position
while (args.length) {
arg = args.shift();
n = parseFloat(args[0]) ? args.shift() : 0;
rule.declarations.push({
property: arg,
value: n
});
}
});
});
}
}
var css = rework(read('positions.css', 'utf8'))
.use(positions())
.toString()
console.log(css);
(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
Plugin framework for CSS preprocessing
The npm package rework receives a total of 408,103 weekly downloads. As such, rework popularity was classified as popular.
We found that rework 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
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.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.