PostCSS plugin for sorting and combining CSS media queries with mobile-first / desktop-first methodologies.
Installations
npm install postcss-sort-media-queries
Score
95.7
Supply Chain
100
Quality
76.2
Maintenance
100
Vulnerability
100
License
Developer
Developer Guide
Module System
Unable to determine the module system for this package.
Min. Node Version
>=14.0.0
Typescript Support
No
Node Version
18.16.0
NPM Version
9.5.1
Statistics
147 Stars
229 Commits
8 Forks
3 Watching
4 Branches
4 Contributors
Updated on 28 Sept 2024
Bundle Size
3.50 kB
Minified
1.31 kB
Minified + Gzipped
Languages
JavaScript (100%)
Total Downloads
Cumulative downloads
Total Downloads
33,267,007
Last day
-8.3%
58,329
Compared to previous day
Last week
7.2%
327,492
Compared to previous week
Last month
7.7%
1,435,170
Compared to previous month
Last year
55.9%
14,727,548
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
1
PostCSS Sort Media Queries
🌏 English ▫ O'zbek
PostCSS plugin for sorting and combining CSS media queries with mobile first / desktop first methodologies.
From 5.0.0 plugin support Media Feature Types: “range”
Table of Contents
Online demo
And here is the online demo
Examples
Mobile first sorting
before
1@media screen and (max-width: 640px) { 2 .head { color: #cfcfcf } 3} 4@media screen and (max-width: 768px) { 5 .footer { color: #cfcfcf } 6} 7@media screen and (max-width: 640px) { 8 .main { color: #cfcfcf } 9} 10@media screen and (min-width: 1280px) { 11 .mobile-first { color: #cfcfcf } 12} 13@media screen and (width > 640px) { 14 .mobile-first { color: #cfcfcf } 15} 16@media screen and (max-width: 640px) { 17 .footer { color: #cfcfcf } 18}
after
1@media screen and (width > 640px) { 2 .mobile-first { color: #cfcfcf } 3} 4@media screen and (min-width: 1280px) { 5 .mobile-first { color: #cfcfcf } 6} 7@media screen and (max-width: 768px) { 8 .footer { color: #cfcfcf } 9} 10@media screen and (max-width: 640px) { 11 /* combined */ 12 .head { color: #cfcfcf } 13 .main { color: #cfcfcf } 14 .footer { color: #cfcfcf } 15}
Desktop first sorting
before
1@media screen and (width < 640px) { 2 .header { color: #cdcdcd } 3} 4@media screen and (min-width: 760px) { 5 .desktop-first { color: #cdcdcd } 6} 7@media screen and (width < 640px) { 8 .main { color: #cdcdcd } 9} 10@media screen and (min-width: 1280px) { 11 .desktop-first { color: #cdcdcd } 12} 13@media screen and (max-width: 760px) { 14 .footer { color: #cdcdcd } 15} 16@media screen and (max-width: 640px) { 17 .footer { color: #cdcdcd } 18}
after
1@media screen and (max-width: 760px) { 2 .footer { color: #cdcdcd } 3} 4@media screen and (width < 640px) { 5 /* combined */ 6 .header { color: #cdcdcd } 7 .main { color: #cdcdcd } 8 .footer { color: #cdcdcd } 9} 10@media screen and (min-width: 760px) { 11 .desktop-first { color: #cdcdcd } 12} 13@media screen and (min-width: 1280px) { 14 .desktop-first { color: #cdcdcd } 15}
Install
First thing's, install the module:
npm install postcss postcss-sort-media-queries --save-dev
Usage
Check you project for existed PostCSS config: postcss.config.js
in the project root, "postcss"
section in package.json
or postcss
in bundle config.
If you already use PostCSS, add the plugin to plugins list:
1module.exports = { 2 plugins: [ 3+ require('postcss-sort-media-queries')({ 4+ sort: 'mobile-first', // default value 5+ }), 6 require('autoprefixer') 7 ] 8}
or with custom sort function
1module.exports = { 2 plugins: [ 3+ require('postcss-sort-media-queries')({ 4+ sort: function(a, b) { 5+ // custom sorting function 6+ } 7+ }), 8 require('autoprefixer') 9 ] 10}
If you do not use PostCSS, add it according to official docs and set this plugin in settings.
Options
Sorting works based on dutchenkoOleg/sort-css-media-queries function.
sort
This option support string or function values.
{string}
'mobile-first'
- (default) mobile first sorting{string}
'desktop-first'
- desktop first sorting{function}
your own sorting function
'mobile-first'
1postcss([ 2 sortMediaQueries({ 3 sort: 'mobile-first' // default 4 }) 5]).process(css);
'desktop-first'
1postcss([ 2 sortMediaQueries({ 3 sort: 'desktop-first' 4 }) 5]).process(css);
Custom sort function
1postcss([ 2 sortMediaQueries({ 3 function(a, b) { 4 return a.localeCompare(b); 5 } 6 }) 7]).process(css);
In this example, all your media queries will sort by A-Z order.
This sorting function is directly passed to Array#sort() method of an array of all your media queries.
Sort configuration
By this configuration you can control sorting behaviour.
1postcss([ 2 sortMediaQueries({ 3 configuration: { 4 unitlessMqAlwaysFirst: true, // or false 5 } 6 }) 7]).process(css);
Or alternatively create a sort-css-mq.config.json
file in the root of your project. Or add property sortCssMQ: {}
in your package.json
.
Only Top Level
Sort only top level media queries to prevent eject nested media queries from parent node
1postcss([ 2 sortMediaQueries({ 3 onlyTopLevel: true, 4 }) 5]).process(css);
Changelog
See Releases history
License
Other PostCSS plugins
postcss-momentum-scrolling
- plugin for adding momentum style scrolling behavior (-webkit-overflow-scrolling:touch
) for elements with overflow (scroll, auto) on iOS
Thanks
- Andrey Sitnik @ai
- Oleh Dutchenko @dutchenkoOleg
- Jakub Caban @Lustmored
- Dmytro Symonov @Kassaila
- Kai Falkowski @SassNinja
- Khayot Razzakov @Khayotbek1
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/yunusga/postcss-sort-media-queries/test.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:23: update your workflow using https://app.stepsecurity.io/secureworkflow/yunusga/postcss-sort-media-queries/test.yml/main?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
9 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 1/19 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 13 are checked with a SAST tool
Score
2.8
/10
Last Scanned on 2024-11-18
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 MoreOther packages similar to postcss-sort-media-queries
sort-css-media-queries
The custom `sort` method (mobile-first / desktop-first) of CSS media queries for `postcss-sort-media-queries`, `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))
postcss-custom-media
Use Custom Media Queries in CSS
postcss-media-minmax
Using more intuitive `>=`, `<=`, `>`, `<` instead of media queries min/max prefix.
@csstools/postcss-media-queries-aspect-ratio-number-values
Use number values in aspect-ratio media queries.