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.
npm install json2mqVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to import json2mq and generate various CSS media query strings from simple to complex JSON objects.
Consider migrating to a more modern and actively maintained library, or implement the media query string generation logic manually.
For ESM projects, use `import json2mq from 'json2mq'` with a bundler (like Webpack or Rollup) configured to handle CJS modules, or use `module.createRequire` in Node.js for explicit CJS loading. Alternatively, find an ESM-native alternative.
If TypeScript types are critical, consider creating a `json2mq.d.ts` file with `declare module 'json2mq' { function json2mq(obj: any): string; export = json2mq; }` or seeking an alternative package with native TypeScript support.If within Node.js ESM, use `const createRequire = require('module').createRequire; const requireLocal = createRequire(import.meta.url); const json2mq = requireLocal('json2mq');`. For browser environments or bundled ESM, ensure your bundler is configured to handle CommonJS modules.If using a bundler (like Webpack, Rollup), ensure it's correctly configured to handle CommonJS modules and their default exports. If in Node.js ESM, use the `createRequire` approach. Otherwise, the package might not be compatible with your setup.