Comparing version 0.1.2 to 0.1.3
30
index.js
@@ -15,6 +15,8 @@ /** | ||
module.exports = exports = function(file) { | ||
var home = process.env.HOME || process.env.HOMEPATH | ||
, file = file || join(home, ".netrc"); | ||
var home = process.env.HOME || process.env.HOMEPATH; | ||
if(!file && !home) return {}; | ||
file = file || join(home, ".netrc"); | ||
if(!fs.existsSync(file)) return {}; | ||
if(!file || !fs.existsSync(file)) return {}; | ||
var netrc = fs.readFileSync(file, "UTF-8"); | ||
@@ -70,1 +72,23 @@ return exports.parse(netrc); | ||
}; | ||
/** | ||
* Generate contents of netrc file from objects. | ||
* @param {Object} machines as returned by `netrc.parse` | ||
* @return {String} text of the netrc file | ||
*/ | ||
exports.format = function format(machines){ | ||
var lines = [], | ||
keys = Object.getOwnPropertyNames(machines).sort(); | ||
keys.forEach(function(key){ | ||
lines.push('machine ' + key); | ||
var machine = machines[key]; | ||
var attrs = Object.getOwnPropertyNames(machine).sort(); | ||
attrs.forEach(function(attr){ | ||
if(typeof(machine[attr]) === 'string'){ | ||
lines.push(' ' + attr + ' ' + machine[attr]); | ||
} | ||
}); | ||
}); | ||
return lines.join('\n'); | ||
}; | ||
{ | ||
"name": "netrc", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "Parse netrc files", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -70,2 +70,21 @@ /** | ||
describe('format', function(){ | ||
it('should generate text that parses to the original', function(){ | ||
var machines = netrc.parse(valid); | ||
var text = netrc.format(machines); | ||
should.exist(text); | ||
text.should.include('machine github.com'); | ||
text.should.include('login CamShaft'); | ||
text.should.include('password 123'); | ||
var parsed = netrc.parse(text); | ||
parsed.should.have.property('github.com'); | ||
parsed["github.com"].should.have.property("login"); | ||
parsed["github.com"].login.should.eql("CamShaft"); | ||
parsed["github.com"].should.have.property("password"); | ||
parsed["github.com"].password.should.eql("123"); | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
6621
10
157