2016-10-10 03:43:44 +02:00
|
|
|
'use strict';
|
2017-05-27 17:36:13 +02:00
|
|
|
module.exports = (str, count, indent) => {
|
|
|
|
indent = indent === undefined ? ' ' : indent;
|
|
|
|
count = count === undefined ? 1 : count;
|
2016-10-10 03:43:44 +02:00
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
if (typeof str !== 'string') {
|
|
|
|
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``);
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
if (typeof count !== 'number') {
|
|
|
|
throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof indent !== 'string') {
|
|
|
|
throw new TypeError(`Expected \`indent\` to be a \`string\`, got \`${typeof indent}\``);
|
2016-10-10 03:43:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count === 0) {
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2017-05-27 17:36:13 +02:00
|
|
|
return str.replace(/^(?!\s*$)/mg, indent.repeat(count));
|
2016-10-10 03:43:44 +02:00
|
|
|
};
|