All files parse.js

90.91% Statements 10/11
75% Branches 3/4
100% Functions 2/2
90.91% Lines 10/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 441x 1x   1x     17x           17x 17x     17x   17x         81x                   81x                    
var format = require('./format')
var calcMultiplier = require('./calcMultiplier')
 
module.exports = function(stdout, options) {
    // TODO: this snould be removed because it never happens.
    // Nonetheless, I want to consider it a breaking changed that's to be made after releasing 0.1.4
    Iif (!stdout) {
        return void 0
    }
 
    // TODO: `options.prefixMultiplier` should become `options.unit`
    // I should deprecate the use of `options.prefixMultiplier` in 0.1.4
    var multiplier = calcMultiplier(options.prefixMultiplier)
    var precision = options.precision
    // TODO: `options.isDisplayPrefixMultiplier` should become `options.showUnit`
    // I should deprecate the use of options.isDisplayPrefixMultiplier in 0.1.4
    var unit = options.isDisplayPrefixMultiplier ? options.prefixMultiplier : null
 
    return stdout
        .trim()
        .split(/\r|\n|\r\n/) // split into rows
        .slice(1) // strip column headers away
        .map(function(row) {
            var columns = row
                // one or more whitespaces followed by one or more digits
                // must be interpreted as column delimiter
                .replace(/\s+(\d+)/g, '\t$1')
                // one or more whitespaces followed by a slash
                // must be interpreted as the last column delimiter
                .replace(/\s+\//g, '\t/')
                // split into columns
                .split(/\t/)
 
            return {
                filesystem: columns.pop(),
                size: format(columns.pop(), multiplier, precision, unit),
                used: format(columns.pop(), multiplier, precision, unit),
                available: format(columns.pop(), multiplier, precision, unit),
                capacity: format(columns.pop(), 0.01),
                mount: columns.join(' '),
            }
        })
}