Gathering detailed insights and metrics for postcss-convert-unit
Gathering detailed insights and metrics for postcss-convert-unit
Gathering detailed insights and metrics for postcss-convert-unit
Gathering detailed insights and metrics for postcss-convert-unit
postcss-px-to-relative-unit
A postcss plugin to convert px to relative length units (vw / rem)
postcss-unit-convert
fork from [postcss-px-to-viewport](https://github.com/evrone/postcss-px-to-viewport) because the npm packages is old.
postcss-unit-converter
PostCSS plugin that provides a function to convert CSS values from one unit to another.
@flatjs/forge-plugin-postcss-pixel
the flatjs plugin to convert pixel unit to rem/rpx
npm install postcss-convert-unit
Typescript
Module System
Min. Node Version
Node Version
NPM Version
70
Supply Chain
97.8
Quality
75.1
Maintenance
50
Vulnerability
100
License
CSS (57.66%)
JavaScript (42.34%)
Total Downloads
10,106
Last Day
1
Last Week
72
Last Month
323
Last Year
1,338
MIT License
1 Stars
14 Commits
1 Watchers
16 Branches
1 Contributors
Updated on Sep 19, 2022
Minified
Minified + Gzipped
Latest Version
0.1.3
Package Id
postcss-convert-unit@0.1.3
Unpacked Size
42.31 kB
Size
7.82 kB
File Count
8
NPM Version
6.4.1
Node Version
10.12.0
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-46.3%
72
Compared to previous week
Last Month
43.6%
323
Compared to previous month
Last Year
-54.7%
1,338
Compared to previous year
Convert values and units in css through custom conversion rules. A new selector can be generated for the converted property.
1npm install postcss-convert-unit --save-dev
postcss config:
1// postcss.config.js 2module.exports = { 3 plugins: { 4 "postcss-convert-units": { 5 convertConfig: [ 6 { 7 declMatcher: { 8 sourceUnit: 'px', 9 targetUnit: 'rem' 10 }, 11 declConvertRules: [{ 12 value: value => value 13 }] 14 } 15 ] 16 } 17 } 18};
input:
1.div { 2 padding: 20px 0 10px 5em; 3}
output:
1.div { 2 padding: 20rem 0 10rem 5em; 3}
postcss config:
1// postcss.config.js 2module.exports = { 3 plugins: { 4 "postcss-convert-units": { 5 convertConfig: [ 6 { 7 declMatcher: { 8 sourceUnit: 'px', 9 targetUnit: 'rem' 10 }, 11 declConvertRules: [ 12 { 13 value: value => value / 75 14 } 15 ] 16 }, 17 { 18 declMatcher: { 19 sourceUnit: 'px', 20 targetUnit: 'px', 21 afterDeclComment: 'px' 22 }, 23 removeMatchDecl: true, 24 declConvertRules: [ 25 { 26 withNewSelector: selector => `[data-dpr="1"] ${selector}`, 27 value: value => value / 2 28 }, 29 { 30 withNewSelector: selector => `[data-dpr="2"] ${selector}`, 31 value: value => value 32 }, 33 { 34 withNewSelector: selector => `[data-dpr="3"] ${selector}`, 35 value: value => value / 2 * 3 36 } 37 ] 38 } 39 ] 40 } 41 } 42};
input:
1.selector { 2 height: 64px; /*px*/ 3 font-size: 28px; /*px*/ 4 border: 1px solid #ddd; /*no*/ 5 width: 150px; 6} 7
output:
1.selector { 2 border: 1px solid #ddd; /*no*/ 3 width: 2rem; 4} 5[data-dpr="1"] .selector { 6 height: 32px; 7 font-size: 14px; 8} 9[data-dpr="2"] .selector { 10 height: 64px; 11 font-size: 28px; 12} 13[data-dpr="3"] .selector { 14 height: 96px; 15 font-size: 42px; 16} 17
1// example 2{ 3 convertConfig: [ 4 { 5 declMatcher: { 6 sourceUnit: 'px', 7 targetUnit: 'rem', 8 afterDeclComment: 'rem' 9 }, 10 precision: 5, 11 removeMatchDecl: false, 12 declConvertRules: [ 13 { 14 value: value => value, 15 withNewSelector: selector => selector 16 } 17 ] 18 } 19 ] 20}
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
convertConfig | convert config list | convertItem[] | [] | yes |
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
declMatcher | match declaration | string | - | yes |
declConvertRules | declaration convert rules | convertRule[] | - | yes |
precision | value precision | number | 5 | no |
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
sourceUnit | source unit | string | - | yes |
targetUnit | target unit | string | - | yes |
afterDeclComment | comment after declaration | string | - | no |
notice: If set withNewSelector
, a new selector will be generated for the converted declaration; if not set withNewSelector
, values and units will converted in origin declaration. for @keyframes, it will converted in origin declaration. If multiple convertRules
are configured, the last configuration will take effect, because the post configuration will override the first configuration.
Attribute | Description | Type | Default | Required |
---|---|---|---|---|
value | value convert rule | function(value),value is matched value,you need implement convert rule,and return converted value | - | yes |
withNewSelector | new selector generated rule | function(selector), selector is matched selector,you need implement convert rule,and return new selector | - | no |
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/14 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
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
branch protection not enabled on development/release branches
Details
Reason
50 existing vulnerabilities detected
Details
Score
Last Scanned on 2025-06-30
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