Skip to content

Commit 3e1af8c

Browse files
committed
Make attributes accessible
1 parent efa6414 commit 3e1af8c

File tree

3 files changed

+760
-760
lines changed

3 files changed

+760
-760
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,26 @@ import pathToRegexp "github.com/soongo/path-to-regexp"
2525
- **path** A string, array or slice of strings, or a regular expression with type *github.com/dlclark/regexp2.Regexp.
2626
- **tokens** An array to populate with tokens found in the path.
2727
- token
28-
- **name** The name of the token (`string` for named or `number` for index)
29-
- **prefix** The prefix character for the segment (e.g. `/`)
30-
- **delimiter** The delimiter for the segment (same as prefix or default delimiter)
31-
- **optional** Indicates the token is optional (`boolean`)
32-
- **repeat** Indicates the token is repeated (`boolean`)
33-
- **pattern** The RegExp used to match this token (`string`)
28+
- **Name** The name of the token (`string` for named or `number` for index)
29+
- **Prefix** The prefix character for the segment (e.g. `/`)
30+
- **Delimiter** The delimiter for the segment (same as prefix or default delimiter)
31+
- **Optional** Indicates the token is optional (`boolean`)
32+
- **Repeat** Indicates the token is repeated (`boolean`)
33+
- **Pattern** The RegExp used to match this token (`string`)
3434
- **options**
35-
- **sensitive** When `true` the regexp will be case sensitive. (default: `false`)
36-
- **strict** When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
37-
- **end** When `true` the regexp will match to the end of the string. (default: `true`)
38-
- **start** When `true` the regexp will match from the beginning of the string. (default: `true`)
39-
- **delimiter** The default delimiter for segments. (default: `'/'`)
40-
- **endsWith** Optional character, or list of characters, to treat as "end" characters.
41-
- **whitelist** List of characters to consider delimiters when parsing. (default: `nil`, any character)
35+
- **Sensitive** When `true` the regexp will be case sensitive. (default: `false`)
36+
- **Strict** When `true` the regexp allows an optional trailing delimiter to match. (default: `false`)
37+
- **End** When `true` the regexp will match to the end of the string. (default: `true`)
38+
- **Start** When `true` the regexp will match from the beginning of the string. (default: `true`)
39+
- **Delimiter** The default delimiter for segments. (default: `'/'`)
40+
- **EndsWith** Optional character, or list of characters, to treat as "end" characters.
41+
- **Whitelist** List of characters to consider delimiters when parsing. (default: `nil`, any character)
4242

4343
```go
4444
var tokens []pathToRegexp.Token
4545
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/foo/:bar", &tokens, nil))
4646
// regexp: ^\/foo\/([^\/]+?)(?:\/)?$
47-
// tokens: [{name:"bar", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"}}]
47+
// tokens: [{Name:"bar", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"}}]
4848
```
4949

5050
**Please note:** The `Regexp` returned by `path-to-regexp` is intended for ordered data (e.g. pathnames, hostnames). It can not handle arbitrarily ordered data (e.g. query strings, URL fragments, JSON, etc).
@@ -60,8 +60,8 @@ Named parameters are defined by prefixing a colon to the parameter name (`:foo`)
6060
```go
6161
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/:foo/:bar", nil, nil))
6262
// tokens: [
63-
// {name:"foo", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"},
64-
// {name:"bar", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"}
63+
// {Name:"foo", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"},
64+
// {Name:"bar", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"}
6565
// ]
6666

6767
match, err := regexp.FindStringMatch("/test/route")
@@ -83,8 +83,8 @@ Parameters can be suffixed with a question mark (`?`) to make the parameter opti
8383
```go
8484
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/:foo/:bar?", nil, nil))
8585
// tokens: [
86-
// {name:"foo", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"},
87-
// {name:"bar", prefix:"/", delimiter:"/", optional:true, repeat:false, pattern:"[^\\/]+?"}
86+
// {Name:"foo", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"},
87+
// {Name:"bar", Prefix:"/", Delimiter:"/", Optional:true, Repeat:false, Pattern:"[^\\/]+?"}
8888
// ]
8989

9090
match, err := regexp.FindStringMatch("/test")
@@ -110,7 +110,7 @@ Parameters can be suffixed with an asterisk (`*`) to denote a zero or more param
110110

111111
```go
112112
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/:foo*", nil, nil))
113-
// tokens: [{name:"foo", prefix:"/", delimiter:"/", optional:true, repeat:true, pattern:"[^\\/]+?"}]
113+
// tokens: [{Name:"foo", Prefix:"/", Delimiter:"/", Optional:true, Repeat:true, Pattern:"[^\\/]+?"}]
114114

115115
match, err := regexp.FindStringMatch("/")
116116
for _, g := range match.Groups() {
@@ -133,7 +133,7 @@ Parameters can be suffixed with a plus sign (`+`) to denote a one or more parame
133133

134134
```go
135135
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/:foo+", nil, nil))
136-
// tokens: [{name:"foo", prefix:"/", delimiter:"/", optional:false, repeat:true, pattern:"[^\\/]+?"}]
136+
// tokens: [{Name:"foo", Prefix:"/", Delimiter:"/", Optional:false, Repeat:true, Pattern:"[^\\/]+?"}]
137137

138138
match, err := regexp.FindStringMatch("/")
139139
fmt.Println(match)
@@ -154,8 +154,8 @@ It is possible to write an unnamed parameter that only consists of a matching gr
154154
```go
155155
regexp := pathToRegexp.Must(pathToRegexp.PathToRegexp("/:foo/(.*)", nil, nil))
156156
// tokens: [
157-
// {name:"foo", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"},
158-
// {name:0, prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:".*"}
157+
// {Name:"foo", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"},
158+
// {Name:0, Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:".*"}
159159
// ]
160160

161161
match, err := regexp.FindStringMatch("/test/route")
@@ -172,7 +172,7 @@ All parameters can have a custom regexp, which overrides the default match (`[^/
172172

173173
```go
174174
regexpNumbers := pathToRegexp.Must(pathToRegexp.PathToRegexp("/icon-:foo(\\d+).png", nil, nil))
175-
// tokens: {name:"foo", prefix:"-", delimiter:"-", optional:false, repeat:false, pattern:"\\d+"}
175+
// tokens: {Name:"foo", Prefix:"-", Delimiter:"-", Optional:false, Repeat:false, Pattern:"\\d+"}
176176

177177
match, err := regexpNumbers.FindStringMatch("/icon-123.png")
178178
for _, g := range match.Groups() {
@@ -185,7 +185,7 @@ fmt.Println(match)
185185
//=> nil
186186

187187
regexpWord := pathToRegexp.Must(pathToRegexp.PathToRegexp("/(user|u)", nil, nil))
188-
// tokens: {name:0, prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"user|u"}
188+
// tokens: {Name:0, Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"user|u"}
189189

190190
match, err = regexpWord.FindStringMatch("/u")
191191
for _, g := range match.Groups() {
@@ -211,10 +211,10 @@ fmt.Printf("%#v\n", tokens[0])
211211
//=> "/route"
212212

213213
fmt.Printf("%#v\n", tokens[1])
214-
//=> pathToRegexp.Token{name:"foo", prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:"[^\\/]+?"}
214+
//=> pathToRegexp.Token{Name:"foo", Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:"[^\\/]+?"}
215215

216216
fmt.Printf("%#v\n", tokens[2])
217-
//=> pathToRegexp.Token{name:0, prefix:"/", delimiter:"/", optional:false, repeat:false, pattern:".*"}
217+
//=> pathToRegexp.Token{Name:0, Prefix:"/", Delimiter:"/", Optional:false, Repeat:false, Pattern:".*"}
218218
```
219219

220220
**Note:** This method only works with strings.

0 commit comments

Comments
 (0)