jQuery URL Decoder Plugin
Parses URL and return its components. Can also build URL from components.
Current version: 1.0
License: MIT License
Download
- Minified (5KB)
- Uncompressed (11KB)
How to use
$.url.decode('http://username:password@hostname/path?arg1=value%40+1&arg2=touch%C3%A9#anchor')
// returns
// http://username:password@hostname/path?arg1=value@ 1&arg2=touché#anchor
// Note: "%40" is replaced with "@", "+" is replaced with " " and "%C3%A9" is replaced with "é"
$.url.encode('file.htm?arg1=value1 @#456&arg2=value2 touché')
// returns
// file.htm%3Farg1%3Dvalue1%20%40%23456%26arg2%3Dvalue2%20touch%C3%A9
// Note: "@" is replaced with "%40" and "é" is replaced with "%C3%A9"
$.url.parse('http://username:password@hostname/path?arg1=value%40+1&arg2=touch%C3%A9#anchor')
// returns
{
source: 'http://username:password@hostname/path?arg1=value%40+1&arg2=touch%C3%A9#anchor',
protocol: 'http',
authority: 'username:password@hostname',
userInfo: 'username:password',
user: 'username',
password: 'password',
host: 'hostname',
port: '',
path: '/path',
directory: '/path',
file: '',
relative: '/path?arg1=value%40+1&arg2=touch%C3%A9#anchor',
query: 'arg1=value%40+1&arg2=touch%C3%A9',
anchor: 'anchor',
params: {
'arg1': 'value@ 1',
'arg2': 'touché'
}
}
$.url.build({
protocol: 'http',
username: 'username',
password: 'password',
host: 'hostname',
path: '/path',
query: 'arg1=value%40+1&arg2=touch%C3%A9',
// or
//params: {
// 'arg1': 'value@ 1',
// 'arg2': 'touché'
//}
anchor: 'anchor',
})
// returns
// http://username:password@hostname/path?arg1=value%40+1&arg2=touch%C3%A9#anchor
Demo
$.url.decode
$.url.encode
$.url.parse
(this output of $.url.parse is JSON-encoded and tab-formatted here) |
$.url.build
|
(this input for $.url.build will evaluate as javascript object) |