1.0.1 • Published 9 years ago

string2mediaquery v1.0.1

Weekly downloads
3
License
MIT
Repository
github
Last release
9 years ago

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