{"id":19301596,"url":"https://github.com/b2ns/postcss-unit","last_synced_at":"2025-07-17T03:36:20.915Z","repository":{"id":57328597,"uuid":"164048292","full_name":"b2ns/postcss-unit","owner":"b2ns","description":"a postcss plugin which convert any css unit","archived":false,"fork":false,"pushed_at":"2019-01-07T15:42:11.000Z","size":4,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T16:50:48.270Z","etag":null,"topics":["em","postcss-plugin","px","rpx","unit","vw"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/b2ns.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-01-04T02:38:27.000Z","updated_at":"2019-01-09T02:03:12.000Z","dependencies_parsed_at":"2022-09-05T19:50:14.664Z","dependency_job_id":null,"html_url":"https://github.com/b2ns/postcss-unit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/b2ns/postcss-unit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2ns%2Fpostcss-unit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2ns%2Fpostcss-unit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2ns%2Fpostcss-unit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2ns%2Fpostcss-unit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b2ns","download_url":"https://codeload.github.com/b2ns/postcss-unit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b2ns%2Fpostcss-unit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265563110,"owners_count":23788645,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["em","postcss-plugin","px","rpx","unit","vw"],"created_at":"2024-11-09T23:18:28.775Z","updated_at":"2025-07-17T03:36:20.895Z","avatar_url":"https://github.com/b2ns.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postcss-unit\n\nUnlike other postcss plugins only dealing with specific unit (px2rem, px2vw, px2rpx, ...), this one convert **any unit** in css as long as you provide *the convert funtcion* !!!\n\n## Install\n\n```shell\n$ npm install postcss-unit --save-dev\n```\n\n## Usage\n\nLike all other postcss plugins, you may use it with Webpack, Gulp, Grunt or other workflow, please refer [this](https://github.com/postcss/postcss)\n\n## Example\n\n### Default options\n\n```javascript\n// with default options\n{\n    from: 'px',\n    to: 'rpx',\n    convert: num =\u003e num, // function to convert the matched number\n    precision: 3, // negative (-1) to leave the number as it is\n    minValue: 0, // number not less than this will be converted\n    mediaQuery: false,  // enable conversion in @media query\n    propWhiteList: [], // string or regexp\n    selectorBlackList: [] // string or regexp\n}\n\n```\n\n```css\n/* input */\n.border-bottom {\n    padding: 0 20px;\n    border-bottom: 1px solid;\n}\n\n/* output */\n.border-bottom {\n    padding: 0 20rpx;\n    border-bottom: 1rpx solid;\n}\n```\n\n### Multi options\n\n\n```javascript\n// give an array of optins to do multi convert at the same time\n[{\n    from: 'px',\n    to: 'vw',\n    convert: num =\u003e num / 7.5,\n    precision: 5,\n    minValue: 1,\n    mediaQuery: true,\n    selectorBlackList: ['.ignore']\n}, {\n    from: 'em',\n    to: 'rem',\n    precision: -1,\n    propWhiteList: [/font-.*/gi],\n}, {\n    from: 'cm',\n    to: 'mm',\n    convert: num =\u003e num * 10\n}]\n```\n\n```css\n/* input */\n@media screen and (max-width: 768px) {\n    h1 {\n        height: 10em;\n        margin: 20cm 100mm;\n        padding: 5px 1px;\n        font-size: 1.5em;\n        line-height: 1.25;\n    }\n    body .ignore h2 {\n        padding: 5px 1px;\n    }\n}\n\n/* output */\n@media screen and (max-width: 102.40000vw) {\n    h1 {\n        height: 10em;\n        margin: 200mm 100mm;\n        padding: 0.66667vw 1px;\n        font-size: 1.5rem;\n        line-height: 1.25;\n    }\n    body .ignore h2 {\n        padding: 5px 1px;\n    }\n}\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2ns%2Fpostcss-unit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb2ns%2Fpostcss-unit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb2ns%2Fpostcss-unit/lists"}