Socket
Socket
Sign inDemoInstall

sort-css-media-queries

Package Overview
Dependencies
0
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.1.1

147

index.js

@@ -1,3 +0,1 @@

'use strict';
/**

@@ -11,6 +9,11 @@ * The custom `sort` method for

* @author Oleg Dutchenko <dutchenko.o.wezom@gmail.com>
* @version 1.0.0
* @sourcecode |+16
* @version 1.1.1
*/
'use strict';
// ----------------------------------------
// Private
// ----------------------------------------
const minMaxWidth = /(!?\(\s*min(-device-)?-width).+\(\s*max(-device)?-width/;

@@ -33,65 +36,2 @@ const minWidth = /\(\s*min(-device)?-width/;

/**
* Sorting an array with media queries
* @param {string} a
* @param {string} b
* @return {number} 1 / 0 / -1
* @sourcecode
*/
module.exports = function (a, b) {
let minA = isMinWidth(a) || isMinHeight(a);
let maxA = isMaxWidth(a) || isMaxHeight(a);
let minB = isMinWidth(b) || isMinHeight(b);
let maxB = isMaxWidth(b) || isMaxHeight(b);
if (minA && maxB) {
return -1;
}
if (maxA && minB) {
return 1;
}
let lengthA = getQueryLength(a);
let lengthB = getQueryLength(b);
if (lengthA > lengthB) {
if (maxA) {
return -1;
}
return 1;
}
if (lengthA < lengthB) {
if (maxA) {
return 1;
}
return -1;
}
return a.localeCompare(b);
};
/**
* Wrapper for creating test functions
* @private
* @param {RegExp} doubleTestTrue
* @param {RegExp} doubleTestFalse
* @param {RegExp} singleTest
* @return {Function}
* @sourcecode
*/
function testQuery (doubleTestTrue, doubleTestFalse, singleTest) {
/**
* @param {string} query
* @return {boolean}
*/
return function(query) {
if ( doubleTestTrue.test(query) ) {
return true;
} else if ( doubleTestFalse.test(query) ) {
return false;
}
return singleTest.test(query);
}
}
/**
* Obtain the length of the media request in pixels.

@@ -103,3 +43,3 @@ * Copy from original source `function inspectLength (length)`

* @return {number}
* @sourcecode
* @sourceCode
*/

@@ -136,2 +76,71 @@ function getQueryLength (length) {

return num;
}
}
/**
* Wrapper for creating test functions
* @private
* @param {RegExp} doubleTestTrue
* @param {RegExp} doubleTestFalse
* @param {RegExp} singleTest
* @return {Function}
* @sourceCode
*/
function testQuery (doubleTestTrue, doubleTestFalse, singleTest) {
/**
* @param {string} query
* @return {boolean}
*/
return function(query) {
if ( doubleTestTrue.test(query) ) {
return true;
} else if ( doubleTestFalse.test(query) ) {
return false;
}
return singleTest.test(query);
}
}
// ----------------------------------------
// Exports
// ----------------------------------------
/**
* Sorting an array with media queries
* @param {string} a
* @param {string} b
* @return {number} 1 / 0 / -1
* @sourceCode
*/
module.exports = function (a, b) {
let minA = isMinWidth(a) || isMinHeight(a);
let maxA = isMaxWidth(a) || isMaxHeight(a);
let minB = isMinWidth(b) || isMinHeight(b);
let maxB = isMaxWidth(b) || isMaxHeight(b);
if (minA && maxB) {
return -1;
}
if (maxA && minB) {
return 1;
}
let lengthA = getQueryLength(a);
let lengthB = getQueryLength(b);
if (lengthA > lengthB) {
if (maxA) {
return -1;
}
return 1;
}
if (lengthA < lengthB) {
if (maxA) {
return 1;
}
return -1;
}
return a.localeCompare(b);
};
{
"name": "sort-css-media-queries",
"version": "1.1.0",
"version": "1.1.1",
"description": "The custom `sort` method for `css-mqpacker` or `pleeease` (which uses css-mqpacker) or, perhaps, something else ))",

@@ -5,0 +5,0 @@ "main": "index.js",

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