source: trip-planner-front/node_modules/indent-string/index.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 743 bytes
Line 
1'use strict';
2
3module.exports = (string, count = 1, options) => {
4 options = {
5 indent: ' ',
6 includeEmptyLines: false,
7 ...options
8 };
9
10 if (typeof string !== 'string') {
11 throw new TypeError(
12 `Expected \`input\` to be a \`string\`, got \`${typeof string}\``
13 );
14 }
15
16 if (typeof count !== 'number') {
17 throw new TypeError(
18 `Expected \`count\` to be a \`number\`, got \`${typeof count}\``
19 );
20 }
21
22 if (typeof options.indent !== 'string') {
23 throw new TypeError(
24 `Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``
25 );
26 }
27
28 if (count === 0) {
29 return string;
30 }
31
32 const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm;
33
34 return string.replace(regex, options.indent.repeat(count));
35};
Note: See TracBrowser for help on using the repository browser.