betturl
v0.3.0
Published
Better URL handling
Downloads
13
Readme
betturl
Better URL handling
Installation
npm install betturl
Usage
var betturl = require('betturl');
var parsed = betturl.parse('http://someurl.com');
// do something with parsed
Methods
betturl.parse(url, options = {})
Parse a URL.
The simplest form of this works very similar to the URL module from the node.js core.
> betturl.parse('http://www.google.com');
{
url: 'http://www.google.com', // the original url parsed
protocol: 'http',
host: 'www.google.com',
port: 80,
path: '/',
query: '',
hash: ''
}
betturl will also parse more complex URLs, like connection URLs, and infer the types of variables in the querystring.
> betturl.parse('mongodb://matt.insler%40gmail.com:[email protected]:6000,4.3.2.1:8000/database-123?auto_reconnect=true&namespace=foo&timeout=3000');
{
url: 'mongodb://matt.insler%40gmail.com:[email protected]:6000,4.3.2.1:8000/database-123?auto_reconnect=true&namespace=foo&timeout=3000',
protocol: 'mongodb',
hosts: [
{ host: '1.2.3.4', port: 6000 },
{ host: '4.3.2.1', port: 8000 }
],
path: '/database-123',
query: {
auto_reconnect: true,
namespace: 'foo',
timeout: 3000
},
hash: '',
auth: {
user: '[email protected]',
password: 'foobar'
}
}
Options
- parse_query Should the querystring be parsed into typed fields. By setting this to false, the query property will be a string. Accepted values: true, false Default: true
License
Copyright (c) 2012 Matt Insler
Licensed under the MIT license.