{"id":11179,"library":"json2mq","title":"JSON to Media Query String Converter","description":"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.","status":"abandoned","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/akiran/json2mq","tags":["javascript"],"install":[{"cmd":"npm install json2mq","lang":"bash","label":"npm"},{"cmd":"yarn add json2mq","lang":"bash","label":"yarn"},{"cmd":"pnpm add json2mq","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for string manipulations and camel case conversion.","package":"string-convert","optional":false}],"imports":[{"note":"This package is CommonJS-only and does not support ES module `import` syntax. It was last published over a decade ago.","wrong":"import json2mq from 'json2mq';","symbol":"json2mq","correct":"const json2mq = require('json2mq');"},{"note":"The default export is the function itself, and it is not a named export. It's only available via `require`.","wrong":"import { json2mq } from 'json2mq';","symbol":"json2mq","correct":"const json2mq = require('json2mq');\njson2mq({minWidth: 100});"}],"quickstart":{"code":"const json2mq = require('json2mq');\n\n// Basic media query\nconsole.log(json2mq({ minWidth: 768 }));\n// Expected: '(min-width: 768px)'\n\n// Complex query with multiple features and units\nconsole.log(json2mq({ screen: true, minWidth: 1024, maxWidth: '120em', orientation: 'landscape' }));\n// Expected: 'screen and (min-width: 1024px) and (max-width: 120em) and (orientation: landscape)'\n\n// Multiple distinct media queries in an array\nconsole.log(json2mq([\n  { screen: true, minWidth: 100 },\n  { handheld: true, orientation: 'landscape' }\n]));\n// Expected: 'screen and (min-width: 100px), handheld and (orientation: landscape)'","lang":"javascript","description":"Demonstrates how to import json2mq and generate various CSS media query strings from simple to complex JSON objects."},"warnings":[{"fix":"Consider migrating to a more modern and actively maintained library, or implement the media query string generation logic manually.","message":"This package is abandoned. The latest version (0.2.0) was published 11 years ago and there have been no updates or security patches since. Using it in modern applications may introduce compatibility issues or security vulnerabilities.","severity":"breaking","affected_versions":">=0.2.0"},{"fix":"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.","message":"The package is CommonJS-only (`require()`) and does not support ES Modules (`import`). This means it cannot be directly imported into modern Node.js or browser projects that use ESM without a compatibility layer or bundler configuration.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"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.","message":"There are no TypeScript type definitions available for this package, either bundled or on DefinitelyTyped. This will result in a poor developer experience for TypeScript users, requiring manual declaration files (`.d.ts`) or `@ts-ignore` directives.","severity":"gotcha","affected_versions":">=0.2.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"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.","cause":"Attempting to use `require()` in an ES module environment (e.g., a Node.js project with `\"type\": \"module\"` in package.json or a `.mjs` file).","error":"ReferenceError: require is not defined in ES module scope"},{"fix":"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.","cause":"Incorrectly attempting to import the default CommonJS export of `json2mq` as a named or default ES module import that does not align with how bundlers might transpile it, especially when `esModuleInterop` is not configured or the environment is pure ESM.","error":"TypeError: (0, _json2mq.default) is not a function"}],"ecosystem":"npm"}