![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
media-query-parser
Advanced tools
media-query-parser
This package's v3 (currently in beta) involves a complete overhaul from v2 to a more sustainable shape. See v2 API docs instead
(100px < width < 200px)
This repo/package contains only the parser, stringify and isParserError.
media-query-fns
uses this library internally to achieve common use-cases.
Other CSS parsers (e.g. css-tree and postcss) do not support all media query syntax out of the box.
Further, the only other media query parser that I'm aware of is postcss-media-query-parser
- which
is specific to postcss and doesn't parse newer syntax like range expressions (i.e.
(width >= 768px)
).
This package is a spec-compliant media query parser that can be used in Node/Deno/etc, or on the client that precisely matches the spec right down to the quirks.
These are valid media queries that this library supports:
@media (768px <= width < 1200px);
@media only print and (color);
@media not (not (not (((hover) or ((not (color)))))));
@media (🐈: 😸 /* if cat happy */) {
/* this query has valid syntax, but is clearly not a real feature.
(see `media-query-fns` for feature checking) */
}
These are invalid media queries that this library will detect:
@media (color) or (hover); /* or cannot be at top level */
@media (min-width: calc(50vw + 10px)); /* functions aren't valid values */
@media not((color)); /* operators need whitespace */
@media (768px < = width < 1200px); /* cannot have a space between `<` and `=` */
This package is available from the npm
registry.
npm install media-query-parser
The shape of Errors are
Supports JavaScript + TypeScript:
import { parseMediaQuery } from "media-query-parser";
const mediaQuery = parseMediaQuery("screen and (min-width: 768px)");
if (!isParserError(mediaQuery)) {
console.log(mediaQuery);
// {
// type: "query",
// mediaType: "screen",
// mediaCondition: {
// type: "condition",
// children: [{
// type: "feature",
// context: "value",
// prefix: "min",
// feature: "width",
// value: {
// type: "dimension", value: 768, unit: "px", flag: "number"
// },
// }],
// },
// }
console.log(stringify(mediaQuery.mediaCondition.children[0]));
// "(min-width: 768px)"
}
Can also be imported via require("media-query-parser")
.
Dev environment (for contributing) requires:
MIT
FAQs
Parse CSS media queries (spec-compliant)
The npm package media-query-parser receives a total of 0 weekly downloads. As such, media-query-parser popularity was classified as not popular.
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
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.