Merge pull request #748 from 30-seconds/indentString

Add indentString
This commit is contained in:
Angelos Chalaris
2018-09-27 16:58:31 +03:00
committed by GitHub
4 changed files with 32 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
const indentString = (str, count, indent = ' ') =>
str.replace(/^/mg, indent.repeat(count));
module.exports = indentString;

View File

@@ -0,0 +1,12 @@
const expect = require('expect');
const indentString = require('./indentString.js');
test('indentString is a Function', () => {
expect(indentString).toBeInstanceOf(Function);
});
test('indentString is a Function', () => {
expect(indentString('Lorem\nIpsum', 2)).toBe(' Lorem\n Ipsum');
});
test('indentString is a Function', () => {
expect(indentString('Lorem\nIpsum', 2, '_')).toBe('__Lorem\n__Ipsum');
});