css-mq-parser
v0.0.3
Published
Parses CSS media queries
Downloads
5,442
Readme
CSS Media Query Parser
Parses CSS media query expressions.
Installation
Install via npm:
$ npm install css-mq-parser
Usage
This package exports one function, which can parse CSS media query expressions and return an AST.
The parser tolerates several known CSS media query browser hacks, but will throw a SyntaxError
if the media query expression is severely malformed.
Note that this module implements a lax/liberal/non-validating parser; even modulo browser hacks, the fact that it parses a given expression successfully does not guarantee that the expression is valid per the relevant CSS specifications.
var parseMediaQuery = require('css-mq-parser');
var ast = parseMediaQuery('screen and (min-width: 48em)');
The ast
variable will have the following payload:
[
{
"inverse": false,
"preTypeHack": "",
"type": "screen",
"postTypeHack": "",
"expressions": [
{
"modifier": "min",
"feature": "width",
"value": "48em"
}
]
}
]
License & Acknowledgements
This project is a fork of css-mediaquery. This software is free to use under the New/Revised BSD License. See the LICENSE file for license text and copyright information.