From a01232d1fd132d9746993f1d4d00e87313c6726a Mon Sep 17 00:00:00 2001 From: Rajkumar Dusad Date: Tue, 28 Feb 2023 17:06:12 +0530 Subject: [PATCH] Type declaration --- index.d.ts | 7 +------ package.json | 2 +- src/route.cjs | 14 +++++++------- src/route.mjs | 14 +++++++------- src/router.cjs | 2 +- src/router.mjs | 2 +- 6 files changed, 18 insertions(+), 23 deletions(-) diff --git a/index.d.ts b/index.d.ts index 61a9f3b..2b48bcf 100644 --- a/index.d.ts +++ b/index.d.ts @@ -29,13 +29,8 @@ declare interface Route { declare type handler = (req: any, res: any) => void; -interface RouterOptions { - caseSensitive?: boolean; - host?: string; -} - export declare class Router { - constructor(options?: RouterOptions); + constructor(options?: { caseSensitive?: boolean; host?: string }); checkout(path: string, ...callbacks: any[]): this; copy(path: string, ...callbacks: any[]): this; delete(path: string, ...callbacks: any[]): this; diff --git a/package.json b/package.json index 6f3f1c3..78cd225 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@routejs/router", - "version": "2.1.0", + "version": "2.1.1", "description": "Fast and lightweight http routing engine for nodejs", "main": "index.mjs", "type": "module", diff --git a/src/route.cjs b/src/route.cjs index 9c407a7..e6a4b62 100644 --- a/src/route.cjs +++ b/src/route.cjs @@ -14,13 +14,13 @@ module.exports = class Route { caseSensitive = false; constructor({ host, method, path, name, group, callbacks, caseSensitive }) { - if (!!host && !(typeof host === "string" || host instanceof String)) { + if (host && !(typeof host === "string" || host instanceof String)) { throw new TypeError( "Error: route host accepts only string as an argument" ); } - if (!!method) { + if (method) { if (Array.isArray(method)) { method = method.map((e) => { if (!(typeof e === "string" || e instanceof String)) { @@ -49,7 +49,7 @@ module.exports = class Route { } } - if (!!path && !(typeof path === "string" || path instanceof String)) { + if (path && !(typeof path === "string" || path instanceof String)) { throw new TypeError( "Error: route path accepts only string as an argument" ); @@ -80,7 +80,7 @@ module.exports = class Route { if (typeof callback !== "function") { throw new TypeError( `Error: ${ - !!path ? "route" : "middleware" + path ? "route" : "middleware" } callback accepts only function as an argument` ); } @@ -95,7 +95,7 @@ module.exports = class Route { } match({ host, method, path }) { - if (!!host && !(typeof host === "string" || host instanceof String)) { + if (host && !(typeof host === "string" || host instanceof String)) { throw new TypeError( "Error: request host accepts only string as an argument" ); @@ -134,7 +134,7 @@ module.exports = class Route { subdomains: {}, }; - if (!!this.hostRegexp) { + if (this.hostRegexp) { const match = this.hostRegexp.exec(host); if (match === null) { return false; @@ -150,7 +150,7 @@ module.exports = class Route { } } - if (!!this.method) { + if (this.method) { if (Array.isArray(this.method)) { if (!this.method.includes(method.toUpperCase())) { return false; diff --git a/src/route.mjs b/src/route.mjs index 05129bd..eee1995 100644 --- a/src/route.mjs +++ b/src/route.mjs @@ -14,13 +14,13 @@ export default class Route { caseSensitive = false; constructor({ host, method, path, name, group, callbacks, caseSensitive }) { - if (!!host && !(typeof host === "string" || host instanceof String)) { + if (host && !(typeof host === "string" || host instanceof String)) { throw new TypeError( "Error: route host accepts only string as an argument" ); } - if (!!method) { + if (method) { if (Array.isArray(method)) { method = method.map((e) => { if (!(typeof e === "string" || e instanceof String)) { @@ -49,7 +49,7 @@ export default class Route { } } - if (!!path && !(typeof path === "string" || path instanceof String)) { + if (path && !(typeof path === "string" || path instanceof String)) { throw new TypeError( "Error: route path accepts only string as an argument" ); @@ -80,7 +80,7 @@ export default class Route { if (typeof callback !== "function") { throw new TypeError( `Error: ${ - !!path ? "route" : "middleware" + path ? "route" : "middleware" } callback accepts only function as an argument` ); } @@ -95,7 +95,7 @@ export default class Route { } match({ host, method, path }) { - if (!!host && !(typeof host === "string" || host instanceof String)) { + if (host && !(typeof host === "string" || host instanceof String)) { throw new TypeError( "Error: request host accepts only string as an argument" ); @@ -134,7 +134,7 @@ export default class Route { subdomains: {}, }; - if (!!this.hostRegexp) { + if (this.hostRegexp) { const match = this.hostRegexp.exec(host); if (match === null) { return false; @@ -150,7 +150,7 @@ export default class Route { } } - if (!!this.method) { + if (this.method) { if (Array.isArray(this.method)) { if (!this.method.includes(method.toUpperCase())) { return false; diff --git a/src/router.cjs b/src/router.cjs index 7a95972..62876e0 100644 --- a/src/router.cjs +++ b/src/router.cjs @@ -192,7 +192,7 @@ module.exports = class Router { } }); let routePath = namedRoute && namedRoute.path; - if (!!namedRoute.params) { + if (namedRoute.params) { if ( !Array.isArray(params) || namedRoute.params.length !== params.length diff --git a/src/router.mjs b/src/router.mjs index 67047e0..06d1f3b 100644 --- a/src/router.mjs +++ b/src/router.mjs @@ -192,7 +192,7 @@ export default class Router { } }); let routePath = namedRoute && namedRoute.path; - if (!!namedRoute.params) { + if (namedRoute.params) { if ( !Array.isArray(params) || namedRoute.params.length !== params.length