UNPKG

stubby

Version:

a lightweight server for stubbing external systems and endpoints

38 lines (27 loc) 858 B
'use strict'; var times = require('../prototype/times'); // eslint-disable-line function spacing (length) { if (length == null) { length = 0; } return ' '.times(length); } function wrap (tokens, continuation, columns) { let wrapped; if (continuation == null) { continuation = 0; } if (columns == null) { columns = process.stdout.columns; } if (continuation + tokens.join(' ').length <= columns) { return tokens.join(' '); } wrapped = ''; const gutter = spacing(continuation); tokens.forEach(function (token) { const lengthSoFar = continuation + wrapped.replace(/\n/g, '').length % columns || columns; if (lengthSoFar + token.length > columns) { wrapped += '\n' + gutter + token; } else { wrapped += ' ' + token; } }); return wrapped.trim(); } module.exports = { spacing: spacing, wrap: wrap };