npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

postcss-reverse-media

v0.1.2

Published

Reverse media query parameters. Equivalent to a `not` if the native syntax allowed. Useful to avoid media query overlap.

Downloads

81

Readme

npm version Build Status

PostCSS Reverse Media

Reverse media query parameters. Equivalent to a not if the native syntax allowed. Useful to avoid media query overlap.

Wait, I thought media queries had not and logic already?

Unfortunately the not all trick doesn't work when you want to chain(and) another parameter.

  • This works to reverse/invert/not the media query parameter:
    • @media not all and (max-width: 250px)
  • When you want to chain, this doesn't work:
    • @media (max-width: 500px) and not all and (max-width: 250px)

I created this plugin so that this kind of thing is easy to do. I prefer to to use the reverse keyword(to avoid confusion and collision in the future) but feel free to change it to not in the options.

  • With postcss-reverse-media: -@media (max-width: 500px) and reverse (max-width: 250px)

More info about media query logic in this article, Logic in Media Queries on CSS-Tricks

Latest Version: v0.1.2

Changelog

Install

npm install postcss-reverse-media --save-dev

Usage

Basic Example

var postcss = require('postcss');
var reverseMedia = require('postcss-reverse-media');

var fs = require('fs');

var mycss = fs.readFileSync('input.css', 'utf8');

// Process your CSS with postcss-reverse-media
var output = postcss([
        reverseMedia(/*options*/)
    ])
    .process(mycss)
    .css;

console.log(output);

Input:

@media reverse (max-width: 150px) { /*...*/ }

@media reverse (min-width: 150px) { /*...*/ }

Output:

@media (min-width: 150.001px) { /*...*/ }

@media (max-width: 149.999px) { /*...*/ }

Chaining parameters with logic

Input:

@media (max-width: 300px) and reverse (max-width: 150px) { /*...*/ }

@media (min-width: 50px) and reverse (min-width: 150px) { /*...*/ }

Output:

@media (max-width: 300px) and (min-width: 150.001px) { /*...*/ }

@media (min-width: 50px) and (max-width: 149.999px) { /*...*/ }

Use with other plugins that modify @media

Put postcss-reverse-media after other plugins that modify @media rules. This is to have all of the substitutions and transformations complete before we look for the reverse qualifier keyword and do our transformations.

var customMedia = require('postcss-custom-media');
var minmax = require('postcss-media-minmax');
var reverseMedia = require('postcss-reverse-media');

var pluginStack = [
	customMedia(),
	minmax(),
	reverseMedia()
];
@custom-media --small-viewport (max-width: 150px);

@media reverse (--small-viewport) { /*...*/ }

Options

  • keyword: string - The media query param reversal operator keyword.
    • Default: 'reverse'
  • increment: number - The ammount we increment/decrement by to avoid parameter overlap
    • Default: 0.001

Testing

npm test