@mapl/router 0.7.0 → 0.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapl/router",
3
- "version": "0.7.0",
3
+ "version": "0.7.1",
4
4
  "description": "The fastest possible JS router",
5
5
  "repository": {
6
6
  "type": "git",
@@ -9,15 +9,13 @@
9
9
  "license": "MIT",
10
10
  "type": "module",
11
11
  "exports": {
12
- "./path/compiler": "./path/compiler.js",
13
- "./method/compiler": "./method/compiler.js",
14
- "./utils": "./utils.js",
15
- "./fast-method/compiler": "./fast-method/compiler.js",
16
- "./tree/node": "./tree/node.js",
17
12
  "./constants": "./constants.js",
13
+ "./utils": "./utils.js",
18
14
  "./method": "./method/index.js",
15
+ "./path": "./path/index.js",
16
+ "./method/compiler": "./method/compiler.js",
17
+ "./path/compiler": "./path/compiler.js",
19
18
  "./tree/compiler": "./tree/compiler.js",
20
- "./fast-method": "./fast-method/index.js",
21
- "./path": "./path/index.js"
19
+ "./tree/node": "./tree/node.js"
22
20
  }
23
21
  }
package/tree/compiler.js CHANGED
@@ -1 +1 @@
1
- export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=`{`;let noStore=node[1]==null;let partLen=node[0].length;let currentIdx=idxPrefix+(idx+partLen);if(partLen>1){let start=idxPrefix+(idx+1);builder=partLen===2?`if(l`+(noStore?`>`:`>=`)+currentIdx+`)if(p.charCodeAt(`+start+`)===`+node[0].charCodeAt(1)+`){`:(noStore?`if(l>`+currentIdx+`)if(`:`if(`)+`p.startsWith("`+node[0].slice(1)+`",`+start+`)){`}else if(noStore)builder=`if(l>`+currentIdx+`){`;idx+=partLen;noStore||(builder+=`if(l===`+currentIdx+`){`+node[1]+`}`);if(node[2]!=null){let childrenEntries=Object.entries(node[2]);if(childrenEntries.length===1)builder+=`if(p.charCodeAt(`+currentIdx+`)===`+childrenEntries[0][0]+`){`+compile(childrenEntries[0][1],paramCount,idx,idxPrefix)+`}`;else{builder+=`switch(p.charCodeAt(`+currentIdx+`)){`;for(let i=0;i<childrenEntries.length;i++)builder+=`case `+childrenEntries[i][0]+`:{`+compile(childrenEntries[i][1],paramCount,idx,idxPrefix)+`}`;builder+=`}`}}if(node[3]!=null){let params=node[3];let hasStore=params[1]!=null;let hasChild=params[0]!=null;if(paramCount>0){builder+=`let i=`+currentIdx+`;`;currentIdx=`i`}let slashIndex=`p.indexOf("/"`+(currentIdx===`0`?``:`,`+currentIdx)+`)`;if(hasChild||!hasStore){builder+=(paramCount>0?``:`let `)+`j=`+slashIndex+`;`;slashIndex=`j`}hasStore&&(builder+=`if(`+slashIndex+`===-1){let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+params[1]+`}`);hasChild&&(builder+=(hasStore?`else if(`:`if(`)+`j>`+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+`,j);`+compile(params[0],paramCount+1,0,`j+`)+`}`)}node[4]==null||(builder+=`let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+node[4]);return builder+`}`};
1
+ export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=`{`;let noStore=node[1]==null;let partLen=node[0].length;let currentIdx=idxPrefix+(idx+partLen);if(partLen>1){let start=idxPrefix+(idx+1);builder=partLen===2?`if(l`+(noStore?`>`:`>=`)+currentIdx+`)if(p.charCodeAt(`+start+`)===`+node[0].charCodeAt(1)+`){`:(noStore?`if(l>`+currentIdx+`)if(`:`if(`)+`p.startsWith("`+node[0].slice(1)+`",`+start+`)){`}else if(noStore)builder=`if(l>`+currentIdx+`){`;idx+=partLen;noStore||(builder+=`if(l===`+currentIdx+`){`+node[1]+`}`);if(node[2]!=null){let childrenEntries=Object.entries(node[2]);if(childrenEntries.length===1)builder+=`if(p.charCodeAt(`+currentIdx+`)===`+childrenEntries[0][0]+`){`+compile(childrenEntries[0][1],paramCount,idx,idxPrefix)+`}`;else{builder+=`switch(p.charCodeAt(`+currentIdx+`)){`;for(let i=0;i<childrenEntries.length;i++)builder+=`case `+childrenEntries[i][0]+`:{`+compile(childrenEntries[i][1],paramCount,idx,idxPrefix)+`break}`;builder+=`}`}}if(node[3]!=null){let params=node[3];let hasStore=params[1]!=null;let hasChild=params[0]!=null;if(paramCount>0){builder+=`let i=`+currentIdx+`;`;currentIdx=`i`}let slashIndex=`p.indexOf("/"`+(currentIdx===`0`?``:`,`+currentIdx)+`)`;if(hasChild||!hasStore){builder+=(paramCount>0?``:`let `)+`j=`+slashIndex+`;`;slashIndex=`j`}hasStore&&(builder+=`if(`+slashIndex+`===-1){let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+params[1]+`}`);hasChild&&(builder+=(hasStore?`else if(`:`if(`)+`j>`+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+`,j);`+compile(params[0],paramCount+1,0,`j+`)+`}`)}node[4]==null||(builder+=`let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+node[4]);return builder+`}`};
@@ -1,13 +0,0 @@
1
- import type { Router } from "./index.js";
2
- declare const _default: (router: Router<string>, methodInput: string, parsePath: string, startIndex: 0 | 1) => string;
3
- /**
4
- * Faster string comparisons for frameworks as most request URL strings are not optimized for slice & comparison.
5
- *
6
- * @example
7
- * // Example path parser
8
- * let $PATH = req.url,
9
- * $PATH_START = p.indexOf('/', 12) + 1,
10
- * $PATH_END = p.indexOf('?', s),
11
- * $PATH_LEN = e === -1 ? p.length : e;
12
- */
13
- export default _default;
@@ -1 +0,0 @@
1
- import{compile}from"../tree/compiler.js";export default (router,methodInput,parsePath,startIndex)=>{let allRouter=router[``];let str=``;for(let key in router)key!==``&&(str+=(str===``?`if(`:`else if(`)+methodInput+`==="`+key+`"){`+(allRouter==null?parsePath:``)+compile(router[key],0,-startIndex,`s+`)+`}`);return allRouter==null?str:parsePath+str+compile(allRouter,0,-startIndex,`s+`)};
@@ -1,4 +0,0 @@
1
- import { type Node } from "../tree/node.js";
2
- export type Router<T = unknown> = Record<string, Node<T>>;
3
- export declare const createRouter: <T>() => Router<T>;
4
- export declare const insertItem: <T>(router: Router<T>, method: string, path: string, item: T) => void;
@@ -1 +0,0 @@
1
- import{createNode,insertItem as nodeInsertItem}from"../tree/node.js";export let createRouter=()=>({});export let insertItem=(router,method,path,item)=>{nodeInsertItem(router[method]??=createNode(`/`),path,item)};