Poly9’s Polyvalent Javascript URL Parser

Written by on November 25th, 2006 in Ajax News.

Denis Laprise and the Poly9 Group needed a robust URL parser in JavaScript, so they created the Polyvalent Javascript URL Parser.

var p = new Poly9.URLParser(’http://user:password@poly9.com/pathname?arguments=1#fragment’);
p.getHost() == ‘poly9.com’;
p.getProtocol() == ‘http’;
p.getPathname() == ‘/pathname’;
p.getQuerystring() == ‘arguments=1′;
p.getFragment() == ‘fragment’;
p.getUsername() == ‘user’;
p.getPassword() == ‘password’;

p.setURL(’another.url.com’);
p.getHost() == ‘another.url.com’;
p.getProtocol() == ”;

p.setURL(’dsdsad’); // throws an exception
 

This smells like a Java group writing JavaScript to me with the camelCase and thus p.getUsername() instead of p.username.

You can check out the implementation and the test suite (zip).

Source: Ajaxian
Original Article: http://ajaxian.com/archives/poly9s-polyvalent-javascript-url-parser

Leave a Reply

You must be logged in to post a comment.



Site Navigation