2.1.0 • Published 5 years ago
extra-url v2.1.0
extra-url
An extension of the builtin url
module.
url.parse('http://user:pass@host.com:8080/p/a/t/h/file.txt?query=string%21#hash', true /* fix? -> fix half-urls */);
/*STANDARD:
┌─────────────────────────────────────────────────────────────────────────────┐
│ href │
├──────────┬┬───────────┬─────────────────┬───────────────────────────┬───────┤
│ protocol ││ auth │ host │ path │ hash │
│ ││ ├──────────┬──────┼──────────┬────────────────┤ │
│ ││ │ hostname │ port │ pathname │ search │ │
│ ││ │ │ │ ├─┬──────────────┤ │
│ ││ │ │ │ │ │ query │ │
" http: // user:pass @ host.com : 8080 /p/a/t/h ? query=string #hash "
│ ││ │ │ │ │ │ │ │
└──────────┴┴───────────┴──────────┴──────┴──────────┴─┴──────────────┴───────┘
*/ //EXTENDED:
Url {
hrefraw: 'http://user:pass@host.com:8080/p/a/t/h/file.txt?query=string%21#hash',
href: 'http://user:pass@host.com:8080/p/a/t/h/file.txt?query=string!#hash',
protocolfull: 'http://',
protocolraw: 'http:',
protocol: 'http',
auth: 'user:pass',
autharr: [ 'user', 'pass' ],
hostfull: 'user:pass@host.com:8080',
authhost: 'user:pass@host.com',
host: 'host.com:8080',
hostname: 'host.com',
port: '8080',
pathraw: '/p/a/t/h/file.txt?query=string%21',
path: '/p/a/t/h/file.txt?query=string!',
pathnameraw: '/p/a/t/h/file.txt',
pathname: '/p/a/t/h/file.txt',
searchraw: '?query=string%21',
search: '?query=string!',
querystringraw: 'query=string%21',
querystring: 'query=string!',
queryarrrawdeep: [ [ 'query', 'string%21' ] ],
queryarrraw: [ 'query=string%21' ],
queryarrdeep: [ [ 'query', 'string!' ] ],
queryarr: [ 'query=string!' ],
queryraw: { query: 'string!' },
query: { query: 'string!' },
directoryraw: '/p/a/t/h',
directory: '/p/a/t/h',
filepureraw: '/file.txt',
filepure: '/file.txt',
fileraw: 'file.txt',
file: 'file.txt',
filenameraw: 'file',
filename: 'file',
extensionfull: '.txt',
extension: 'txt',
hashraw: '#hash',
hash: '#hash',
hashnameraw: 'hash',
hashname: 'hash',
pathobject:
{ root: '/',
dir: '/p/a/t/h',
base: 'file.txt',
ext: '.txt',
name: 'file' },
toString: [Function: toString],
slashes: true,
_revoke: [Function: revoke] }
*/
By editing one of the properties of the Url object returned by url.parse, the whole object gets rebuilt to adjust on the change!