Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace 'or (||)' cond with default params #153

Merged
merged 1 commit into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions lib/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ module.exports = Layer;
* @private
*/

function Layer(path, methods, middleware, opts) {
this.opts = opts || {};
function Layer(path, methods, middleware, opts = {}) {
this.opts = opts;
this.name = this.opts.name || null;
this.methods = [];
this.paramNames = [];
Expand Down Expand Up @@ -60,14 +60,12 @@ Layer.prototype.match = function (path) {
*
* @param {String} path
* @param {Array.<String>} captures
* @param {Object=} existingParams
* @param {Object=} params
* @returns {Object}
* @private
*/

Layer.prototype.params = function (path, captures, existingParams) {
const params = existingParams || {};

Layer.prototype.params = function (path, captures, params = {}) {
for (let len = captures.length, i = 0; i < len; i++) {
if (this.paramNames[i]) {
const c = captures[i];
Expand Down
11 changes: 4 additions & 7 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ module.exports = Router;
* @constructor
*/

function Router(opts) {
function Router(opts = {}) {
if (!(this instanceof Router)) return new Router(opts);

this.opts = opts || {};
this.opts = opts;
this.methods = this.opts.methods || [
'HEAD',
'OPTIONS',
Expand Down Expand Up @@ -425,8 +425,7 @@ Router.prototype.routes = Router.prototype.middleware = function () {
* @returns {Function}
*/

Router.prototype.allowedMethods = function (options) {
options = options || {};
Router.prototype.allowedMethods = function (options = {}) {
const implemented = this.methods;

return function allowedMethods(ctx, next) {
Expand Down Expand Up @@ -550,9 +549,7 @@ Router.prototype.redirect = function (source, destination, code) {
* @private
*/

Router.prototype.register = function (path, methods, middleware, opts) {
opts = opts || {};

Router.prototype.register = function (path, methods, middleware, opts = {}) {
const router = this;
const stack = this.stack;

Expand Down