I have been working as a web-developer for many years, I am bored with doing the same task again and again. What do you do when you need to modify some URL part, where URL is a simple string? It's possibly to do the trick with regular expression or in some other way, or try to search for some existing solution. By the way, I didn't find any good solution (because of weight or functionality) and am tired of this so much that I decided to write my own. The goal was to have a really simple, easy-to-use functionality with minimum code-base. Hope I was able to fit those requirements.
Using the Code
The code is available at Github and licensed under MIT license conditions. So feel free to use it anywhere and do what you want.
There is also a possibility to install it via JAM repository, simply as:
$ jam install jsurl
Look at this simple example of using the library. It's really easy. First, you need just instantiate the
Url object from
string, then to use it as an object or as a
string, depending on circumstances:
var u = new Url('http://user:email@example.com:8080/some/path?foo=bar#anchor');
alert( 'Source URL is ' + u);
u.hash = 'new-anchor';
u.protocol = 'https';
u.pass = '';
u.query.foo = 'baz';
u.query.bar = [1,2,3];
alert( 'New URL is ' + u);
Points of Interest
I was totally focused on having this library without any external dependencies and that was done. So I just hope it will be useful to anyone else.
Please, don't hesitate to leave your feedback, comments and bug reports.