Parse all kinds of urls, simple or otherwise. Returns a modifiable JSON object that can be converted to a string.
Primary goal: Keep urls modifiable, without worrying about anything else. Allow for modifying urls, and generating a neat url with accomodated changes.
Often you might be parsing urls, modifying some parameter using strings,
and the whole system looks messy.
seeks to solve that problem. Just give it a string, which is converted
into JSON modifiable form. Mess up any way you want to with the parameters,
playing around with the params, and just call a
Url.toString() to get your modified url.
Now you don't need to worry about
urlparamify has got you covered.
One of the legit feedbacks I received on reddit was how is this module any different from the core url module ?
Unlike the core
urlparamify accepts any kind of url like mentioned
url works only when a url of the format
provided. I started off working on a task with
url itself, but the multiple
fallacies in url (url.parse('http://google.com') for instance, along with
multiple urls mentioned in this test suite) and other interactions suggested me
to make a url suited to these requirements. An instance of this module's sturdiness
can be seen in Usage and examples below.
Find a url that breaks this module ? Let me know.
$ npm install urlparamify
Each url is broken down into the following components:
href: The original input string
protocol: http / https request protocol
host: what website / localhost ip,port combination
baseurl: The base url of the url to be queried.
path: Path section of the URL
query: The query part of the url, unaltered
queryParams: A json object to modify/add to your query
Apart from this, each url object has the following functions:
getBaseurl(): Get the latest baseurl parameter
toString(): Convert our url object into a neatly formatted string.
Usage and examples
> var Url = ;> var h = ;> hhref: 'http://google.com/path1/?q=data&d=sad#hash'protocol: 'http'host: 'google.com'baseurl: 'http://google.com'path: 'path1'query: 'q=data&d=sad'queryParams: q: 'data' d: 'sad'hash: 'hash'getBaseurl: FunctiontoString: Function> h;'http://google.com/path1?q=data&d=sad#hash'// let's put a smile on that face> hqueryParamsd = 'happy';> h;'http://google.com/path1?q=data&d=happy#hash'// let's try adding new query parameters> hqueryParamsnew = 'wow';> h;'http://google.com/path1?q=data&d=happy&new=wow#hash'// I don't like hashtags. Get rid of it> hhash = "";> h;'http://google.com/path1?q=data&d=sad&new=wow'// But what if I want to add things that were never there to begin with ?// With urlparamify, you can not only modify, but also add new parameters with ease> var g => g'google.com'> gpath = 'somepath'> g'google.com/somepath'> gqueryParamssearch = 'data'> g'google.com/somepath?search=data'
npm test npm run cover istanbul cover test/test.js // The results are stored in coverage/
The source files are in
src, and the distribution files are in
dist. Transpiled the code for ease.
A little reminder for myself: When ready to deploy, at a clean git history,
npm version patch -m "Version %s - add sweet badges" major.minor.patch : 1.1.0
If you want to publish your own module, this article on Medium is a great place to start.
MIT © Kaustubh Hiware