Socket
Socket
Sign inDemoInstall

doiuse

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

doiuse - npm Package Compare versions

Comparing version 0.0.5 to 0.1.0

cli.js

59

dist/index.js

@@ -1,2 +0,2 @@

var Detector, featureData, missingSupport, _;
var Detector, doiuse, featureData, missingSupport, _;

@@ -11,49 +11,24 @@ _ = require('lodash');

/*
Usage: `postcss(doiuse(opts))`.
`opts`:
- `browsers`: an autoprefixer-like array of browsers.
- `onUnsupportedFeatureUse`: `function(usageInfo)`
`usageInfo` looks like this:
```
{
feature: 'css-gradients', //slug identifying a caniuse-db feature
featureData:{
missing: {
// subset of selected browsers that are missing support for this
// particular feature, mapped to the version and (lack of)support code
ie: { '8': 'n' }
},
caniuseData: { // data from caniuse-db/features-json/[feature].json }
},
usage: //the postcss node where that feature is being used.
}
Called once for each usage of each css feature not supported by the selected
browsers.
*/
module.exports = function(_arg) {
var browsers, cb, detector, features, onUnsupportedFeatureUse;
browsers = _arg.browsers, onUnsupportedFeatureUse = _arg.onUnsupportedFeatureUse;
if (browsers == null) {
browsers = [];
doiuse = function(_arg) {
var browserSelection, browsers, cb, detector, features, onUnsupportedFeatureUse, _ref;
browserSelection = _arg.browserSelection, onUnsupportedFeatureUse = _arg.onUnsupportedFeatureUse;
if (browserSelection == null) {
browserSelection = doiuse["default"].slice();
}
cb = onUnsupportedFeatureUse != null ? onUnsupportedFeatureUse : function() {};
features = missingSupport(browsers);
_ref = missingSupport(browserSelection), browsers = _ref.browsers, features = _ref.features;
detector = new Detector(_.keys(features));
return {
info: function() {
return {
browsers: browsers,
features: features
};
},
postcss: function(css) {
return detector.process(css, function(_arg1) {
var browser, feature, loc, message, usage, versions, _i, _len;
var feature, loc, message, usage, _ref1;
feature = _arg1.feature, usage = _arg1.usage;
versions = features[feature].missing;
browsers = [];
for (_i = 0, _len = versions.length; _i < _len; _i++) {
browser = versions[_i];
browsers.push(browser + ' (' + _.keys(versions[browser]).join(',') + ')');
}
loc = usage.source;
message = loc.id + ' line ' + loc.start.line + " : " + feature + ' not supported by ' + browsers.join(',');
message = ((_ref1 = loc.file) != null ? _ref1 : loc.id) + ':' + ' line ' + loc.start.line + ', col ' + loc.start.column + " - " + features[feature].title + ' not supported by: ' + features[feature].missing;
return cb({

@@ -69,1 +44,5 @@ feature: feature,

};
doiuse["default"] = ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1'];
module.exports = doiuse;

@@ -13,3 +13,3 @@ var BrowserSelection, Browsers, browsersData, _;

this.browsers = new Browsers(browsersData, this.browsersRequest);
this.list = this.browsers.selected.map(function(s) {
this._list = this.browsers.selected.map(function(s) {
return s.split(' ');

@@ -24,3 +24,3 @@ });

}
return _.find(this.list, function(_arg) {
return _.find(this._list, function(_arg) {
var b, v;

@@ -32,4 +32,8 @@ b = _arg[0], v = _arg[1];

BrowserSelection.prototype.list = function() {
return this._list.slice();
};
return BrowserSelection;
})();

@@ -1,2 +0,2 @@

var BrowserSelection, features, filterStats, fs, missing, _;
var BrowserSelection, features, filterStats, formatBrowserName, fs, missing, _;

@@ -11,2 +11,4 @@ features = require('../data/features');

formatBrowserName = require('./util').formatBrowserName;
filterStats = function(browsers, stats) {

@@ -37,4 +39,8 @@ return _.transform(stats, function(resultStats, versionData, browser) {

'feature-name': {
missing: {
'ie': '8', // etc.
title: 'Title of feature'
missing: "IE (8), Chrome (31)"
missingData: {
// map of browser -> version -> (lack of)support code
ie: { '8': 'n' },
chrome: { '31': 'n' }
}

@@ -53,3 +59,3 @@ caniuseData: {

missing = function(browserRequest) {
var browsers, data, feature, featureData, json, result;
var browsers, data, feature, featureData, json, missingData, result;
browsers = new BrowserSelection(browserRequest);

@@ -61,10 +67,22 @@ result = {};

featureData = JSON.parse(json);
result[feature] = {
missing: filterStats(browsers, featureData.stats),
caniuseData: featureData
};
missingData = filterStats(browsers, featureData.stats);
missing = _.reduce(missingData, function(res, versions, browser) {
res.push(formatBrowserName(browser, _.keys(versions)));
return res;
}, []).join(', ');
if (missing.length !== 0) {
result[feature] = {
title: featureData.title,
missing: missing,
missingData: missingData,
caniuseData: featureData
};
}
}
return result;
return {
browsers: browsers.list(),
features: result
};
};
module.exports = missing;
{
"name": "doiuse",
"version": "0.0.5",
"version": "0.1.0",
"description": "Lint CSS for browser support against caniuse database.",

@@ -9,2 +9,3 @@ "main": "dist/index.js",

},
"bin": "./cli.js",
"repository": {

@@ -29,6 +30,10 @@ "type": "git",

"caniuse-db": "^1.0.30000023",
"lodash": "^2.4.1"
"concat-stream": "^1.4.6",
"lodash": "^2.4.1",
"postcss": "^3.0.2",
"yargs": "^1.3.3"
},
"devDependencies": {
"coffee-script": "^1.8.0",
"del": "^0.1.3",
"gulp": "^3.8.10",

@@ -35,0 +40,0 @@ "gulp-coffee": "^2.2.0",

@@ -10,2 +10,23 @@ doiuse

# TL;DR
## Command Line
```bash
doiuse --browsers "ie >= 9, > 1%, last 2 versions" main.css
```
**Sample output:**
```
/projects/website/main.css: line 5, col 3 - CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css: line 6, col 3 - CSS3 Box-sizing not supported by: IE (8,9,10,11), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10,11)
/projects/website/main.css: line 8, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 9, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 10, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 11, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 12, col 3 - CSS user-select: none not supported by: IE (8,9)
/projects/website/main.css: line 13, col 3 - Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css: line 14, col 3 - Pointer events not supported by: IE (8,9,10), Firefox (32,33), Chrome (36,37,38), Safari (8,7.1), Opera (24,25), iOS Safari (8,7.1,8.1), Android Browser (4.1,4.4,4.4.4), IE Mobile (10)
/projects/website/main.css: line 32, col 3 - CSS3 Transforms not supported by: IE (8)
```
## JS
```javascript

@@ -29,8 +50,8 @@ var postcss = require('postcss');

- If a feature in that dataset only specifies `properties`, we just use those
properties for substring matches against the properties used in the input CSS.
properties for regex/substring matches against the properties used in the input CSS.
- If a feature also specifies `values`, then we also require that the associated
value matches one of those values (again, with a substring match).
value matches one of those values.
TODO:
- [ ] Selectors and @-rules
- [ ] Support @-rules
- [ ] Allow each feature to have multiple instances of the match criteria laid

@@ -40,3 +61,3 @@ out above, so that different, disjoint (property, value) combinations can

- [ ] Subfeatures, in to allow a slightly looser coupling with caniuse-db's
structure (I'm thinking about the different versions of flexbox.)
structure (for handling, e.g., partial support, the different flexbox versions, etc.)
- [ ] Prefix-aware testing: i.e., pass along a list of prefixes used with a

@@ -50,3 +71,3 @@ given feature. (This is low priority: just use autoprefixer.)

{
browsers: ['ie >= 8', '> 1%'] // an autoprefixer-like array of browsers.
browserSelection: ['ie >= 8', '> 1%'] // an autoprefixer-like array of browsers.
onUnsupportedFeatureUse: function(usageInfo) { } // a callback for usages of features not supported by the selected browsers

@@ -60,7 +81,9 @@ }

{
message: '<input source>: line <l>, col <c> - CSS3 Gradients not supported by: IE (8)'
feature: 'css-gradients', //slug identifying a caniuse-db feature
featureData:{
missing: {
// subset of selected browsers that are missing support for this
// particular feature, mapped to the version and (lack of)support code
title: 'CSS Gradients',
missing: "IE (8)" // string of browsers missing support for this feature.
missingData: {
// map of browser -> version -> (lack of)support code
ie: { '8': 'n' }

@@ -70,3 +93,3 @@ },

},
usage: //the postcss node where that feature is being used.
usage: {} //the postcss node where that feature is being used.
}

@@ -82,2 +105,2 @@ ```

**NOTE:** The files in test/cases are from autoprefixer-core, Copyright 2013 Andrey Sitnik <andrey@sitnik.ru>. Please see https://github.com/postcss/autoprefixer-core.
**NOTE:** Many of the files in test/cases are from autoprefixer-core, Copyright 2013 Andrey Sitnik <andrey@sitnik.ru>. Please see https://github.com/postcss/autoprefixer-core.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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