Skip to content

Commit

Permalink
filter out comment and empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
pkrumins committed Apr 3, 2011
1 parent fbf3bd3 commit 7393004
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,26 @@ exports.get = function (username, cb) {
function getUsers (cb) {
fs.readFile('/etc/passwd', function (err, users) {
if (err) throw err;
cb(users.split('\n').map(function (user) {
var fields = user.split(':');
return {
username : fields[0],
password : fields[1],
userId : fields[2],
groupId : fields[3],
name : fields[4],
homedir : fields[5],
shell : fields[6]
}
}));
cb(
users
.toString()
.split('\n')
.filter(function (user) {
return user.length && user[0] != '#';
})
.map(function (user) {
var fields = user.split(':');
return {
username : fields[0],
password : fields[1],
userId : fields[2],
groupId : fields[3],
name : fields[4],
homedir : fields[5],
shell : fields[6]
}
});
);
});
}

0 comments on commit 7393004

Please sign in to comment.