0.1.2 • Published 10 years ago

css-mediaquery v0.1.2

Weekly downloads
476,192
License
-
Repository
github
Last release
10 years ago

CSS Media Query

Build Status Dependency Status npm Version

Parses and determines if a given CSS Media Query matches a set of values via JavaScript.

Installation

Install via npm:

$ npm install css-mediaquery

Usage

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.

Matching

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".

Parsing

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.

License

This software is free to use under the Yahoo! Inc. BSD license. See the LICENSE file for license text and copyright information.

@mochilabs/ra-ui-materialui@travelshift/web@fela-next/fela-plugin-native-media-queryrn-media-queryjinnireact-native-web-stylesonesize-css@infinitebrahmanuniverse/nolb-css-m@postmates/frontend-utils@wavemaker/app-rn-runtime@everything-registry/sub-chunk-1420@ygorconfig/open-props@ygorconfig/stylex@dynatrace/strato-components-preview@expo/match-media@hokify/penthouse@jfkz/tailwind-rn@flexis/srcset@kampaay/ra-ui-materialui@kdh/client@micimize/material-ui@micromag/core@meese-os/client@mkven/ra-conditions@panneau/core@pochta/ui@react-native-extra/match-media@react-native-extra/match-media-polyfill@roadmanfong/expo-match-media@napred/native@funya._./css-to-react-native-transform@gechiui/block-editor@farfetch/react-context-responsive@opengeoweb/spaceweather@osjs/client@nds_core/nds@raymondwang/mock-match-media@ray-js/css-to-react-native@raarts/react-native-extended-stylesheet@rabex-kit/core@ramirezcgn/react-context-responsive@oreact/core@stylexjs/open-props@stylexjs/stylex@storipress/stylelint-plugin-block@telus-uds/components-base@jamsch/nativewind@joseaburt/del-components@joseaburt/mui-v5-react-table-manager@startupjs/css-to-react-native-transform@specfocus/view-focus.muijsdom-testing-mocks@tarik02/penthouse@sbf/fairplay-utils@seasons/ra-ui-materialuilumen-cms-basemedia-query-splitting-pluginmatchmediamatchmediaquerymetnotimeseriesangular-container-media-querymq-removemq4-hover-hover-shimno-media-queriesactbasepocket-penthousecompare-media-queriesra-ui-materialuipenthousebud-wp-editor-querybrowser-xbrianzafpostcss-ie8postcssifypostcss-mobile-only-mqspostcss-mq-dedupepostcss-media-query-filterpostcss-mobile-viewportunitspostcss-unmqpostcss-remove-media-query-rangespostcss-react-native@xcube/build-template@xcube/cube-build-templatemock-match-mediamobilizerwhitenose-projectresponsive-stylesheetrework-plugin-unmqreact-native-media-queryreact-native-nativewindreact-native-responsive-stylereact-native-match-mediareact-native-match-media-polyfillreact-native-match-media-polyfill1darmody-css-to-react-native-transformdp-taro-css-to-react-nativereact-strict-dommv-tmp-ui-materialui@vizual/styled-components-test-utilsmatch-media-mock
0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.0

10 years ago