@@ -38,109 +38,15 @@ This package was originally made to work with [react-router-magic](https://githu
3838> Note : If you use Typescript, typings are include in the package !
3939
4040``` js
41- import { PathPattern } from ' path-pattern' ;
41+ import { createPattern } from ' path-pattern' ;
4242```
4343
4444### Node
4545
4646``` js
47- const PathPattern = require (' path-pattern' ).PathPattern ;
47+ const createPattern = require (' path-pattern' ).createPattern ;
4848```
4949
50- ## Usage
51-
52- ### Basic example
53-
54- ``` js
55- import { PathPattern } from ' path-pattern' ;
56-
57- // let's create a simple pattern
58- const homePattern = new PathPattern (' /home' );
59-
60- // test if the path match with a location
61- homePattern .match ({ pathname: ' /home' })
62- // => { path: '/home', url: '/home', isExact: true, params: {} }
63-
64- // match only the start of the path :
65- homePattern .match ({ pathname: ' /home/hello' })
66- // => { path: '/home', url: '/home', isExact: false, params: {} }
67-
68- // you can use matchExact to match only exact path
69- homePattern .matchExact ({ pathname: ' /home' })
70- // => { path: '/home', url: '/home', isExact: true, params: {} }
71-
72- homePattern .matchExact ({ pathname: ' /home/hello' })
73- // => false
74-
75- // You can get a path from a pattern with compile
76- // this is more useful when parameters are envolved (see bellow)
77- homePattern .compile ()
78- // => '/home'
79- ```
80-
81- ### Pattern with parameters
82-
83- ``` js
84- import { PathPattern } from ' path-pattern' ;
85-
86- // A pattern with params
87- const userPattern = new PathPattern (' /user/:user' );
88-
89- userPattern .match ({ pathname: ' /user' })
90- // => false
91-
92- userPattern .match ({ pathname: ' /user/john' })
93- // => { path: '/user/:user', url: '/user/john', isExact: true, params: { user: 'john' } }
94-
95- // you can pass params value to compile it
96- userPattern .compile ({ user: ' john' })
97- // => '/user/john'
98- ```
99-
100- ### Inherited pattern
101-
102- ``` js
103- import { InheritedPathPattern } from ' path-pattern' ;
104-
105- // A pattern that inherite from another
106- const pagePattern = new InheritedPathPattern (homePattern, ' /:page' );
107-
108- pagePattern .match ({ pathname: ' /home/hello' })
109- // => { path: '/home/:page', url: '/home/hello', isExact: true, params: { page: 'hello' } }
110-
111- // compile works as expected
112- pagePattern .compile ({ page: ' yolo' })
113- // => '/home/yolo'
114-
115- ```
116-
117- ## API
118-
119- ### ` Matcher ` (type)
120-
121- > ` (location: Location) => Match; `
122-
123- A matcher is a function that take a location (a string or a [ https://github.com/ReactTraining/history ] (Location object)) and return a Match object or false.
124-
125- ### ` Match ` (type)
126-
127- > ` false | { params, isExact, path, url } `
128-
129- An object that represent the result of a ` Matcher ` . If the path doesn't match it's false, if it does it's an object.
130-
131- ### ` PathPattern `
132-
133- #### - ` constructor(pattern: string) `
134-
135- #### - ` matchAdvanced(options): Matcher `
136-
137- - ` options ` : Object ` { exact?: boolean; strict?: boolean; } `
138- - ` returns ` : A ` Matcher ` function
139-
140- #### - ``
141-
142- ####
143-
14450## Versioning
14551
14652We use [ SemVer] ( http://semver.org/ ) for versioning. For the versions available, see the [ releases on this repository] ( https://github.com/Realytics/path-pattern/releases ) .
0 commit comments