Socket
Socket
Sign inDemoInstall

find-my-way

Package Overview
Dependencies
Maintainers
2
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-my-way - npm Package Compare versions

Comparing version 1.10.0 to 1.10.1

test/issue-49.test.js

27

index.js
'use strict'
/*
Node type
static: 0,
param: 1,
matchAll: 2,
regex: 3
multi-param: 4
It's used for a parameter, that is followed by another parameter in the same part
Char codes:

@@ -23,2 +15,3 @@ '#': 35

const Node = require('./node')
const NODE_TYPES = Node.prototype.types
const httpMethods = ['DELETE', 'GET', 'HEAD', 'PATCH', 'POST', 'PUT', 'OPTIONS', 'TRACE', 'CONNECT']

@@ -89,3 +82,3 @@ var errored = false

if (path.charCodeAt(i) === 58) {
var nodeType = 1
var nodeType = NODE_TYPES.PARAM
j = i + 1

@@ -109,5 +102,5 @@ this._insert(method, path.slice(0, i), 0, null, null, null, null)

if (isRegex && (i === len || path.charCodeAt(i) === 47)) {
nodeType = 3
nodeType = NODE_TYPES.REGEX
} else if (i < len && path.charCodeAt(i) !== 47) {
nodeType = 4
nodeType = NODE_TYPES.MULTI_PARAM
}

@@ -175,3 +168,3 @@

currentNode.map = {}
currentNode.kind = 0
currentNode.kind = NODE_TYPES.STATIC
currentNode.regex = null

@@ -332,3 +325,3 @@ currentNode.wildcardChild = null

// static route
if (kind === 0) {
if (kind === NODE_TYPES.STATIC) {
// if exist, save the wildcard child

@@ -354,3 +347,3 @@ if (currentNode.wildcardChild !== null) {

// parametric route
if (kind === 1) {
if (kind === NODE_TYPES.PARAM) {
currentNode = node

@@ -370,3 +363,3 @@ i = 0

// wildcard route
if (kind === 2) {
if (kind === NODE_TYPES.MATCH_ALL) {
decoded = fastDecode(path)

@@ -383,3 +376,3 @@ if (errored) {

// parametric(regex) route
if (kind === 3) {
if (kind === NODE_TYPES.REGEX) {
currentNode = node

@@ -400,3 +393,3 @@ i = 0

// multiparametric route
if (kind === 4) {
if (kind === NODE_TYPES.MULTI_PARAM) {
currentNode = node

@@ -403,0 +396,0 @@ i = 0

'use strict'
/*
Node type
static: 0,
param: 1,
matchAll: 2,
regex: 3
multi-param: 4
It's used for a parameter, that is followed by another parameter in the same part
*/
const types = {
STATIC: 0,
PARAM: 1,
MATCH_ALL: 2,
REGEX: 3,
// It's used for a parameter, that is followed by another parameter in the same part
MULTI_PARAM: 4
}

@@ -18,3 +17,3 @@ function Node (prefix, children, kind, map, regex) {

this.numberOfChildren = this.children.length
this.kind = kind || 0
this.kind = kind || this.types.STATIC
this.map = map || {}

@@ -26,18 +25,31 @@ this.regex = regex || null

Object.defineProperty(Node.prototype, 'types', {
value: types
})
Node.prototype.add = function (node) {
if (node.kind === 2) {
if (node.kind === this.types.MATCH_ALL) {
this.wildcardChild = node
}
if (node.kind === 1 || node.kind === 3 || node.kind === 4) {
for (var i = 0; i < this.numberOfChildren; i++) {
if (this.children[i].kind === 0) {
this.children[i].parametricBrother = node
}
this.children.push(node)
this.children.sort((n1, n2) => n1.kind - n2.kind)
this.numberOfChildren++
// Search for a parametric brother and store it in a variable
var parametricBrother = null
for (var i = 0; i < this.numberOfChildren; i++) {
const child = this.children[i]
if ([this.types.PARAM, this.types.REGEX, this.types.MULTI_PARAM].indexOf(child.kind) > -1) {
parametricBrother = child
break
}
}
this.children.push(node)
this.children.sort((n1, n2) => n1.kind - n2.kind)
this.numberOfChildren++
// Save the parametric brother inside a static child
for (i = 0; i < this.numberOfChildren; i++) {
if (this.children[i].kind === this.types.STATIC && parametricBrother) {
this.children[i].parametricBrother = parametricBrother
}
}
}

@@ -44,0 +56,0 @@

{
"name": "find-my-way",
"version": "1.10.0",
"version": "1.10.1",
"description": "Crazy fast http radix based router",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -108,3 +108,4 @@ # find-my-way

Regular expression routes are supported as well, but pay attention, RegExp are very expensive in term of performance!
Regular expression routes are supported as well, but pay attention, RegExp are very expensive in term of performance!<br>
If you want to declare a regular expression route, you must put the regular expression inside round parenthesis after the parameter name.
```js

@@ -111,0 +112,0 @@ // parametric with regexp

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc