Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Turns human readable breakpoints into correct mediaqueries.
This is particularly useful when working with window.matchMedia or when you work with CSS dinamically using JavaScript.
If you are using nodejs (but also browserify, webpack, etc...) you can simply use npm:
npm install mediaquery
then you can
var MQ = require('mediaquery');
By the way you if you are not using node, you may use bower
bower install mediaquery
then you can use it from window.MQ
or require it using AMD
Assuming you have an object to describe the mediaqueries you need such as
var myMedias = {
small: 300,
medium: 600,
tablet: 'tablet media query',
big: 1024,
huge: Infinity
};
Note that all the numerical values (Infinity included) will be automatically sorted in the correct order, while all the strings will be considered custome media queries; every other type of values will be stripped out.
So small: 300
means that my small
media query will span from 0 to 300px,
while medium
will be from 301px to 600px; finally huge
will go from 1025px
to... Infinitely large screens.
If you do not specify an Infinity breakpoint a default
breakpoint will be
created spanning from the biggest available breakpoint to infinity.
You can use asObject
to get back a similar object where the numbers for your
breakpoints are substituted with correct mediaqueries.
e.g.
var MQ = require('mediaqueries');
MQ.asObject(myMedias);
will return
{
small: 'screen and (max-width: 300px)',
medium: 'screen and (min-width: 301px) and (max-width: 600px)',
big: 'screen and (min-width: 601px) and (max-width: 1024px)',
huge: 'screen and (min-width: 1025px)',
tablet: 'tablet media query'
}
You can also have an array of couples ['name', 'mediaquery'] in output.
e.g.
MQ.asArray(myMedias);
will return
[
['small', 'screen and (max-width: 300px)'],
['medium', 'screen and (min-width: 301px) and (max-width: 600px)'],
['big', 'screen and (min-width: 601px) and (max-width: 1024px)'],
['huge', 'screen and (min-width: 1025px)'],
['tablet', 'tablet media query']
]
If you need to filter out the numerical breakpoints from a mixed object you can
use getBreakPoints
e.g.
MQ.getBreakPoints(myMedias);
will return
{
small: 300,
medium: 600,
big: 1024,
huge: Infinity // remember that Infinity is a number
}
In the same way you may need to filter out all the custom strings e.g.
MQ.getCustomQueries(myMedias);
will return
{
tablet: 'tablet media query'
}
FAQs
turns human readable breakpoints into correct mediaqueries
We found that mediaquery demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.