Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
eslint: update eslint config & fix code
- Loading branch information
Showing
10 changed files
with
410 additions
and
414 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
'use strict'; | ||
'use strict' | ||
|
||
/** | ||
* module dependencies | ||
*/ | ||
|
||
const pathToRegexp = require('path-to-regexp'); | ||
const debug = require('debug')('impress:layer'); | ||
const pathToRegexp = require('path-to-regexp') | ||
const debug = require('debug')('impress:layer') | ||
|
||
module.exports = class Layer { | ||
constructor(path, options, fn) { | ||
// setup regex | ||
this.regexp = pathToRegexp(path, this.keys = [], options); | ||
this.regexp = pathToRegexp(path, this.keys = [], options) | ||
|
||
// fn*(next) | ||
this.fn = fn; | ||
this.name = fn.name || '<anonymous>'; | ||
this.fn = fn | ||
this.name = fn.name || '<anonymous>' | ||
|
||
// will present after match | ||
this.path = ''; | ||
this.params = {}; | ||
this.path = '' | ||
this.params = {} | ||
|
||
if (path === '/' && options.end === false) { | ||
this.regexp.fastSlash = true; | ||
this.regexp.fastSlash = true | ||
} | ||
} | ||
|
||
match(path) { | ||
if (!path) { | ||
return false; | ||
return false | ||
} | ||
|
||
if (this.regexp.fastSlash) { | ||
return true; | ||
return true | ||
} | ||
|
||
const m = this.regexp.exec(path); | ||
const m = this.regexp.exec(path) | ||
if (!m) { | ||
return false; | ||
return false | ||
} | ||
|
||
// m = [full,group1...groupN] | ||
this.path = m[0]; | ||
this.params = {}; | ||
let n = 0; // store the anaymous params | ||
this.path = m[0] | ||
this.params = {} | ||
let n = 0 // store the anaymous params | ||
|
||
for (let i = 0, len = this.keys.length; i < len; i++) { | ||
const key = this.keys[i].name || n++; | ||
const val = m[i + 1]; | ||
this.params[key] = decodeParam(val); | ||
const key = this.keys[i].name || n++ | ||
const val = m[i + 1] | ||
this.params[key] = decodeParam(val) | ||
} | ||
|
||
return true; | ||
return true | ||
} | ||
}; | ||
} | ||
|
||
function decodeParam(val) { | ||
/* istanbul ignore next */ | ||
if (typeof val !== 'string') { | ||
return val; | ||
return val | ||
} | ||
|
||
/* istanbul ignore next */ | ||
try { | ||
return decodeURIComponent(val); | ||
return decodeURIComponent(val) | ||
} catch (e) { | ||
const err = new TypeError('Failed to decode param "' + val + '"'); | ||
err.status = 400; | ||
throw err; | ||
const err = new TypeError('Failed to decode param "' + val + '"') | ||
err.status = 400 | ||
throw err | ||
} | ||
} |
Oops, something went wrong.