Socket
Socket
Sign inDemoInstall

media-query-fns

Package Overview
Dependencies
1
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    media-query-fns

Useful functions for working with CSS media queries in JS/TS


Version published
Weekly downloads
2.9K
decreased by-15.51%
Maintainers
1
Install size
118 kB
Created
Weekly downloads
 

Readme

Source

media-query-fns

npm npm type definitions license npm downloads install size

Cool functions for media queries. Spec-compliant.


Install

This package is available from the npm registry.

npm install media-query-fns

Usage

Supports JavaScript + TypeScript:

import { compileQuery, matches, toEnglishString } from "media-query-fns";

// returns data that can be used to interpret the query
const maxWidthQuery = compileQuery(`(max-width: 1200px)`);
// (throws if invalid query syntax)

const testEnv = (widthPx = 1280, heightPx = 800) => ({
  widthPx,
  heightPx,
  deviceWidthPx: widthPx,
  deviceHeightPx: heightPx,
  dppx: 2,
});
console.log(matches(maxWidthQuery, testEnv(1280))); // false
console.log(matches(maxWidthQuery, testEnv(1000))); // true

const complexQuery = compileQuery(`screen and (monochrome) and (orientation)`);
console.log(matches(complexQuery, testEnv()));
// true

console.log(toEnglishString(maxWidthQuery));
// 'if width ≤ 1200px'
console.log(toEnglishString(complexQuery));
// 'if (is screen AND monochrome)'
// note: (orientation) without "landscape" or "portrait" is always true, so it's removed for brevity

Can also be imported via require("media-query-fns").

Contributing

  • PRs welcome and accepted, simply fork and create
  • Issues also very welcome
  • Treat others with common courtesy and respect 🤝

Dev environment (for contributing) requires:

  • node >= 16.14.0
  • npm >= 6.8.0
  • git >= 2.11

Licence

MIT

Keywords

FAQs

Last updated on 13 Jun 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc