You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.js 485B

1234567891011121314151617181920
  1. 'use strict';
  2. var repeating = require('repeating');
  3. module.exports = function (str, indent, count) {
  4. if (typeof str !== 'string' || typeof indent !== 'string') {
  5. throw new TypeError('`string` and `indent` should be strings');
  6. }
  7. if (count != null && typeof count !== 'number') {
  8. throw new TypeError('`count` should be a number');
  9. }
  10. if (count === 0) {
  11. return str;
  12. }
  13. indent = count > 1 ? repeating(indent, count) : indent;
  14. return str.replace(/^(?!\s*$)/mg, indent);
  15. };