All files / node-activedirectory/lib/services/internal service.truncateLogOutput.js

20% Statements 3/15
0% Branches 0/10
0% Functions 0/1
27.27% Lines 3/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 171x   1x                           1x
const maxOutputLength   = 256;
 
const truncateLogOutput = (output, maxLength) => {
    if (typeof (maxLength) === 'undefined') maxLength = maxOutputLength;
    if (!output) return (output);
 
    if (typeof (output) !== 'string') output = output.toString();
    var length = output.length;
    if ((!length) || (length < (maxLength + 3))) return (output);
 
    var prefix = Math.ceil((maxLength - 3) / 2);
    var suffix = Math.floor((maxLength - 3) / 2);
    return (output.slice(0, prefix) + '...' +
        output.slice(length - suffix));
}
 
module.exports = truncateLogOutput;