blob: b6ab264aeae13f7a4c6b6fc03e992b1f29eb92db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
'use strict';
module.exports = (str, count, indent) => {
indent = indent === undefined ? ' ' : indent;
count = count === undefined ? 1 : count;
if (typeof str !== 'string') {
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof str}\``);
}
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}\``);
}
if (count === 0) {
return str;
}
return str.replace(/^(?!\s*$)/mg, indent.repeat(count));
};
|