-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
108 lines (90 loc) · 1.81 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const calc = require('./index')
const pathToRegexp = require('path-to-regexp');
var ori = [
'*',
"/:id",
"/a/b/c",
"/e/:id/f",
"/e/adf:id/f",
"/e/adf:id/f/asdf/asdf",
"/e/adf:id/f3434",
"/:f0/:f1/:f2",
"/a/:d/m",
"/a/:e",
"/a/e/*",
]
for (let i = 0; i < ori.length; i++) {
const path = ori[i];
const r = path.split('/')
// console.log(r, calc(path))
// [ '*' ] 100
// [ '', ':id' ] 19
// [ '', 'a', 'b', 'c' ] 11.11
// [ '', 'e', ':id', 'f' ] 11.91
// [ '', 'e', 'adf:id', 'f' ] 11.6661
// [ '', ':f0', ':f1', ':f2' ] 19.99
// [ '', 'a', ':d', 'm' ] 11.91
// [ '', 'a', ':e' ] 11.9
// [ '', 'a', 'e', '*' ] 11.2
}
ori = [
'*',
"/:id",
"/:page?",
"/:page?/sfdsd",
"/:page+",
"/:page+/fsd/er",
"/:page*",
"/:page*/werw/yu",
"/:page/:fsdf",
"/:page/fsdf"
]
for (let i = 0; i < ori.length; i++) {
const path = ori[i];
const r = path.split('/')
console.log(r, calc(path))
// [ '*' ] 100
// [ '', ':id' ] 19
// [ '', ':page?' ] 19.7
// [ '', ':page+' ] 19.8
// [ '', ':page*' ] 19.9
// [ '', ':page', 'fsdf' ] 19.1
}
ori = [
'*',
'/*',
"/:foo/(.*)",
]
for (let i = 0; i < ori.length; i++) {
const path = ori[i];
const r = path.split('/')
// console.log(r, calc(path))
// [ '*' ] 100
// [ '', '*' ] 20
// [ '', ':foo', '(.*)' ] 19.1
}
ori = [
'*',
"/:id",
"/:page?",
"/:page+",
"/:page*",
"/:icon(\\d+)"
]
for (let i = 0; i < ori.length; i++) {
const path = ori[i];
const r = path.split('/')
// console.log(r, calc(path))
// [ '*' ] 100
// [ '', ':id' ] 19
// [ '', ':page?' ] 19
// [ '', ':page+' ] 19
// [ '', ':page*' ] 19
// [ '', ':icon(\\d+)' ] 19
}
var re = pathToRegexp('/:foo+')
let a = re.exec('/')
let b = re.exec('/a')
let c = re.exec('/a/a')
let d = re.exec('/a/a/sdf')
// console.log(a, b, c, d)