Gathering detailed insights and metrics for postcss-transform
Gathering detailed insights and metrics for postcss-transform
Gathering detailed insights and metrics for postcss-transform
Gathering detailed insights and metrics for postcss-transform
postcss
Tool for transforming styles with JS plugins
postcss-reduce-transforms
Reduce transform functions with PostCSS.
postcss-modules-scope
A CSS Modules transform to extract export statements from local-scope classes
postcss-modules-extract-imports
A CSS Modules transform to extract local aliases for inline imports
npm install postcss-transform
Typescript
Module System
Node Version
NPM Version
69.9
Supply Chain
97.8
Quality
75.5
Maintenance
50
Vulnerability
100
License
JavaScript (89.76%)
CSS (10.24%)
Total Downloads
964
Last Day
3
Last Week
4
Last Month
23
Last Year
217
8 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Apr 13, 2021
Minified
Minified + Gzipped
Latest Version
1.0.0
Package Id
postcss-transform@1.0.0
Unpacked Size
12.99 kB
Size
4.69 kB
File Count
10
NPM Version
6.14.11
Node Version
14.16.0
Cumulative downloads
Total Downloads
Last Day
0%
3
Compared to previous day
Last Week
-20%
4
Compared to previous week
Last Month
-23.3%
23
Compared to previous month
Last Year
85.5%
217
Compared to previous year
1
CSS converts other units(px/rem/em)
Tips:This project is based on the modifications made by
postcss-pxtorem
and extended some features
A plugin for PostCSS that generates rem units from pixel units.
1$ npm install postcss-transform --save-dev
Pixels are the easiest unit to use (opinion). The only issue with them is that they don't let browsers change the default font size of 16. This script converts every px value to a rem from the properties you choose to allow the browser to set the font size.
With the default settings, only font related properties are targeted.
1// input 2h1 { 3 margin: 0 0 20px; 4 font-size: 32px; 5 line-height: 1.2; 6 letter-spacing: 1px; 7} 8 9// output 10h1 { 11 margin: 0 0 20px; 12 font-size: 2rem; 13 line-height: 1.2; 14 letter-spacing: 0.0625rem; 15}
1var fs = require('fs'); 2var postcss = require('postcss'); 3var pxTransform = require('postcss-transform'); 4var css = fs.readFileSync('main.css', 'utf8'); 5var options = { 6 replace: false 7}; 8var processedCss = postcss(pxTransform(options)).process(css).css; 9 10fs.writeFile('main-rem.css', processedCss, function (err) { 11 if (err) { 12 throw err; 13 } 14 console.log('Rem file written.'); 15});
Type: Object | Null
Default:
1{ 2 rootValue: 16, 3 unitPrecision: 5, 4 propList: ['font', 'font-size', 'line-height', 'letter-spacing'], 5 selectorBlackList: [], 6 replace: true, 7 mediaQuery: false, 8 minPixelValue: 0, 9 exclude: /node_modules/i 10}
targetUnit
(String) css unit string (new add)rootValue
(Number | Function) Represents the root element font size or returns the root element font size based on the input
parameterunitPrecision
(Number) The decimal numbers to allow the REM units to grow to.propList
(Array) The properties that can change from px to rem.
*
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 px.
['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 px to be converted in media queries.minPixelValue
(Number) Set the minimum pixel value to replace.exclude
(String, Regexp, Function) The file path to ignore and leave as px.
'exclude'
will match \project\postcss-transform\exclude\path
/exclude/i
will match \project\postcss-transform\exclude\path
function (file) { return file.indexOf('exclude') !== -1; }
1var gulp = require('gulp'); 2var postcss = require('gulp-postcss'); 3var autoprefixer = require('autoprefixer'); 4var pxTransform = require('postcss-transform'); 5 6gulp.task('css', function () { 7 8 var processors = [ 9 autoprefixer({ 10 browsers: 'last 1 version' 11 }), 12 pxTransform({ 13 replace: false 14 }) 15 ]; 16 17 return gulp.src(['build/css/**/*.css']) 18 .pipe(postcss(processors)) 19 .pipe(gulp.dest('build/css')); 20});
Currently, the easiest way to have a single property ignored is to use a capital in the pixel unit declaration.
1// `px` is converted to `rem` 2.convert { 3 font-size: 16px; // converted to 1rem 4} 5 6// `Px` or `PX` is ignored by `postcss-transform` but still accepted by browsers 7.ignore { 8 border: 1Px solid; // ignored 9 border-width: 2PX; // ignored 10}
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
3 existing vulnerabilities detected
Details
Reason
Found 0/8 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-05-12
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More