0.1.2 • Published 8 years ago
smart-url v0.1.2
SmartUrl
Provides Url object with parsing from string
Usage
var SmartUrl = require('smart-url').SmartUrl
var smartUrl = SmartUrl.parse('https://test.com:5000/path?a=2&b=3#hash');The smartUrl object contains next properties:
scheme: The scheme of the URL (e.g.https).host: Host name (e.g.test.com).port: Port (e.g.5000).pathname: URL path (e.g.path).query: Object with query parameters (e.g.a=2&b=3).fragment: fragment part (hash), which start from#(e.g.hash).
Note that all url parts except fragment is read-only. Also you can change query by smartUrl object methods
Fragment methods
You can set fragment part or remove it
var smartUrl = SmartUrl.parse('https://test.com#hash')
//smartUrl.fragment is 'hash'
smartUrl.fragment = 'newHash'
//smartUrl.fragment is 'newHash'
smartUrl.removeFragment()
//smartUrl.fragment is nullQuery methods
You can set fragment part or remove it
var smartUrl = SmartUrl.parse('https://test.com?a=2&b=xyz')
//smartUrl.query is {a:'2', b:'xyz'}
smartUrl.addToQuery('b', 3.14)
//smartUrl.query is {a:'2', b:'3.14'}
smartUrl.removeFromQuery('b')
//smartUrl.query is {a:'2'}
smartUrl.addToQuery('c', 3.14)
//smartUrl.query is {a:'2', c:'3.14'}