Skip to content

Commit

Permalink
Merge pull request #34 from lengfangbing/feat-update
Browse files Browse the repository at this point in the history
Feat update
  • Loading branch information
冷方冰 authored Sep 20, 2020
2 parents 59e5efd + 3ec54b7 commit ec4dd4e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions router_test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
parseUrlQuery,
splitPath,
splitNewPath,
splitUrl
} from './utils/test/url_test.ts';

Expand Down
27 changes: 27 additions & 0 deletions utils/test/url_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,33 @@ export function splitPath(path: string){
}
return res;
}
export function splitNewPath(path: string){
const res = [];
let url = path.substring(1) || '/';
let i = 0;
while((i = url.indexOf('/')) >= 0){
const v = url.substring(0, i);
let j = 0;
if((j = v.indexOf(':')) >= 0){
res.push({key: '', paramsName: v.substring(j+1)});
}else if((j = v.indexOf('*')) >= 0){
res.push({key: '#', paramsName: v.substring(j+1)});
}else{
res.push(`/${v}`);
}
url = url.substring(i+1);
}
if(url.length){
if((i = url.indexOf(':')) >= 0){
res.push({key: '', paramsName: url.substring(i+1)});
}else if((i = url.indexOf('*')) >= 0){
res.push({key: '#', paramsName: url.substring(i+1)});
}else{
res.push(`/${url}`);
}
}
return res;
}
declare global{
interface Map<K,V>{
toObj: Function
Expand Down

0 comments on commit ec4dd4e

Please sign in to comment.