| Leo Repp | 58b9f11 | 2021-11-22 11:57:47 +0100 | [diff] [blame^] | 1 | 'use strict'; |
| 2 | var repeating = require('repeating'); |
| 3 | |
| 4 | module.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 | }; |