88
99## sample
1010
11- ``` js
11+ ``` ts
1212import Parth from ' parth' ;
1313
1414const parth = new Parth ();
15- var props = {handle : function (){} };
15+ const props = { handle : () : void => {} };
1616
1717parth .set (' (get|post) /:page/:view' , props )
1818 .get (' get /weekend/baby?query=string#hash user.10.beers now' )
@@ -37,22 +37,22 @@ parth.set('(get|post) /:page/:view', props)
3737
3838Parth exports a ` Parth ` class (default export)
3939
40- ``` js
40+ ``` ts
4141import Parth from ' parth' ;
4242```
4343
4444which can take the options below
4545
46- ``` js
47- var parth = new Parth (options);
46+ ``` ts
47+ const parth = new Parth (options );
4848```
4949
5050_ options_ type ` object ` , can be
5151 - ` options.defaultRE ` default ` regex ` used if none is given after the params
5252
5353example:
5454
55- ``` js
55+ ``` ts
5656const parth = new Parth ({ defaultRE: / [^ \s \/ ?#] + / });
5757
5858parth .set (' /page/:view' ) // no regex given after ":view"
@@ -77,8 +77,8 @@ parth.set('/page/:view') // no regex given after ":view"
7777
7878## parth.set
7979
80- ``` js
81- function set (string path [, object options ])
80+ ``` ts
81+ parth . set (path , options ); // (path: string, options?: object) => this
8282```
8383This method job is to sanitize ` path ` and order it with those previously stored.
8484
@@ -91,20 +91,21 @@ _returns_ `this`
9191> NOTE: ` options ` is deep cloned beforehand to avoid mutation
9292
9393` path ` can contain any number of parameters(regexes) in the form
94- ```js
95- :param-label(\\regexp(?:here))
94+ ``` ts
95+ ' :param-label(\\ regexp(?:here))'
9696```
9797Any string matching the regular expression below qualifies as a parameter
9898
99- ````js
100- /:([-\w]+)(\([^\s]+?[)][?)]*)?/g;
101- ````
99+ ``` ts
100+ const paramRE = / :([-\w ] + )(\( [^ \s ] +? [)][?)] * )? / g ;
101+ ```
102102
103103[ Go to http://regexr.com/ ] ( http://regexr.com/3cuqq ) and test it out.
104104
105105## parth.get
106- ```js
107- function get(string path)
106+
107+ ``` ts
108+ parth .get (path ); // (path: string) => ParthResult | null
108109```
109110
110111Take a string and return a clone of the store object properties
@@ -140,25 +141,6 @@ With [npm](http://npmjs.org)
140141
141142 npm install --save parth
142143
143- ### examples
144-
145- Run the [ ` example.ts ` ] ( example.ts ) file: ` npx tsx example.ts ` (or ` npm run dist ` then run with Node after changing the import to ` ./dist ` ).
146-
147- ### test
148-
149- npm test
150-
151- ```
152- ➜ parth npm test
153- PASS test/paths.test.ts
154- PASS test/params.test.ts
155- PASS test/options.test.ts
156- PASS test/notFound.test.ts
157-
158- Test Suites: 4 passed, 4 total
159- Tests: 20 passed, 20 total
160- ```
161-
162144### license
163145
164146The MIT License (MIT)
0 commit comments