Miuri is simple JavaScript class for parsing URIs. It's designed to be used in browser, but it can be used as a NodeJS module.
It can retrieve information:
miuri = require('miuri.js') // when run on Node.js
uri = new miuri('http://google.com')
uri.hostname() // google.com
uri.protocol() // http
uri.path() // /
Also from URIs with complex queries:
uri = new miuri('/?test=foo&arr[]=1&arr[]=2&data[name]=bar')
uri.query('test') // foo
uri.query('arr') // [1, 2]
uri.query('data') // {name: 'bar'}
uri.query() // {test: 'foo', arr: [1, 2], name: 'bar'}
With Miuri you can build full URIs:
uri = new miuri()
uri.hostname('bing.com')
.protocol('http')
.path('search')
.query({
s: 'my test'
})
.toString() // http://bing.com/search?s=my%20test
An alias fo host()
Returns object with path details:
dirname
basename
extension
filename
Example for url http://google.com/path/to/file.txt
:
{
"dirname": "/path/to",
"basename": "file.txt",
"extension": "txt",
"filename": "file"
}
Miuri is released under a MIT License.