Skip to content

radmen/miuri.js

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
src
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

miuri.js

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

API reference

protocol([protocol])

username([username])

password([password])

host([host])

hostname([host])

An alias fo host()

port([port])

path([path])

query([prop, [value]])

fragment([fragment])

pathinfo()

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"
}

toString()

License

Miuri is released under a MIT License.