ureal
v0.1.0
Published
urls are serialised data structures; this library lets you treat them that way
Downloads
1
Readme
Urls are, at their heart, serialised data-structures. They're really awkward to work with, and everyone in the web-world has seen god-awful regex hacks in one project or another. We don't use string manipulation on JSON, though; so why subject ourselves to it for urls?
API
ureal.parse(url) -> object
Like JSON.parse
, ureal.parse
takes a string (a url), and turns it into a userful datastructure. For instance:
ureal.parse('https://user:[email protected]/profile?edit=email')
Returns:
{ protocol: 'https',
user: 'user',
password: 'password',
domain: 'secure.my-site.com',
path: [ 'profile' ],
params: { edit: 'email' } }
ureal.stringify(object) -> url
ureal.stringify
takes an object in the same format as ureal.parse
emits, and constructs a url out of it:
ureal.stringify({ protocol: 'https',
user: 'user',
password: 'password',
domain: 'secure.my-site.com',
path: [ 'profile' ],
params: { edit: 'email' } })
Returns:
'https://user:[email protected]/profile?edit=email'
```g