Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

maishu-router

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

maishu-router - npm Package Compare versions

Comparing version 1.4.0 to 1.4.2

1

out/route-item-collection.d.ts

@@ -12,1 +12,2 @@ import { RouterItem } from "./route-item";

}
export declare function parseRouterString(routerString: string): RouterItem[];
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.RouterItems = void 0;
const errors_1 = require("./errors");
exports.parseRouterString = exports.RouterItems = void 0;
const route_item_1 = require("./route-item");
let signals = {
star: "*",
colon: ":",
question: "?"
};
class RouterItems {
constructor(routerString) {
// let arr = routerString.split("/").filter(o => o);
// for (let i = 0; i < arr.length; i++) {
// let item = new RouterItem(arr[i]);
// let isExists = this._items.filter(o => o.name == item.name).length > 0;
// if (isExists)
// throw errors.routeItemExists(arr[i]);
this._items = [];
this._index = 0;
let arr = routerString.split("/").filter(o => o);
for (let i = 0; i < arr.length; i++) {
let item = new route_item_1.RouterItem(arr[i]);
let isExists = this._items.filter(o => o.name == item.name).length > 0;
if (isExists)
throw errors_1.errors.routeItemExists(arr[i]);
this._items.push(item);
}
// this._items.push(item);
// }
this._items = parseRouterString(routerString);
}

@@ -39,1 +44,61 @@ get all() {

exports.RouterItems = RouterItems;
function parseRouterString(routerString) {
if (routerString.endsWith("/") == false)
routerString = routerString + "/";
// let routeRegex: string | undefined;
let nameStart;
let nameEnd;
let regexStart;
let regexEnd;
let routerItems = [];
let currentChar;
let previousChar;
for (let i = 0; i < routerString.length; i++) {
previousChar = currentChar;
currentChar = routerString[i];
if (currentChar == '/') {
if (previousChar == '\\')
continue;
if (nameStart == undefined) {
nameStart = i + 1;
}
else if (nameStart != undefined && nameEnd == undefined && regexStart == undefined) {
nameEnd = i - 1;
}
else if (regexStart != undefined) {
regexEnd = i - 1;
}
if (nameStart != undefined && nameEnd != undefined) {
console.assert(nameEnd > nameStart);
var routeSegment = routerString.substring(nameStart, nameEnd + 1);
let routeItem = new route_item_1.RouterItem(routeSegment);
if (regexStart != undefined && regexEnd != undefined) {
var routeRegex = routerString.substring(regexStart, regexEnd + 1);
// 替换 \/ 为 /
routeRegex = routeRegex.replace(/\\\//, '/');
routeItem.regexp = new RegExp(routeRegex);
}
routerItems.push(routeItem);
nameStart = undefined;
nameEnd = undefined;
regexStart = undefined;
regexEnd = undefined;
if (i + 1 <= routerString.length - 1) {
nameStart = i + 1;
}
}
}
else if (currentChar == '#') {
regexStart = i + 1;
nameEnd = i - 1;
}
else if (i == routerString.length - 1) {
if (nameStart != undefined && nameEnd == undefined && regexStart == undefined)
nameEnd = i;
else if (regexStart != undefined)
regexEnd = i;
}
}
return routerItems;
}
exports.parseRouterString = parseRouterString;

2

package.json
{
"name": "maishu-router",
"version": "1.4.0",
"version": "1.4.2",
"author": "shu mai",

@@ -5,0 +5,0 @@ "dependencies": {

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