connexion-string
Advanced tools
Comparing version 0.1.1 to 0.1.2
19
index.js
@@ -67,2 +67,21 @@ function ConnString(defaults) { | ||
ConnString.prototype.stringify = function(serverObj) { | ||
var serverStr | ||
if(serverObj) { | ||
serverStr = serverObj.host | ||
if(serverObj.port || this._defaults.port) { | ||
serverStr += ':' + serverObj.port | ||
} | ||
if(serverObj.user) { | ||
var credentials = serverObj.user | ||
if(serverObj.password) { | ||
credentials += ':' + serverObj.password | ||
} | ||
serverStr = credentials + '@' + serverStr | ||
} | ||
} | ||
return serverStr | ||
} | ||
module.exports = ConnString |
{ | ||
"name": "connexion-string", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "servers connexion string (de)serialization", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -56,2 +56,46 @@ | ||
}) | ||
describe('serialize', function() { | ||
it('host', function() { | ||
var expectedStr = '127.0.0.1' | ||
var server = connStr.parse(expectedStr) | ||
var actualStr = connStr.stringify(server) | ||
assert.ok(actualStr) | ||
assert.equal(actualStr, 'user@127.0.0.1:22') | ||
}) | ||
it('user@host', function() { | ||
var expectedStr = 'myName@127.0.0.1' | ||
var server = connStr.parse(expectedStr) | ||
var actualStr = connStr.stringify(server) | ||
assert.ok(actualStr) | ||
assert.equal(actualStr, 'myName@127.0.0.1:22') | ||
}) | ||
it('user@host:port', function() { | ||
var expectedStr = 'myName@127.0.0.1:2222' | ||
var server = connStr.parse(expectedStr) | ||
var actualStr = connStr.stringify(server) | ||
assert.ok(actualStr) | ||
assert.equal(actualStr, expectedStr) | ||
}) | ||
it('user:pwd@host:port', function() { | ||
var expectedStr = 'myName:123456@127.0.0.1:2222' | ||
var server = connStr.parse(expectedStr) | ||
var actualStr = connStr.stringify(server) | ||
assert.ok(actualStr) | ||
assert.equal(actualStr, expectedStr) | ||
}) | ||
}) | ||
}) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5123
145