Skip to content

Commit

Permalink
Code style (jscs)
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvdo committed Mar 1, 2015
1 parent 2f55410 commit c19d645
Show file tree
Hide file tree
Showing 16 changed files with 491 additions and 420 deletions.
61 changes: 61 additions & 0 deletions .jscsrc
@@ -0,0 +1,61 @@
{
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"requireOperatorBeforeLineBreak": true,
"requireCamelCaseOrUpperCaseIdentifiers": true,
"maximumLineLength": {
"value": 120,
"allowComments": true,
"allowRegex": true
},
"validateIndentation": 2,
"validateQuoteMarks": "'",

"disallowMultipleLineStrings": true,
"disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true,
"disallowSpaceAfterPrefixUnaryOperators": true,
"disallowMultipleVarDecl": "exceptUndefined",
"disallowKeywordsOnNewLine": ["else"],

"requireSpaceAfterKeywords": [
"if",
"else",
"for",
"while",
"do",
"switch",
"return",
"try",
"catch"
],
"requireSpaceBeforeBinaryOperators": [
"=", "+=", "-=", "*=", "/=", "%=", "<<=", ">>=", ">>>=",
"&=", "|=", "^=", "+=",

"+", "-", "*", "/", "%", "<<", ">>", ">>>", "&",
"|", "^", "&&", "||", "===", "==", ">=",
"<=", "<", ">", "!=", "!=="
],
"requireSpaceAfterBinaryOperators": true,
"requireSpacesInConditionalExpression": true,
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInForStatement": true,
"requireLineFeedAtFileEnd": true,
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"disallowSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpacesInsideParentheses": true,

"disallowMultipleLineBreaks": true,
"disallowNewlineBeforeBlockStatements": true
}
11 changes: 11 additions & 0 deletions Gulpfile.js
Expand Up @@ -50,6 +50,17 @@ gulp.task('lint', function() {
.pipe(jshint.reporter('jshint-stylish'));
});

/**
*
* Coding style
*
*/
gulp.task('jscs', function() {
var jscs = require('gulp-jscs');
gulp.src(['lib/**/*.js', 'test/**/*.js'])
.pipe(jscs());
});

/**
*
* Test spec
Expand Down
93 changes: 47 additions & 46 deletions lib/browsers.js
Expand Up @@ -7,27 +7,29 @@
*/
function Browsers (options) {

var browserslist = require('autoprefixer-core/node_modules/browserslist');
var module = 'autoprefixer-core/node_modules/';

options = options || {};
options.browsers = options.browsers || browserslist.defaults;
var browserslist = require(module + 'browserslist');

this.selected = browserslist(options.browsers);
this.browsers = browserslist.data;
options = options || {};
options.browsers = options.browsers || browserslist.defaults;

var features = {};
this.selected = browserslist(options.browsers);
this.browsers = browserslist.data;

this.getBrowsersByFeature(require('autoprefixer-core/node_modules/caniuse-db/features-json/rem'), function(browsers) {
features.rem = browsers;
});
this.getBrowsersByFeature(require('autoprefixer-core/node_modules/caniuse-db/features-json/css-opacity'), function(browsers) {
features.opacity = browsers;
});
this.getBrowsersByFeature(require('autoprefixer-core/node_modules/caniuse-db/features-json/css-gencontent'), function(browsers) {
features.pseudoElements = browsers;
});
var features = {};

this.features = features;
this.getBrowsersByFeature(require(module + 'caniuse-db/features-json/rem'), function(browsers) {
features.rem = browsers;
});
this.getBrowsersByFeature(require(module + 'caniuse-db/features-json/css-opacity'), function(browsers) {
features.opacity = browsers;
});
this.getBrowsersByFeature(require(module + 'caniuse-db/features-json/css-gencontent'), function(browsers) {
features.pseudoElements = browsers;
});

this.features = features;

}

Expand All @@ -38,50 +40,49 @@ function Browsers (options) {
*
*/
Browsers.prototype.getBrowsersByFeature = function(data, callback) {
var match = /(n|a)($|\s)/;
var need = [];
data = data.stats;
for (var browser in data) {
var versions = data[browser];
for (var interval in versions) {
var support = versions[interval];
var dbl = interval.split('-');
for (var i = 0, len = dbl.length; i < len; i++) {
var version = dbl[i];
if (this.browsers[browser] && support.match(match)) {
version = version.replace(/\.0$/, '');
need.push(browser + ' ' + version);
}
}
var match = /(n|a)($|\s)/;
var need = [];
data = data.stats;
for (var browser in data) {
var versions = data[browser];
for (var interval in versions) {
var support = versions[interval];
var dbl = interval.split('-');
for (var i = 0, len = dbl.length; i < len; i++) {
var version = dbl[i];
if (this.browsers[browser] && support.match(match)) {
version = version.replace(/\.0$/, '');
need.push(browser + ' ' + version);
}
}
}
var sorted = need.sort(function(a, b) {
a = a.split(' ');
b = b.split(' ');
if (a[0] > b[0]) {
return 1;
} else if (a[0] < b[0]) {
return -1;
} else {
return parseFloat(a[1]) - parseFloat(b[1]);
}
});
return callback(sorted);
}
var sorted = need.sort(function(a, b) {
a = a.split(' ');
b = b.split(' ');
if (a[0] > b[0]) {
return 1;
} else if (a[0] < b[0]) {
return -1;
} else {
return parseFloat(a[1]) - parseFloat(b[1]);
}
});
return callback(sorted);
};


/**
*
* New Browsers instance
*
*/
var browsers = function(options) {
return new Browsers(options);
return new Browsers(options);
};

/**
*
* Exports
*
*/
module.exports = browsers;
module.exports = browsers;

0 comments on commit c19d645

Please sign in to comment.