@mapl/router 0.0.7 → 0.0.8
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/index.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export function createRouter(){return[null,null]}export function insertItem(router,path,item){if(path.includes("*"))nodeInsertItem(router[1]??=createNode("/"),path,item);else(router[0]??={})[path]=item}export function compileRouter(router,state){const contentBuilder=state.contentBuilder;
|
|
1
|
+
export function createRouter(){return[null,null]}export function insertItem(router,path,item){if(path.includes("*"))nodeInsertItem(router[1]??=createNode("/"),path,item);else(router[0]??={})[path]=item}export function compileRouter(router,state){const contentBuilder=state.contentBuilder;const hasStatic=router[0]!==null;if(hasStatic){const staticMap=router[0];let hasMultiple=false;for(const key in staticMap){contentBuilder.push(`${hasMultiple?"else ":""}if(${PATH}===${JSON.stringify(key.slice(1))}){`);state.compileItem(staticMap[key],state,false);contentBuilder.push("}");hasMultiple=true}}if(hasStatic)contentBuilder.push("else{");contentBuilder.push(`const ${PATH_LEN}=${PATH}.length;`);if(router[1]!==null)compileNode(router[1],state,false,false,-1,"");if(hasStatic)contentBuilder.push("}")}import{PATH,PATH_LEN}from"./constants.js";import{compileNode}from"./tree/compiler.js";import{createNode,insertItem as nodeInsertItem}from"./tree/node.js";
|