New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

compare-media-queries

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

compare-media-queries

Opinionated function to compare media queries

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

compare-media-queries

Opinionated sorting function. Originaly made to be used in mqpacker sort function.

This function evaluates only first media query. It can't compare additional queries separated by comma.

Warning: You have to take into account that sorting media queries in CSS can produce unintended results.

Usage

import compare from 'compare-media-queries';

compare(a, b, options);

Returns numbers as required by Array.prototype.sort().

Parameters

ParameterTypeDescription
astringrequired First media query
bstringrequired Second media query
optionsobjectOptions

Options

Function uses two objects to evaluate weight of media query.

weights

Object containing weights for different parts of media query. You can efectively change sorting rules by providing different weights.

Defaults:

const defaultWeights = {
    types: {
        all: 1000,
        screen: 2000,
        print: 3000,
        unknown: 9000
    },
    modifiers: {
        min: 100,
        max: 200,
        unknown: 900
    },
    features: {
        blank: 10,
        width: 20,
        height: 30,
        resolution: 40,
        unknown: 90
    }
}

unknown is used for every unknown rule

units

units are used for value conversion. For example 10px will became 10, 10em will became 160 etc.

You can provide rules for unknown units.

Defaults:

const defaultUnits = {
    ch: 8.8984375,
    em: 16, 
    rem: 16,
    ex: 8.296875,
    px: 1,
    dppx: 1,
    dpi: 1
}

Rules

Default weights are for mobile-first sorting and are calculated based on following order

  • Media types: all | unspecified, screen, print, other types
  • Modifiers: min, max
  • Features: width, height, resolution, other
  • Values: ascending order

If specifity is same for both queries, values are compared. If modifier max is used, values are sorted in descending order.

Keywords

FAQs

Package last updated on 13 Feb 2017

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc