Skip to content

Commit

Permalink
chore(all): add eslint and fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bryanrsmith committed Aug 27, 2015
1 parent a823d83 commit d99c08e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 90 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "./node_modules/aurelia-tools/.eslintrc"
}
8 changes: 4 additions & 4 deletions build/tasks/lint.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var gulp = require('gulp');
var paths = require('../paths');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var eslint = require('gulp-eslint');

gulp.task('lint', function() {
return gulp.src(paths.source)
.pipe(jshint())
.pipe(jshint.reporter(stylish));
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
"devDependencies": {
"aurelia-tools": "^0.1.6",
"babel-dts-generator": "^0.2.5",
"babel-eslint": "^4.1.0",
"conventional-changelog": "0.0.11",
"del": "^1.1.0",
"gulp": "^3.8.10",
"gulp-babel": "^5.1.0",
"gulp-bump": "^0.3.1",
"gulp-jshint": "^1.9.0",
"gulp-eslint": "^1.0.0",
"gulp-rename": "^1.2.2",
"gulp-yuidoc": "^0.1.2",
"jasmine-core": "^2.1.3",
"jshint-stylish": "^1.0.0",
"karma": "^0.12.28",
"karma-babel-preprocessor": "^5.2.1",
"karma-chrome-launcher": "^0.1.7",
Expand Down
175 changes: 91 additions & 84 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,80 +1,82 @@
function trimDots(ary: string[]) {
var i, part;
for (i = 0; i < ary.length; ++i) {
part = ary[i];
if (part === '.') {
ary.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i == 1 && ary[2] === '..') || ary[i - 1] === '..') {
continue;
} else if (i > 0) {
ary.splice(i - 1, 2);
i -= 2;
}
function trimDots(ary: string[]): void {
for (let i = 0; i < ary.length; ++i) {
let part = ary[i];
if (part === '.') {
ary.splice(i, 1);
i -= 1;
} else if (part === '..') {
// If at the start, or previous value is still ..,
// keep them so that when converted to a path it may
// still work when converted to a path, even though
// as an ID it is less than ideal. In larger point
// releases, may be better to just kick out an error.
if (i === 0 || (i === 1 && ary[2] === '..') || ary[i - 1] === '..') {
continue;
} else if (i > 0) {
ary.splice(i - 1, 2);
i -= 2;
}
}
}
}

export function relativeToFile(name : string, file : string) : string {
var lastIndex,
normalizedBaseParts,
fileParts = (file && file.split('/')),
nameParts = name.trim().split('/');
export function relativeToFile(name: string, file: string): string {
let fileParts = file && file.split('/');
let nameParts = name.trim().split('/');

if (nameParts[0].charAt(0) === '.' && fileParts) {
//Convert file to array, and lop off the last part,
//so that . matches that 'directory' and not name of the file's
//module. For instance, file of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
normalizedBaseParts = fileParts.slice(0, fileParts.length - 1);
nameParts = normalizedBaseParts.concat(nameParts);
//Convert file to array, and lop off the last part,
//so that . matches that 'directory' and not name of the file's
//module. For instance, file of 'one/two/three', maps to
//'one/two/three.js', but we want the directory, 'one/two' for
//this normalization.
let normalizedBaseParts = fileParts.slice(0, fileParts.length - 1);
nameParts.unshift(...normalizedBaseParts);
}

trimDots(nameParts);

return nameParts.join('/');
}

export function join(path1 : string, path2 : string) : string {
var url1, url2, url3, i, ii, urlPrefix, trailingSlash;

if(!path1){
export function join(path1: string, path2: string): string {
if (!path1) {
return path2;
}

if(!path2){
if (!path2) {
return path1;
}

urlPrefix = path1.indexOf('//') === 0 ? '//' :
path1.indexOf('/') === 0 ? '/' : '';
trailingSlash = path2.slice(-1) == '/' ? '/' : '';
let urlPrefix;
if (path1.indexOf('//') === 0) {
urlPrefix = '//';
} else if (path1.indexOf('/') === 0) {
urlPrefix = '/';
} else {
urlPrefix = '';
}

url1 = path1.split('/');
url2 = path2.split('/');
url3 = [];
let trailingSlash = path2.slice(-1) === '/' ? '/' : '';

for (i = 0, ii = url1.length; i < ii; ++i) {
if (url1[i] == '..') {
let url1 = path1.split('/');
let url2 = path2.split('/');
let url3 = [];

for (let i = 0, ii = url1.length; i < ii; ++i) {
if (url1[i] === '..') {
url3.pop();
} else if (url1[i] == '.' || url1[i] == '') {
} else if (url1[i] === '.' || url1[i] === '') {
continue;
} else {
url3.push(url1[i]);
}
}

for (i = 0, ii = url2.length; i < ii; ++i) {
if (url2[i] == '..') {
for (let i = 0, ii = url2.length; i < ii; ++i) {
if (url2[i] === '..') {
url3.pop();
} else if (url2[i] == '.' || url2[i] == '') {
} else if (url2[i] === '.' || url2[i] === '') {
continue;
} else {
url3.push(url2[i]);
Expand All @@ -84,65 +86,70 @@ export function join(path1 : string, path2 : string) : string {
return urlPrefix + url3.join('/').replace(/\:\//g, '://') + trailingSlash;
}

var r20 = /%20/g,
rbracket = /\[\]$/,
class2type = {};
export function buildQueryString(a: Object, traditional?: boolean): string {
let s = [];

'Boolean Number String Function Array Date RegExp Object Error'.split(' ').forEach((name, i) => {
class2type['[object ' + name + ']'] = name.toLowerCase();
});
function add(key: string, value: any) {
// If value is a function, invoke it and return its value
let v = value;
if (typeof value === 'function') {
v = value();
} else if (value === null || value === undefined) {
v = '';
}

function type( obj ){
if (obj == null){
return obj + "";
s.push(encodeURIComponent(key) + '=' + encodeURIComponent(v));
}

// Support: Android<4.0 (functionish RegExp)
return typeof obj === 'object' || typeof obj === 'function'
? class2type[ toString.call(obj) ] || 'object'
: typeof obj;
}

export function buildQueryString(a : Object, traditional? : boolean) : string {
var s = [],
add = function(key:string, value:any) {
// If value is a function, invoke it and return its value
value = typeof value === 'function' ? value() : (value == null ? '' : value);
s[s.length] = encodeURIComponent(key) + '=' + encodeURIComponent(value);
};

for(let prefix in a){
for (let prefix in a) {
_buildQueryString(prefix, a[prefix], traditional, add);
}

// Return the resulting serialization
return s.join('&').replace(r20, '+');
}

function _buildQueryString(prefix:string, obj:any, traditional:boolean, add: (p:string, v:any) => void){
if (Array.isArray(obj)){
function _buildQueryString(prefix: string, obj: any, traditional: boolean, add: (p: string, v: any) => void): void {
if (Array.isArray(obj)) {
// Serialize array item.
obj.forEach((v, i) => {
if(traditional || rbracket.test(prefix)){
if (traditional || rbracket.test(prefix)) {
// Treat each array item as a scalar.
add(prefix, v);
} else{
} else {
// Item is non-scalar (array or object), encode its numeric index.
_buildQueryString(
prefix + '[' + (typeof v === 'object' ? i : '') + ']',
v,
traditional,
add
);
let innerPrefix = prefix + '[' + (typeof v === 'object' ? i : '') + ']';
_buildQueryString(innerPrefix, v, traditional, add);
}
});
} else if (!traditional && type(obj) === 'object'){
} else if (!traditional && type(obj) === 'object') {
// Serialize object item.
for (let name in obj) {
_buildQueryString(prefix + '[' + name + ']', obj[name], traditional, add);
}
} else{
} else {
// Serialize scalar item.
add(prefix, obj);
}
}

const r20 = /%20/g;
const rbracket = /\[\]$/;
const class2type = {};

'Boolean Number String Function Array Date RegExp Object Error'
.split(' ')
.forEach((name) => {
class2type['[object ' + name + ']'] = name.toLowerCase();
});

function type(obj: any) {
if (obj === null || obj === undefined) {
return obj + '';
}

// Support: Android<4.0 (functionish RegExp)
return typeof obj === 'object' || typeof obj === 'function'
? class2type[toString.call(obj)] || 'object'
: typeof obj;
}

0 comments on commit d99c08e

Please sign in to comment.