4 * Parse the content of a passwd file into a list of user objects.
5 * This function ignores blank lines and comments.
8 * // assuming '/etc/passwd' contains:
9 * // doowb:*:123:123:Brian Woodward:/Users/doowb:/bin/bash
10 * console.log(parse(fs.readFileSync('/etc/passwd', 'utf8')));
14 * //=> username: 'doowb',
18 * //=> gecos: 'Brian Woodward',
19 * //=> homedir: '/Users/doowb',
20 * //=> shell: '/bin/bash'
24 * @param {String} `content` Content of a passwd file to parse.
25 * @return {Array} Array of user objects parsed from the content.
29 module.exports = function(content) {
30 if (typeof content !== 'string') {
31 throw new Error('expected a string');
39 function user(line, i) {
40 if (!line || !line.length || line.charAt(0) === '#') {
44 // see https://en.wikipedia.org/wiki/Passwd for field descriptions
45 var fields = line.split(':');
51 // see https://en.wikipedia.org/wiki/Gecos_field for GECOS field descriptions