2 module.exports = (str, count, opts) => {
3 // Support older versions: use the third parameter as options.indent
4 // TODO: Remove the workaround in the next major version
5 const options = typeof opts === 'object' ? Object.assign({indent: ' '}, opts) : {indent: opts || ' '};
6 count = count === undefined ? 1 : count;
8 if (typeof str !== 'string') {
9 throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``);
12 if (typeof count !== 'number') {
13 throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
16 if (typeof options.indent !== 'string') {
17 throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``);
24 const regex = options.includeEmptyLines ? /^/mg : /^(?!\s*$)/mg;
25 return str.replace(regex, options.indent.repeat(count));