@mapl/router 0.8.0 → 0.8.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.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "The fastest possible JS router",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,12 +10,12 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  "./utils": "./utils.js",
13
+ "./method/compiler": "./method/compiler.js",
13
14
  "./constants": "./constants.js",
14
15
  "./method": "./method/index.js",
15
- "./method/compiler": "./method/compiler.js",
16
- "./path/compiler": "./path/compiler.js",
17
16
  "./path": "./path/index.js",
18
- "./tree/compiler": "./tree/compiler.js",
19
- "./tree/node": "./tree/node.js"
17
+ "./tree/node": "./tree/node.js",
18
+ "./path/compiler": "./path/compiler.js",
19
+ "./tree/compiler": "./tree/compiler.js"
20
20
  }
21
21
  }
package/path/compiler.js CHANGED
@@ -1 +1 @@
1
- import{compile}from"../tree/compiler.js";import{isEmptyNode}from"../tree/node.js";export default (router,startIndex)=>{let str=``;for(let i=1;i<router.length;i+=2)str+=(str===``?`if(`:`else if(`)+`p==="`+router[i].slice(startIndex)+`"){`+router[i+1]+`}`;return str+(isEmptyNode(router[0])?``:`let l=p.length;`+compile(router[0],0,-startIndex,``))};
1
+ import{compile}from"../tree/compiler.js";import{isEmptyNode}from"../tree/node.js";export default (router,startIndex)=>{let str=``;for(let i=1;i<router.length;i+=2)str+=(str===``?`if(`:`else if(`)+`p==="`+router[i].slice(1-startIndex)+`"){`+router[i+1]+`}`;return str+(isEmptyNode(router[0])?``:`let l=p.length;`+compile(router[0],0,startIndex,``))};
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)+`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
+ export let compile=(node,paramCount,idx,idxPrefix)=>{let builder=``;let currentIdx=idxPrefix+idx;node[1]==null||(builder+=`if(l===`+currentIdx+`){`+node[1]+`}`);if(node[2]!=null)for(let i=0,children=Object.values(node[2]);i<children.length;i++){let childNode=children[i];let nodePath=childNode[0];let nextIdx=idx+nodePath.length;builder+=(childNode[1]==null?(i>0?`else if(`:`if(`)+`l>`+idxPrefix+nextIdx+`&&`:i>0?`else if(`:`if(`)+`p.startsWith("`+nodePath+`",`+currentIdx+`)){`+compile(childNode,paramCount,nextIdx,idxPrefix)+`}`}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]+`}`);if(hasChild){let childNode=params[0];let nodePath=childNode[0];builder+=(hasStore?`else if(`:`if(`)+`j>`+currentIdx+`){let q`+paramCount+`=p.slice(`+currentIdx+`,j);`+(childNode[1]==null?`if(l>j+`+nodePath.length+`)`:``)+(nodePath.length>1?`if(p.startsWith("`+nodePath.slice(1)+`",j+1)){`:`{`)+compile(childNode,paramCount+1,nodePath.length,`j+`)+`}}`}}node[4]==null||(builder+=`let q`+paramCount+`=`+(currentIdx===`0`?`p`:`p.slice(`+currentIdx+`)`)+`;`+node[4]);return builder};