@ndiinginc/router 4.14.0 → 4.14.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/router.js +8 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ndiinginc/router",
3
- "version": "4.14.0",
3
+ "version": "4.14.1",
4
4
  "description": "",
5
5
  "main": "./src/index.js",
6
6
  "scripts": {
package/src/router.js CHANGED
@@ -219,14 +219,15 @@ class Router {
219
219
  * @param {Object} state
220
220
  * @returns {{path:Array,params:Object,matched:Boolean}}
221
221
  */
222
- search(method, path, node, nodes = [], params = {}, state = { nodes: [], params: {} }) {
222
+ search(method, path, node = this.root, nodes = [], params = {}, state = { nodes: [], params: {} }) {
223
223
  nodes.push(node);
224
224
  if (0 === path.length) {
225
225
  if (node.handlers.has(method) || node.handlers.has("ALL")) {
226
226
  return { nodes, params, matched: true };
227
227
  }
228
228
  if (nodes.length > state.nodes.length) {
229
- state = { nodes: nodes.slice(), params: { ...params } };
229
+ state.nodes=nodes.slice()
230
+ params={...params}
230
231
  }
231
232
  nodes.pop();
232
233
  return { nodes: state.nodes, params: state.params, matched: false };
@@ -256,7 +257,8 @@ class Router {
256
257
  };
257
258
  }
258
259
  if (nodes.length > state.nodes.length) {
259
- state = { nodes: nodes.slice(), params: { ...params } };
260
+ state.nodes=nodes.slice()
261
+ params={...params}
260
262
  }
261
263
  nodes.pop();
262
264
  return { nodes: state.nodes, params: state.params, matched: false };
@@ -291,11 +293,11 @@ class Router {
291
293
  * @returns {{matched: boolean;params: Object;paramsLength: number;handlers: any[];errorHandlers: any[];}}
292
294
  */
293
295
  find(method, path) {
294
- let res = this.search(method, path, this.root);
296
+ let res = this.search(method, path);
295
297
 
296
298
  if (!res.matched && path.length > 1) {
297
299
  const alt = path.endsWith("/") ? path.slice(0, -1) : path + "/";
298
- res = this.search(method, alt, this.root);
300
+ res = this.search(method, alt);
299
301
  }
300
302
  const handlers = {};
301
303
  const errorHandlers = {};
@@ -313,5 +315,6 @@ class Router {
313
315
  errorHandlers: Object.values(errorHandlers),
314
316
  };
315
317
  }
318
+
316
319
  }
317
320
  exports.Router = Router;