Indents each line in the provided string.
String.prototype.replace()
and a regular expression to add the character specified by indent
count
times at the start of each line.indent
, to use a default indentation character of ' '
.const indentString = (str, count, indent = ' ') =>
str.replace(/^/gm, indent.repeat(count));
indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum'
indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum'
JavaScript, String
Converts an hsl()
color string to an object with the values of each color.
JavaScript, String
Converts an rgb()
color string to an object with the values of each color.
JavaScript, String
Creates a new string with the results of calling a provided function on every character in the given string.