Day 27: Working on urlparamify

< 1 min read    29 May 2017    

So, the day [rather the midnight] begins with extensively working on urlparamify, which is used for url manipulation and rebuilding.

Will be working on this for a while now. I’ve extensively added some more params to query. Have a look. :P

Usage details:

> var Url = require('urlparamify');
> var h = Url('http://google.com/path1?q=data&d=sad#hash');

> h
{ href: '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: [Function],
toString: [Function] }

> h.toString();
'http://google.com/path1?q=data&d=sad#hash'

// let's put a smile on that face
> h.queryParams.d = 'happy';
> h.toString();
'http://google.com/path1?q=data&d=happy#hash'

// let's try adding new query parameters
> h.queryParams.new = 'wow';
> h.toString();
'http://google.com/path1?q=data&d=happy&new=wow#hash'

// I don't like hashtags. Get rid of it
> h.hash = "";
> h.toString();
'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 = Url('google.com')
> g.toString()
'google.com'
> g.path = 'somepath'
> g.toString()
'google.com/somepath'
> g.queryParams.search = 'data'
> g.toString()
'google.com/somepath?search=data'

Another big backend project awaits. Read up on affiliation and recommendation systems.

Some rights reserved.

Leave a Comment