parse-columns
Parse text columns, like the output of unix commands
Install
$ npm install --save parse-columns
Usage
$ df -kP
Filesystem 1024-blocks Used Available Capacity Mounted on
/dev/disk1 487350400 467871060 19223340 97% /
devfs 185 185 0 100% /dev
map -hosts 0 0 0 100% /net
var childProcess = require('child_process');
var parseColumns = require('parse-columns');
childProcess.execFile('df', ['-kP'], function (err, stdout) {
console.log(parseColumns(stdout, {
transform: function (el, header, columnIndex) {
if (columnIndex >= 1 && columnIndex <= 3) {
return Number(el);
}
return el;
}
}));
});
API
parseColumns(input, [options])
input
Required
Type: string
Text columns to parse.
options
separator
Type: string
Default: ' '
Separator to split columns on.
Type: array
Headers to use instead of the existing ones.
transform
Type: function
Transform elements.
Useful for being able to cleanup or change the type of elements.
The supplied function gets the following arguments and is expected to return the element:
element
(string)header
(string)columnIndex
(number)rowIndex
(number)
Related
License
MIT © Sindre Sorhus