Prepare repository for merge

This commit is contained in:
Angelos Chalaris
2023-05-01 22:35:56 +03:00
parent fc4e61e6fa
commit b3ad01863a
578 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,22 @@
---
title: Indent string
type: snippet
tags: [string]
cover: clutter
dateModified: 2020-11-01T20:50:57+02:00
---
Indents each line in the provided string.
- Use `String.prototype.replace()` and a regular expression to add the character specified by `indent` `count` times at the start of each line.
- Omit the third argument, `indent`, to use a default indentation character of `' '`.
```js
const indentString = (str, count, indent = ' ') =>
str.replace(/^/gm, indent.repeat(count));
```
```js
indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum'
indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum'
```