@mapl/router 0.3.2 → 0.3.4
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 +1 -1
- package/quick-match.d.ts +2 -0
- package/quick-match.js +1 -0
- package/tree/matcher.d.ts +1 -1
- package/tree/matcher.js +1 -1
package/package.json
CHANGED
package/quick-match.d.ts
ADDED
package/quick-match.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default (pattern,path)=>{let params=[];let offset=-1;for(let i=1,tmp;i<pattern.length;i++){tmp=pattern.charCodeAt(i);if(pattern.charCodeAt(i)===42){if(i===pattern.length-1){if(path.includes("/",i+offset))return null;params.push(path.slice(i+offset));return params}if(pattern.charCodeAt(i+1)===47){tmp=path.indexOf("/",i+offset);if(tmp===-1)return null;params.push(path.slice(i+offset,tmp));offset+=tmp-(i+offset)-1;continue}params.push(path.slice(i+offset));return params}if(tmp!==path.charCodeAt(i+offset))return null}return offset+pattern.length===path.length?params:null};
|
package/tree/matcher.d.ts
CHANGED
|
@@ -2,5 +2,5 @@ import type { Node } from './node.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Match a pathname and returns the result
|
|
4
4
|
*/
|
|
5
|
-
declare const f: (node: Node<unknown>, path: string, params: string[], start: number
|
|
5
|
+
declare const f: (node: Node<unknown>, path: string, params: string[], start: number) => unknown;
|
|
6
6
|
export default f;
|
package/tree/matcher.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let f=(node,path,params,start
|
|
1
|
+
let f=(node,path,params,start)=>{let part=node[0];let tmp=part.length;if(tmp!==1&&(start+tmp>path.length||path.indexOf(part,start)!==start))return null;start+=tmp;if(start===path.length&&node[1]!==null)return node[1];if(node[2]!==null){tmp=node[2][path.charCodeAt(start)];if(typeof tmp!=="undefined"){tmp=f(tmp,path,params,start);if(tmp!==null)return tmp}}if(node[3]!==null){tmp=path.indexOf("/",start);if(tmp===-1){if(node[3][1]!==null){params.push(path.substring(start));return node[3][1]}}else if(tmp!==start&&node[3][0]!==null){params.push(path.substring(start,tmp));tmp=f(node[3][0],path,params,tmp);if(tmp!==null)return tmp;params.pop()}}if(node[4]!==null){params.push(path.substring(start));return node[4]}return null};export default f;
|