string2mediaquery

1.0.1 • Public • Published

String2MediaQuery Build Status

Install

$ npm install --save String2MediaQuery

Usage

var mq = String2MediaQuery('>=mobile', {mobile: '320px'});
//=> (min-width: 320px)
 
var mq = String2MediaQuery('>=mobile <1024px', {mobile: '320px'});
//=> (min-width: 320px) and (max-width: 1023px)
 
// The result can then be used with window.matchMedia like this.
if (window.matchMedia(mq).matches) {
  // ...
}
 

API

String2MediaQuery(query, breakpoints)

query

Required Type: string

The simplified query as text.

breakpoints

Type: object Default: {}

Named breakpoints can be passed as an object with names and with as string with pixel units. ex: {mobile: "320px", desktop: "960px"}

This is expecially useful if you are importing css breakpoints.

License

MIT © David Mignot

Package Sidebar

Install

npm i string2mediaquery

Weekly Downloads

1

Version

1.0.1

License

MIT

Last publish

Collaborators

  • idflood