k-indent
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

K Indent

Simple indentation tool, supports relative indent

npm npm npm npm

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? :octocat: Check github repo

Package Sidebar

Install

npm i k-indent

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

121 kB

Total Files

21

Last publish

Collaborators

  • kostayne