Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
postcss-rem-to-pixel
Advanced tools
Convert rem (root em) units to px units using PostCSS. Based on postcss-pxtorem.
A plugin for PostCSS that generates px units from rem units.
$ npm install postcss-rem-to-pixel --save-dev
Sometimes you need to include a third-party css file that uses rems. Great pracitice! Unless you can't afford to change your body font-size just for some vendor. This script converts every rem value to a px value from the properties you choose using a default font size of 16px.
With the default settings, only font related properties are targeted.
// input
h1 {
margin: 0 0 20px;
font-size: 2rem;
line-height: 1.2;
letter-spacing: 0.0625rem;
}
// output
h1 {
margin: 0 0 20px;
font-size: 32px;
line-height: 1.2;
letter-spacing: 1px;
}
var fs = require('fs');
var postcss = require('postcss');
var remToPx = require('postcss-rem-to-pixel');
var css = fs.readFileSync('main.css', 'utf8');
var options = {
replace: false
};
var processedCss = postcss(remToPx(options)).process(css).css;
fs.writeFile('main-px.css', processedCss, function (err) {
if (err) {
throw err;
}
console.log('Rem file written.');
});
Type: Object | Null
Default:
{
rootValue: 16,
unitPrecision: 5,
propList: ['font', 'font-size', 'line-height', 'letter-spacing'],
selectorBlackList: [],
replace: true,
mediaQuery: false,
minRemValue: 0
}
rootValue
(Number) The root element font size.unitPrecision
(Number) The decimal precision px units are allowed to use, floored (rounding down on half).propList
(Array) The properties that can change from rem to px.
*
to enable all properties. Example: ['*']
*
at the start or end of a word. (['*position*']
will match background-position-y
)!
to not match a property. Example: ['*', '!letter-spacing']
['*', '!font*']
selectorBlackList
(Array) The selectors to ignore and leave as rem.
['body']
will match .body-class
[/^body$/]
will match body
but not .body
replace
(Boolean) replaces rules containing rems instead of adding fallbacks.mediaQuery
(Boolean) Allow rem to be converted in media queries.minRemValue
(Number) Set the minimum rem value to replace.var gulp = require('gulp');
var postcss = require('gulp-postcss');
var autoprefixer = require('autoprefixer');
var remToPx = require('postcss-rem-to-pixel');
gulp.task('css', function () {
var processors = [
autoprefixer({
browsers: 'last 1 version'
}),
remToPx({
replace: false
})
];
return gulp.src(['build/css/**/*.css'])
.pipe(postcss(processors))
.pipe(gulp.dest('build/css'));
});
Currently, the easiest way to have a single property ignored is to use a capital in the rem unit declaration.
// `rem` is converted to `px`
.convert {
font-size: 1rem; // converted to 16px
}
// `Rem` or `REM` is ignored by `postcss-rem-to-pixel` but still accepted by browsers
.ignore {
border: 1Rem solid; // ignored
border-width: 2REM; // ignored
}
FAQs
Convert rem (root em) units to px units using PostCSS. Based on postcss-pxtorem.
We found that postcss-rem-to-pixel demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.