blob: 4a21687b2859cb5f2078bcf142f3d6d55a8e9df1 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2var repeating = require('repeating');
3
4module.exports = function (str, indent, count) {
5 if (typeof str !== 'string' || typeof indent !== 'string') {
6 throw new TypeError('`string` and `indent` should be strings');
7 }
8
9 if (count != null && typeof count !== 'number') {
10 throw new TypeError('`count` should be a number');
11 }
12
13 if (count === 0) {
14 return str;
15 }
16
17 indent = count > 1 ? repeating(indent, count) : indent;
18
19 return str.replace(/^(?!\s*$)/mg, indent);
20};