Skip to content

Commit

Permalink
Added unparse to generate .netrc contents from objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
jjmason committed May 18, 2013
1 parent 9a4be54 commit 6036f13
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions index.js
Expand Up @@ -66,3 +66,25 @@ exports.parse = function(content) {

return machines
};

/**
* Generate contents of netrc file from objects.
* @param {Object} machines as returned by `netrc.parse`
* @return {String} text of the netrc file
*/
exports.unparse = function(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');
};

0 comments on commit 6036f13

Please sign in to comment.