From ff81c06f48a124ec1221da627760df1d0b31a509 Mon Sep 17 00:00:00 2001 From: Malte Wassermann Date: Sat, 21 Jun 2014 14:38:49 +0200 Subject: [PATCH 1/2] Fixed issue #7 --- index.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 0783e84..7b2af0a 100644 --- a/index.js +++ b/index.js @@ -13,9 +13,10 @@ exports.parse = parseQuery; var RE_MEDIA_QUERY = /^(?:(only|not)?\s*([_a-z][_a-z0-9-]*)|(\([^\)]+\)))(?:\s*and\s*(.*))?$/i, RE_MQ_EXPRESSION = /^\(\s*([_a-z-][_a-z0-9-]*)\s*(?:\:\s*([^\)]+))?\s*\)$/, - RE_MQ_FEATURE = /^(?:(min|max)-)?(.+)/, + RE_MQ_FEATURE = /^(?:-(webkit|moz|o)-)?(?:(min|max)-)?(?:-(moz)-)?(.+)/, RE_LENGTH_UNIT = /(em|rem|px|cm|mm|in|pt|pc)?\s*$/, - RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?\s*$/; + RE_RESOLUTION_UNIT = /(dpi|dpcm|dppx)?\s*$/, + RE_COMMENTS = /\/\*[^*]*\*+([^/][^*]*\*+)*\//gi; function matchQuery(mediaQuery, values) { return parseQuery(mediaQuery).some(function (query) { @@ -86,6 +87,8 @@ function matchQuery(mediaQuery, values) { function parseQuery(mediaQuery) { return mediaQuery.split(',').map(function (query) { + // Remove comments first + query = query.replace(RE_COMMENTS, ''); query = query.trim(); var captures = query.match(RE_MEDIA_QUERY); @@ -128,8 +131,8 @@ function parseQuery(mediaQuery) { var feature = captures[1].toLowerCase().match(RE_MQ_FEATURE); return { - modifier: feature[1], - feature : feature[2], + modifier: feature[2], + feature : feature[4], value : captures[2] }; }); From c48eac5309fe835bb3c57072a67ec5a55b551d85 Mon Sep 17 00:00:00 2001 From: Malte Wassermann Date: Sat, 21 Jun 2014 14:38:59 +0200 Subject: [PATCH 2/2] Fixed issue #10 --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7b2af0a..0166780 100644 --- a/index.js +++ b/index.js @@ -69,8 +69,8 @@ function matchQuery(mediaQuery, values) { case 'color': case 'color-index': case 'monochrome': - expValue = parseInt(expValue, 10) || 1; - value = parseInt(value, 10) || 0; + expValue = !isNaN(expValue) ? parseInt(expValue, 10) : value > 0 ? value : 1; + value = !isNaN(value) ? parseInt(value, 10) : expValue > 0 ? expValue : 0; break; }