move to_uri() into lib/uri.js to allow use on client