1
1
# url-pattern
2
2
3
- [ ![ Build Status] ( https://travis-ci.org/snd/url-pattern.png )] ( https://travis-ci.org/snd/url-pattern )
3
+ [ ![ NPM Package] ( https://img.shields.io/npm/v/url-pattern.svg?style=flat )] ( https://www.npmjs.org/package/url-pattern )
4
+ [ ![ Build Status] ( https://travis-ci.org/snd/url-pattern.svg?branch=master )] ( https://travis-ci.org/snd/url-pattern/branches )
5
+ [ ![ Dependencies] ( https://david-dm.org/snd/url-pattern.svg )] ( https://david-dm.org/snd/url-pattern )
4
6
5
- url-pattern is easy pattern matching and segment extraction for
6
- urls, domains, filepaths and any string composed of segments joined
7
- by a separator character
7
+ > url-pattern is easy pattern matching and segment extraction for
8
+ > urls, domains, filepaths and any string composed of segments joined
9
+ > by a separator character
8
10
9
11
[ check out ** passage** if you are looking for simple composable routing that builds on top of url-pattern] ( https://github.com/snd/passage )
10
12
11
- - [ install] ( #install )
12
- - [ require] ( #require )
13
- - [ match urls or filepaths] ( #match-urls-or-filepaths )
14
- - [ match domains] ( #match-domains )
15
- - [ license] ( #license-mit )
16
-
17
- ### install
18
-
19
13
```
20
14
npm install url-pattern
21
15
```
22
16
23
- ** or**
24
-
25
- put this line in the dependencies section of your ` package.json ` :
26
-
27
- ```
28
- "url-pattern": "0.6.0"
29
- ```
30
-
31
- then run:
32
-
33
- ```
34
- npm install
35
- ```
36
-
37
- ### require
17
+ require with commonjs:
38
18
39
19
``` javascript
40
- var urlPattern = require (' url-pattern' );
20
+ var Pattern = require (' url-pattern' );
41
21
```
42
22
23
+ [ lib/url-pattern.js] ( lib/url-pattern.js ) can be used in the browser.
24
+ it supports AMD as well.
25
+
43
26
### match urls or filepaths
44
27
45
28
##### make pattern from string
46
29
47
30
``` javascript
48
- var pattern = urlPattern . newPattern (' /users/:id' );
31
+ var pattern = new Pattern (' /users/:id' );
49
32
```
50
33
51
34
the default separator is ` / ` . you can pass a custom separator
52
- as the second argument to ` newPattern ` .
35
+ as the second argument.
53
36
54
37
##### match pattern against url
55
38
@@ -63,7 +46,7 @@ pattern.match('/projects/5'); // => null
63
46
##### make pattern from regex
64
47
65
48
``` javascript
66
- var regexPattern = urlPattern . newPattern (/ \/ test\/ (. * )/ );
49
+ var regexPattern = new Pattern (/ \/ test\/ (. * )/ );
67
50
```
68
51
69
52
##### match regex pattern against url
@@ -78,7 +61,7 @@ regexPattern.match('/users/test'); // => null
78
61
##### make wildcard pattern from string
79
62
80
63
``` javascript
81
- var wildcardPattern = urlPattern . newPattern (' */users/:id/*' );
64
+ var wildcardPattern = new Pattern (' */users/:id/*' );
82
65
```
83
66
84
67
##### match wildcard pattern against url
@@ -93,7 +76,7 @@ wildcardPattern.match('/api/v1/users/10/followers/20');
93
76
##### make optional pattern from string
94
77
95
78
``` javascript
96
- var optionalPattern = urlPattern . newPattern (' (/)users(/:foo)/bar(/*)' );
79
+ var optionalPattern = new Pattern (' (/)users(/:foo)/bar(/*)' );
97
80
```
98
81
99
82
##### match optional pattern against url
@@ -116,7 +99,7 @@ optionalPattern.match('/users/biff/bar/beep/boop');
116
99
##### make pattern from string
117
100
118
101
``` javascript
119
- var pattern = urlPattern . newPattern (' :sub.google.com' , ' .' );
102
+ var pattern = new Pattern (' :sub.google.com' , ' .' );
120
103
```
121
104
122
105
the default separator is ` / ` . you can pass a custom separator
@@ -149,7 +132,7 @@ regexPattern.match('google.com'); // => null
149
132
##### make wildcard pattern from string
150
133
151
134
``` javascript
152
- var wildcardPattern = urlPattern . newPattern (' *.:sub.google.*' );
135
+ var wildcardPattern = new Pattern (' *.:sub.google.*' );
153
136
```
154
137
155
138
##### match wildcard pattern against url
@@ -161,4 +144,4 @@ wildcardPattern.match('subsub.www.google.com');
161
144
// => {sub: 'www', _: ['subsub', 'com']}
162
145
```
163
146
164
- ### license: MIT
147
+ ## [ license: MIT] ( LICENSE )
0 commit comments