package/package.json000644 001750 001750 0000001002 12101767566013023 0ustar00000000 000000 { "name": "url-join", "version": "0.0.1", "description": "Join urls and normalize as in path.join.", "main": "lib/url-join.js", "scripts": { "test": "mocha --require should" }, "repository": { "type": "git", "url": "git://github.com/jfromaniello/url-join.git" }, "keywords": [ "url", "join" ], "author": "José F. Romaniello (http://joseoncode.com)", "license": "MIT", "devDependencies": { "should": "~1.2.1", "mocha": "~1.8.1" } } package/.npmignore000644 001750 001750 0000000024 12101766467012536 0ustar00000000 000000 node_modules/* *.logpackage/README.md000644 001750 001750 0000001104 12101766432012006 0ustar00000000 000000 Join all arguments together and normalize the resulting url. ## Install ~~~ npm install url-join ~~~ ## Usage ~~~javascript var urljoin = require('url-join'); var fullUrl = urljoin('http://www.google.com', 'a', '/b/cd', '?foo=123'); console.log(fullUrl); \\will print: 'http://www.google.com/a/b/cd?foo=123' ~~~ This works similar to [path.join](http://nodejs.org/api/path.html#path_path_join_path1_path2) but you shouldn't use ```path.join``` for urls since it will work different depending of the operative systems but also doesn't work for some cases. ## License MITpackage/lib/url-join.js000644 001750 001750 0000000446 12101766000013371 0ustar00000000 000000 function normalize (str) { return str .replace(/[\/]+/g, '/') .replace(/\/\?/g, '?') .replace(/\/\#/g, '#') .replace(/\:\//g, '://'); } module.exports = function () { var joined = [].slice.call(arguments, 0).join('/'); return normalize(joined); };package/test/tests.js000644 001750 001750 0000001503 12101766020013202 0ustar00000000 000000 var urljoin = require('../lib/url-join'); describe('url join', function () { it('should work for simple case', function () { urljoin('http://www.google.com/', 'foo/bar', '?test=123') .should.eql('http://www.google.com/foo/bar?test=123'); }); it('should be able to join protocol', function () { urljoin('http:', 'www.google.com/', 'foo/bar', '?test=123') .should.eql('http://www.google.com/foo/bar?test=123'); }); it('should remove extra slashes', function () { urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123') .should.eql('http://www.google.com/foo/bar?test=123'); }); it('should support anchors in urls', function () { urljoin('http:', 'www.google.com///', 'foo/bar', '?test=123', '#faaaaa') .should.eql('http://www.google.com/foo/bar?test=123#faaaaa'); }); });