Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
css-mediaquery
Advanced tools
Parses and determines if a given CSS Media Query matches a set of values.
The css-mediaquery package is a tool for parsing and evaluating CSS media queries. It is useful for determining if a media query matches a given set of values or for extracting information from media query strings. This can be particularly helpful for server-side rendering, where you might want to match styles to a device's characteristics, or for dynamically adjusting UI components in JavaScript based on media query logic.
Parsing media queries
This feature allows you to parse a CSS media query string into a structured format that can be easily manipulated or evaluated in JavaScript.
const cssMediaQuery = require('css-mediaquery');
const parsedQuery = cssMediaQuery.parse('screen and (min-width: 480px)');
console.log(parsedQuery);
Evaluating media queries
This feature enables you to evaluate whether a media query matches a given set of values, such as the type of device or the viewport width. This is useful for conditionally applying styles or functionality.
const cssMediaQuery = require('css-mediaquery');
const matches = cssMediaQuery.match('screen and (min-width: 480px)', {
type: 'screen',
width: '1024px'
});
console.log(matches); // true or false
Enquire.js is a lightweight, pure JavaScript library for responding to CSS media queries. It is similar to css-mediaquery but is more focused on providing a JavaScript API for responding to media queries in the browser, rather than parsing or evaluating them in a general context.
This package is similar to css-mediaquery in that it allows you to evaluate media queries in JavaScript. However, matchmediaquery is designed to mimic the window.matchMedia API found in browsers, providing a polyfill for environments where matchMedia is not available.
json2mq is a package that allows you to generate media query strings from JavaScript objects. While it does not evaluate or parse media queries like css-mediaquery, it provides a complementary functionality that can be useful when constructing media queries dynamically.
Parses and determines if a given CSS Media Query matches a set of values via JavaScript.
Install via npm:
$ npm install css-mediaquery
This package has two exports: parse()
, and match()
which can parse CSS Media
Queries and determine if a media query matches a given set of values.
The match()
method lets you compare a media query expression with a JavaScript
object and determine if a media query matches a given set of values.
var mediaQuery = require('css-mediaquery');
var isMatch = mediaQuery.match('screen and (min-width: 40em)', {
type : 'screen',
width: '1024px'
});
console.log(isMatch); // => true
The values specified to check a media query string against should be thought of
as if they are the current state of a device/browser. A type
value must be
specified, and it can not be "all"
.
Existing CSS Parsers don't do a great job at parsing the details of media
queries. That's where css-mediaquery
shines. You can parse a media query
expression and get an AST back by using the parse()
method.
var mediaQuery = require('css-mediaquery'),
ast = mediaQuery.parse('screen and (min-width: 48em)');
The ast
variable will have the following payload:
[
{
inverse: false,
type : 'screen',
expressions: [
{
modifier: 'min',
feature : 'width',
value : '48em'
}
]
}
]
This package was written with care to following the W3C Recommendations for CSS3 Media Queries and CSS3 Values and Units. It supports all of the Media Features and will properly convert values to a common unit before comparing them.
This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.
FAQs
Parses and determines if a given CSS Media Query matches a set of values.
The npm package css-mediaquery receives a total of 619,799 weekly downloads. As such, css-mediaquery popularity was classified as popular.
We found that css-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
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.