JSON to Media Query String Converter

0.2.0 · abandoned · verified Sun Apr 19

json2mq is a JavaScript utility that translates plain JavaScript objects or JSON structures into valid CSS media query strings. Its current and only stable version is 0.2.0, which was published over eleven years ago, signifying that the package is no longer actively maintained or developed. The library automatically appends 'px' to numeric dimension values, handles various media types (e.g., 'screen', 'handheld'), and supports negations. A key differentiator is its straightforward, declarative input format for generating potentially complex CSS media query syntax, including support for multiple queries via an array of objects. Due to its age, it predates modern JavaScript module systems and TypeScript integration.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to import json2mq and generate various CSS media query strings from simple to complex JSON objects.

const json2mq = require('json2mq');

// Basic media query
console.log(json2mq({ minWidth: 768 }));
// Expected: '(min-width: 768px)'

// Complex query with multiple features and units
console.log(json2mq({ screen: true, minWidth: 1024, maxWidth: '120em', orientation: 'landscape' }));
// Expected: 'screen and (min-width: 1024px) and (max-width: 120em) and (orientation: landscape)'

// Multiple distinct media queries in an array
console.log(json2mq([
  { screen: true, minWidth: 100 },
  { handheld: true, orientation: 'landscape' }
]));
// Expected: 'screen and (min-width: 100px), handheld and (orientation: landscape)'

view raw JSON →