Last active
August 29, 2015 14:13
-
-
Save sintaxi/20298a3b2a93390cd630 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Implementation | |
*/ | |
var url = require("url") | |
var u = function(domain){ | |
var urlObj = url.parse(domain || "https://foo.com") | |
if (["http:", "https:"].indexOf(urlObj.protocol) === -1) { | |
urlObj.protocol = "http" | |
} | |
return url.format(urlObj) | |
} | |
/** | |
* Tests | |
*/ | |
var assert = require("assert") | |
describe("u", function(){ | |
it("should exist", function(done){ | |
assert.notEqual(u, undefined, "oops") | |
assert.notEqual(u, null, "oops") | |
done() | |
}) | |
it("should have sane default of foo.com over SSL", function(done){ | |
assert.equal(u(), "https://foo.com/") | |
done() | |
}) | |
it("should be able to set protocol", function(done){ | |
assert.equal(u("http://foo.com"), "http://foo.com/") | |
done() | |
}) | |
it("should be able to set port", function(done){ | |
assert.equal(u("foo.com:5000"), "http://foo.com:5000/") | |
done() | |
}) | |
it("should be able to override the protocol", function(done){ | |
assert.equal(u("http://foo.com"), "http://foo.com/") | |
done() | |
}) | |
it("should be able to omit protocol altogether. will default to http", function(done){ | |
assert.equal(u("foo.com"), "http://foo.com/") | |
done() | |
}) | |
}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment