mirror of
https://github.com/snachodog/just-the-docs.git
synced 2025-09-13 05:13:33 -06:00
Initial commit
This commit is contained in:
44
node_modules/doiuse/lib/browsers.js
generated
vendored
Normal file
44
node_modules/doiuse/lib/browsers.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// Generated by CoffeeScript 2.0.0-beta8
|
||||
'use strict';
|
||||
|
||||
var _slicedToArray = (function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError('Invalid attempt to destructure non-iterable instance'); } }; })();
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
||||
|
||||
var browserslist = require('browserslist');
|
||||
var _ = require('lodash');
|
||||
module.exports = (function () {
|
||||
function BrowserSelection(query) {
|
||||
_classCallCheck(this, BrowserSelection);
|
||||
|
||||
this.browsersRequest = query;
|
||||
this._list = browserslist(this.browsersRequest).map(function (s) {
|
||||
return s.split(' ');
|
||||
});
|
||||
}
|
||||
|
||||
_createClass(BrowserSelection, [{
|
||||
key: 'test',
|
||||
value: function test(browser, version) {
|
||||
version = version.split('-');
|
||||
if (version.length === 1) version.push(version[0]);
|
||||
return _.find(this._list, function (_ref) {
|
||||
var _ref2 = _slicedToArray(_ref, 2);
|
||||
|
||||
var b = _ref2[0];
|
||||
var v = _ref2[1];
|
||||
|
||||
return b === browser && v >= version[0] && v <= version[1];
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'list',
|
||||
value: function list() {
|
||||
return this._list.slice();
|
||||
}
|
||||
}]);
|
||||
|
||||
return BrowserSelection;
|
||||
})();
|
168
node_modules/doiuse/lib/detect-feature-use.js
generated
vendored
Normal file
168
node_modules/doiuse/lib/detect-feature-use.js
generated
vendored
Normal file
@@ -0,0 +1,168 @@
|
||||
'use strict';
|
||||
|
||||
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
|
||||
|
||||
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; return arr2; } else { return Array.from(arr); } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
|
||||
|
||||
var _ = require('lodash');
|
||||
var features = require('../data/features');
|
||||
|
||||
var PLUGIN_OPTION_COMMENT = 'doiuse-';
|
||||
var DISABLE_FEATURE_COMMENT = PLUGIN_OPTION_COMMENT + 'disable';
|
||||
var ENABLE_FEATURE_COMMENT = PLUGIN_OPTION_COMMENT + 'enable';
|
||||
|
||||
/*
|
||||
* str: string to search in.
|
||||
* searchfor: string or pattern to search for.
|
||||
*/
|
||||
function isFoundIn(str) {
|
||||
str = stripUrls(str);
|
||||
return function find(searchfor) {
|
||||
if (searchfor instanceof RegExp) return searchfor.test(str);else if (_.isFunction(searchfor)) return searchfor(str);else return str && str.indexOf(searchfor) >= 0;
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* Strip the contents of url literals so they aren't matched
|
||||
* by our naive substring matching.
|
||||
*/
|
||||
function stripUrls(str) {
|
||||
return str.replace(/url\([^\)]*\)/g, 'url()');
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect the use of any of a given list of CSS features.
|
||||
* ```
|
||||
* var detector = new Detector(featureList)
|
||||
* detector.process(css, cb)
|
||||
* ```
|
||||
*
|
||||
* `featureList`: an array of feature slugs (see caniuse-db)
|
||||
* `cb`: a callback that gets called for each usage of one of the given features,
|
||||
* called with an argument like:
|
||||
* ```
|
||||
* {
|
||||
* usage: {} // postcss node where usage was found
|
||||
* feature: {} // caniuse-db feature slug
|
||||
* ignore: {} // caniuse-db feature to ignore in current file
|
||||
* }
|
||||
* ```
|
||||
*/
|
||||
module.exports = (function () {
|
||||
function Detector(featureList) {
|
||||
_classCallCheck(this, Detector);
|
||||
|
||||
this.features = _.pick(features, featureList);
|
||||
this.ignore = [];
|
||||
}
|
||||
|
||||
_createClass(Detector, [{
|
||||
key: 'decl',
|
||||
value: function decl(_decl, cb) {
|
||||
for (var feat in this.features) {
|
||||
var properties = this.features[feat].properties || [];
|
||||
var values = this.features[feat].values;
|
||||
if (properties.filter(isFoundIn(_decl.prop)).length > 0) {
|
||||
if (!values || values.filter(isFoundIn(_decl.value)).length > 0) {
|
||||
cb({ usage: _decl, feature: feat, ignore: this.ignore });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'rule',
|
||||
value: function rule(_rule, cb) {
|
||||
for (var feat in this.features) {
|
||||
var selectors = this.features[feat].selectors || [];
|
||||
if (selectors.filter(isFoundIn(_rule.selector)).length > 0) {
|
||||
cb({ usage: _rule, feature: feat, ignore: this.ignore });
|
||||
}
|
||||
}
|
||||
|
||||
this.node(_rule, cb);
|
||||
}
|
||||
}, {
|
||||
key: 'atrule',
|
||||
value: function atrule(_atrule, cb) {
|
||||
for (var feat in this.features) {
|
||||
var atrules = this.features[feat].atrules || [];
|
||||
var params = this.features[feat].params;
|
||||
if (atrules.filter(isFoundIn(_atrule.name)).length > 0) {
|
||||
if (!params || params.filter(isFoundIn(_atrule.params)).length > 0) {
|
||||
cb({ usage: _atrule, feature: feat, ignore: this.ignore });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.node(_atrule, cb);
|
||||
}
|
||||
}, {
|
||||
key: 'comment',
|
||||
value: function comment(_comment, cb) {
|
||||
var text = _comment.text.toLowerCase();
|
||||
|
||||
if (_.startsWith(text, PLUGIN_OPTION_COMMENT)) {
|
||||
var option = text.split(' ', 1)[0];
|
||||
var value = text.replace(option, '').trim();
|
||||
|
||||
switch (option) {
|
||||
case DISABLE_FEATURE_COMMENT:
|
||||
if (value === '') {
|
||||
this.ignore = _.keysIn(this.features);
|
||||
} else {
|
||||
this.ignore = _.uniq([].concat(_toConsumableArray(this.ignore), _toConsumableArray(value.split(',').map(function (feat) {
|
||||
return feat.trim();
|
||||
}))));
|
||||
}
|
||||
break;
|
||||
case ENABLE_FEATURE_COMMENT:
|
||||
if (value === '') {
|
||||
this.ignore = [];
|
||||
} else {
|
||||
this.ignore = _.without.apply(_, [this.ignore].concat(_toConsumableArray(value.split(',').map(function (feat) {
|
||||
return feat.trim();
|
||||
}))));
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: 'node',
|
||||
value: function node(_node, cb) {
|
||||
var _this = this;
|
||||
|
||||
_node.each(function (child) {
|
||||
switch (child.type) {
|
||||
case 'rule':
|
||||
_this.rule(child, cb);
|
||||
break;
|
||||
case 'decl':
|
||||
_this.decl(child, cb);
|
||||
break;
|
||||
case 'atrule':
|
||||
_this.atrule(child, cb);
|
||||
break;
|
||||
case 'comment':
|
||||
_this.comment(child, cb);
|
||||
break;
|
||||
default:
|
||||
throw new Error('Unkonwn node type ' + child.type);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'process',
|
||||
value: function process(node, cb) {
|
||||
// Reset ignoring rules specified by inline comments per each file
|
||||
this.ignore = [];
|
||||
|
||||
// Recursively walk nodes in file
|
||||
this.node(node, cb);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Detector;
|
||||
})();
|
86
node_modules/doiuse/lib/doiuse.js
generated
vendored
Normal file
86
node_modules/doiuse/lib/doiuse.js
generated
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var missingSupport = require('./missing-support');
|
||||
var Detector = require('./detect-feature-use');
|
||||
var Multimatch = require('multimatch');
|
||||
|
||||
function doiuse(options) {
|
||||
var browserQuery = options.browsers;
|
||||
var onFeatureUsage = options.onFeatureUsage;
|
||||
var ignoreOptions = options.ignore;
|
||||
var ignoreFiles = options.ignoreFiles;
|
||||
|
||||
if (!browserQuery) {
|
||||
browserQuery = doiuse['default'].slice();
|
||||
}
|
||||
|
||||
var _missingSupport = missingSupport(browserQuery);
|
||||
|
||||
var browsers = _missingSupport.browsers;
|
||||
var features = _missingSupport.features;
|
||||
|
||||
var detector = new Detector(_.keys(features));
|
||||
|
||||
return {
|
||||
info: function info() {
|
||||
return {
|
||||
browsers: browsers,
|
||||
features: features
|
||||
};
|
||||
},
|
||||
|
||||
postcss: function postcss(css, result) {
|
||||
return detector.process(css, function (_ref) {
|
||||
var feature = _ref.feature;
|
||||
var usage = _ref.usage;
|
||||
var ignore = _ref.ignore;
|
||||
|
||||
if (ignore && ignore.indexOf(feature) !== -1) {
|
||||
return;
|
||||
}
|
||||
if (ignoreOptions && ignoreOptions.indexOf(feature) !== -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (ignoreFiles && Multimatch(usage.source.input.from, ignoreFiles).length > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.join(' and ') + ' (' + feature + ')';
|
||||
|
||||
result.warn(message, { node: usage, plugin: 'doiuse' });
|
||||
|
||||
if (onFeatureUsage) {
|
||||
var loc = usage.source;
|
||||
loc.original = css.source.input.map ? {
|
||||
start: css.source.input.map.consumer().originalPositionFor(loc.start),
|
||||
end: css.source.input.map.consumer().originalPositionFor(loc.end)
|
||||
} : {
|
||||
start: loc.start,
|
||||
end: loc.end
|
||||
};
|
||||
|
||||
message = (loc.original.start.source || loc.input.file || loc.input.from) + ':' + loc.original.start.line + ':' + loc.original.start.column + ': ' + message;
|
||||
|
||||
onFeatureUsage({
|
||||
feature: feature,
|
||||
featureData: features[feature],
|
||||
usage: usage,
|
||||
message: message
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
doiuse['default'] = ['> 1%', 'last 2 versions', 'Firefox ESR', 'Opera 12.1'];
|
||||
module.exports = doiuse;
|
110
node_modules/doiuse/lib/missing-support.js
generated
vendored
Normal file
110
node_modules/doiuse/lib/missing-support.js
generated
vendored
Normal file
@@ -0,0 +1,110 @@
|
||||
'use strict';
|
||||
|
||||
var features = require('../data/features');
|
||||
var BrowserSelection = require('./browsers');
|
||||
var _ = require('lodash');
|
||||
var formatBrowserName = require('./util').formatBrowserName;
|
||||
|
||||
var caniuse = require('caniuse-db/fulldata-json/data-1.0');
|
||||
|
||||
function filterStats(browsers, stats) {
|
||||
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) {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
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(', ');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data on CSS features not supported by the given autoprefixer-like
|
||||
* browser selection.
|
||||
*
|
||||
* @returns `{browsers, features}`, where `features` is an array of:
|
||||
* ```
|
||||
* {
|
||||
* 'feature-name': {
|
||||
* title: 'Title of feature'
|
||||
* missing: "IE (8), Chrome (31)"
|
||||
* missingData: {
|
||||
* // map of browser -> version -> (lack of)support code
|
||||
* ie: { '8': 'n' },
|
||||
* chrome: { '31': 'n' }
|
||||
* }
|
||||
* partialData: {
|
||||
* // map of browser -> version -> (partial)support code
|
||||
* ie: { '7': 'a' },
|
||||
* ff: { '29': 'a #1' }
|
||||
* }
|
||||
* caniuseData: {
|
||||
* // caniuse-db json data for this feature
|
||||
* }
|
||||
* },
|
||||
* 'feature-name-2': {} // etc.
|
||||
* }
|
||||
* ```
|
||||
*
|
||||
* `feature-name` is a caniuse-db slug.
|
||||
*/
|
||||
function missing(browserRequest) {
|
||||
var browsers = new BrowserSelection(browserRequest);
|
||||
var result = {};
|
||||
|
||||
Object.keys(features).forEach(function (feature) {
|
||||
var featureData = caniuse.data[feature];
|
||||
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);
|
||||
|
||||
if (missing.length > 0 || partial.length > 0) {
|
||||
result[feature] = {
|
||||
title: featureData.title,
|
||||
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;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
browsers: browsers.list(),
|
||||
features: result
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = missing;
|
13
node_modules/doiuse/lib/util.js
generated
vendored
Normal file
13
node_modules/doiuse/lib/util.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
var agents = require('caniuse-db/data').agents;
|
||||
|
||||
module.exports = {
|
||||
formatBrowserName: function formatBrowserName(browserKey, versions) {
|
||||
var browserName = (agents[browserKey] || {}).browser;
|
||||
if (!versions) {
|
||||
return browserName;
|
||||
}
|
||||
return browserName + ' (' + versions.join(',') + ')';
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user