File tree 3 files changed +27
-7
lines changed
3 files changed +27
-7
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+ const { parse } = require ( 'url' ) ;
2
+ const UrlPattern = require ( 'url-pattern' ) ;
3
+
4
+ const patternOpts = {
5
+ segmentNameCharset : 'a-zA-Z0-9_-'
6
+ } ;
7
+
8
+ const isPattern = pattern => pattern instanceof UrlPattern ;
9
+
10
+ const getParamsAndQuery = ( pattern , url ) => {
11
+ const { query, pathname } = parse ( url , true ) ;
12
+ const route = isPattern ( pattern ) ? pattern : new UrlPattern ( pattern , patternOpts ) ;
13
+ const params = route . match ( pathname ) ;
14
+
15
+ return { query, params } ;
16
+ } ;
17
+
18
+ module . exports = {
19
+ getParamsAndQuery,
20
+ isPattern,
21
+ patternOpts
22
+ } ;
Original file line number Diff line number Diff line change 2
2
"name" : " microrouter" ,
3
3
"description" : " 🚉 A tiny and functional router for ZEIT's Micro" ,
4
4
"version" : " 3.1.0" ,
5
- "main" : " dist/index.js" ,
6
- "jsnext:main" : " lib/index.js" ,
5
+ "main" : " dist/lib/ index.js" ,
6
+ "jsnext:main" : " src/ lib/index.js" ,
7
7
"scripts" : {
8
8
"release" : " np" ,
9
9
"lint" : " eslint ./src/**/*.js" ,
10
- "build" : " yarn lint && rm -rf dist/* && babel src/lib --ignore *.test.js --out-dir dist --copy-files" ,
10
+ "build" :
11
+ " yarn lint && rm -rf dist/* && babel src --ignore *.test.js --out-dir dist --copy-files" ,
11
12
"test" : " nyc ava" ,
12
13
"coverage" : " nyc report --reporter=text-lcov | coveralls" ,
13
14
"format" : " yarn lint && prettier --write \" src/**/*.js\" "
40
41
"node" : " >=6.10.0"
41
42
},
42
43
"lint-staged" : {
43
- "src/**/*.js" : [
44
- " yarn format" ,
45
- " git add"
46
- ]
44
+ "src/**/*.js" : [" yarn format" , " git add" ]
47
45
},
48
46
"husky" : {
49
47
"pre-commit" : " lint-staged && npm test"
You can’t perform that action at this time.
0 commit comments