Comparing version 2.3.0 to 2.4.0
@@ -50,4 +50,12 @@ 'use strict'; | ||
var message = features[feature].title + ' not supported by: ' + features[feature].missing + ' (' + feature + ')'; | ||
var messages = []; | ||
if (features[feature].missing) { | ||
messages.push(' not supported by: ' + features[feature].missing); | ||
} | ||
if (features[feature].partial) { | ||
messages.push(' only partially supported by: ' + features[feature].partial); | ||
} | ||
var message = features[feature].title + messages[0] + (messages[1] ? ' and ' + messages[1] : '') + ' (' + feature + ')'; | ||
result.warn(message, { node: usage, plugin: 'doiuse' }); | ||
@@ -54,0 +62,0 @@ |
@@ -11,18 +11,35 @@ 'use strict'; | ||
function filterStats(browsers, stats) { | ||
return _.transform(stats, function (resultStats, versionData, browser) { | ||
// filter only versions of selected browsers that don't support this | ||
// feature (i.e., don't have 'y' in their stats) | ||
var versWithoutSupport = _.transform(versionData, function (result, support, ver) { | ||
return _.reduce(stats, function (resultStats, versionData, browser) { | ||
// filter only versions of selected browsers that don't fully support this feature | ||
var feature = _.reduce(versionData, function (result, support, ver) { | ||
var selected = browsers.test(browser, ver); | ||
if (selected && !/(^|\s)y($|\s)/.test(support)) { | ||
result[selected[1]] = support; | ||
if (selected) { | ||
// check if browser is NOT fully (i.e., don't have 'y' in their stats) supported | ||
if (!/(^|\s)y($|\s)/.test(support)) { | ||
// when it's not partially supported ('a'), it's missing | ||
var testprop = /(^|\s)a($|\s)/.test(support) ? 'partial' : 'missing'; | ||
if (!result[testprop]) { | ||
result[testprop] = {}; | ||
} | ||
result[testprop][selected[1]] = support; | ||
} | ||
} | ||
}); | ||
// filter out browsers for which there are *no* (selected) versions lacking | ||
// support. | ||
if (_.keys(versWithoutSupport).length !== 0) { | ||
resultStats[browser] = versWithoutSupport; | ||
return result; | ||
}, { missing: {}, partial: {} }); | ||
if (_.keys(feature.missing).length !== 0) { | ||
resultStats.missing[browser] = feature.missing; | ||
} | ||
}); | ||
if (_.keys(feature.partial).length !== 0) { | ||
resultStats.partial[browser] = feature.partial; | ||
} | ||
return resultStats; | ||
}, { missing: {}, partial: {} }); | ||
} | ||
function lackingBrowsers(browserStats) { | ||
return _.reduce(browserStats, function (res, versions, browser) { | ||
res.push(formatBrowserName(browser, _.keys(versions))); | ||
return res; | ||
}, []).join(', '); | ||
} | ||
@@ -44,2 +61,7 @@ /** | ||
* } | ||
* partialData: { | ||
* // map of browser -> version -> (partial)support code | ||
* ie: { '7': 'a' }, | ||
* ff: { '29': 'a #1' } | ||
* } | ||
* caniuseData: { | ||
@@ -57,3 +79,2 @@ * // caniuse-db json data for this feature | ||
var browsers = new BrowserSelection(browserRequest); | ||
var result = {}; | ||
@@ -63,17 +84,22 @@ | ||
var featureData = caniuse.data[feature]; | ||
var missingData = filterStats(browsers, featureData.stats); | ||
var lackData = filterStats(browsers, featureData.stats); | ||
var missingData = lackData.missing; | ||
var partialData = lackData.partial; | ||
// browsers with missing or partial support for this feature | ||
var missing = lackingBrowsers(missingData); | ||
var partial = lackingBrowsers(partialData); | ||
// browsers missing support for this feature | ||
var missing = _.reduce(missingData, function (res, versions, browser) { | ||
res.push(formatBrowserName(browser, _.keys(versions))); | ||
return res; | ||
}, []).join(', '); | ||
if (missing.length > 0) { | ||
if (missing.length > 0 || partial.length > 0) { | ||
result[feature] = { | ||
title: featureData.title, | ||
missing: missing, | ||
missingData: missingData, | ||
caniuseData: featureData | ||
}; | ||
if (missing.length > 0) { | ||
result[feature].missingData = missingData; | ||
result[feature].missing = missing; | ||
} | ||
if (partial.length > 0) { | ||
result[feature].partialData = partialData; | ||
result[feature].partial = partial; | ||
} | ||
} | ||
@@ -80,0 +106,0 @@ }); |
{ | ||
"name": "doiuse", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Lint CSS for browser support against caniuse database.", | ||
@@ -36,3 +36,3 @@ "main": "lib/doiuse.js", | ||
"ldjson-stream": "^1.2.1", | ||
"lodash": "^3.5.0", | ||
"lodash": "^4.0.0", | ||
"multimatch": "^2.0.0", | ||
@@ -39,0 +39,0 @@ "postcss": "^5.0.8", |
@@ -120,3 +120,3 @@ [![Build Status](https://travis-ci.org/anandthakker/doiuse.svg?branch=master)](https://travis-ci.org/anandthakker/doiuse) | ||
{ | ||
browsers: ['ie >= 8', '> 1%'] // an autoprefixer-like array of browsers. | ||
browsers: ['ie >= 8', '> 1%'], // an autoprefixer-like array of browsers. | ||
ignore: ['rem'], // an optional array of features to ignore | ||
@@ -123,0 +123,0 @@ ignoreFiles: ['**/normalize.css'], // an optional array of file globs to match against original source file path, to ignore |
@@ -36,20 +36,46 @@ var test = require('tape') | ||
'ie >= 7', | ||
'safari >= 6' | ||
'safari >= 6', | ||
'opera >= 10.1' | ||
]).features | ||
var bgimgopts = data['background-img-opts'] | ||
hasKeys(t, bgimgopts, ['missing', 'title', 'missingData', 'caniuseData']) | ||
hasKeys(t, bgimgopts, ['missing', 'partial', 'title', 'missingData', 'partialData', 'caniuseData']) | ||
var missing = bgimgopts.missingData | ||
hasKeys(t, missing, ['ie', 'safari']) | ||
var partial = bgimgopts.partialData | ||
hasKeys(t, missing, ['ie']) | ||
hasKeys(t, missing.ie, ['7', '8']) | ||
hasKeys(t, missing.safari, ['6', '6.1']) | ||
hasKeys(t, partial, ['safari', 'opera']) | ||
hasKeys(t, partial.safari, ['6', '6.1']) | ||
hasKeys(t, partial.opera, ['10.0-10.1']) | ||
t.end() | ||
}) | ||
test('only yields features not supported by selected browser', function (t) { | ||
var data, f, featureData | ||
test('partialData only yields features partially supported by selected browser', function (t) { | ||
var data, f, featureData, p | ||
data = missingSupport(['ie 8']).features | ||
for (f in data) { | ||
featureData = data[f] | ||
var partial = [] | ||
for (p in data) { | ||
if (data[p].partialData) { | ||
partial.push(data[p]) | ||
} | ||
} | ||
for (f in partial) { | ||
featureData = partial[f] | ||
hasKeys(t, featureData.partialData, ['ie']) | ||
} | ||
t.end() | ||
}) | ||
test('missingData only yields features not supported by selected browser', function (t) { | ||
var data, f, featureData, m | ||
data = missingSupport(['ie 8']).features | ||
var missing = [] | ||
for (m in data) { | ||
if (data[m].missingData) { | ||
missing.push(data[m]) | ||
} | ||
} | ||
for (f in missing) { | ||
featureData = missing[f] | ||
hasKeys(t, featureData.missingData, ['ie']) | ||
@@ -56,0 +82,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
67249
1868
+ Addedlodash@4.17.21(transitive)
- Removedlodash@3.10.1(transitive)
Updatedlodash@^4.0.0