Security News
NIST Misses 2024 Deadline to Clear NVD Backlog
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
media-query-parser
Advanced tools
media-query-parser
@media (100px < width < 200px)
import { toAST } from 'media-query-parser'
// Simple responsive media query
console.log(toAST('(max-width: 768px)'))
/* [
{
"mediaPrefix":null,
"mediaType":"all",
"mediaCondition":{
"operator":null,
"children":[
{"context":"value",
"prefix":"max",
"feature":"width",
"value":{"type":"<dimension-token>","value":768,"unit":"px","flag":"number"}
}
]
}
}
] */
// Supports comma separated media-query lists
console.log(toAST('print, (not (color))'))
// Trims the `@media` if it starts with it, the `{` and anything that follows
console.log(toAST('@media screen { body { background: #000 } }'))
// Full support for new range syntax
console.log(toAST('(100px < width < 200px)'))
// ...which was no mean feat...
console.log(toAST('(4/3 <= aspect-ratio <= 16/9)'))
// Throws an Error with invalid media query syntax
console.log(toAST('clearly this is not a valid media query')) // => Error
// ...even the normal looking but invalid ones:
{
console.log(toAST('(max-width: 768px) and screen')) // => Error
// explanation: screen must be on left hand side
console.log(toAST('screen and (max-width: 768px) or (hover)')) // => Error
// explanation: spec disallows `and` and `or` on same level as ambiguous
}
This library does:
(((((max-width: 768px)))))
This library does not:
(max-power: infinite)
is as valid as (hover: none)
(max-width: -100px)
is always
false
)Note that:
npm install media-query-parser --save
# yarn add media-query-parser
Alternatively, there are also client web builds available:
<!-- window.MediaQueryParser -->
<script src="https://unpkg.com/media-query-parser/dist/media-query-parser.umd.js"></script>
API
MIT
FAQs
Parse CSS media queries (spec-compliant)
We found that media-query-parser demonstrated a healthy version release cadence and project activity because the last version was released less than 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
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.