K Indent
Simple indentation tool, supports relative indent
Install
# npm
npm i k-indent
# yarn
yarn add k-indent
Usage
Indent string
// adds 2 spaces indent
indentStr('a', 2); // ' a'
// adds 2 stars indent
indentStr('a', 2, '*'); // '**a'
// first line of string contains only spaces
const str1 = `
a
`;
// not indents empty lines
indentStr(str1, 2, ' ', { indentEmptyLines: true });
/* Output
(no spaces)
a (2 spaces)
'*/
const str2 = `{
a: 1,
b: {
c: 2
}
}`;
// adds 2 spaces with keeping relative indent
indentStr(str2, 2, { relativeIndent: true });
/* Output
{
a: 1,
b: {
c: 2
}
}
*/
Create indent
createIndent(2); // ' '
createIndent(2, '*'); // '**'
Contributing
Want to collaborate? Check github repo