Tuesday, July 07, 2009

Standing on the Shoulder of Giants to Manage Paths

In other words, using other people's code instead of implementing path management from scratch.

I needed to add a JavaScript function to resolve paths. Resolving paths can mean 2 things; in my case, I want a function that accepts a path (which is potentially a relative path) and outputs an absolute path. The catch is that the function is implemented in JavaScript.

After 2 days of search, my colleagues found js-uri, a small JavaScript library that does exactly what I need. So far, it performs beautifully.

To test the function, I use the test cases given in RFC 1808 section 5.

I hope someone will find this useful when he/she needs to resolve paths in JavaScript :)