super-url-path
A super library for formatting URL paths, similar to TS static grammar detection.
Install
npm i super-url-path
Usage
Usually it is used in this way:
const SuperUrlPath = ;const uri = '/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}';console;console
Variable Grammar
it likes typescript:
abc: string# or abc?: string
You should use it like this:
/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}
uri.router(options)
create a new url by options.
uri)
uri.match(url)
Judging whether URL conforms to the rules. it returns a boolean value.
uri; // true or false
uri.exec(url)
Get the value of the variable from the rule and return a JSON data format
const SuperUrlPath = ;const uri = '/abc/des/abc-d_:{abc:string}*x--a{cde?:number}-d/test{value:string}';console;// => { abc: 'dista', cde: '123', value: 'dd' }
Add custom data format
use SuperUrlPath.addType(name, regexp_string)
- name
string
the datatype name. - regexp_string
string
a String Regular Expression.
const SuperUrlPath = ;SuperUrlPath;// then you can use like thisconst uri = '/interface/api/user/custom_{user: user_id}/{id: number}';
License
super-url-path
is MIT licensed.