Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jpwilliams/sindent

Remove indentation from template literals using template tags.
https://github.com/jpwilliams/sindent

indent literals spaces string tabs tags template

Last synced: 22 days ago
JSON representation

Remove indentation from template literals using template tags.

Awesome Lists containing this project

README

        

# sindent
Remove indentation from string literals in a predictable manner using template tags.

``` js
const sindent = require('sindent')

sindent`This string
should only indent
right here
but nowhere else,
as it's obvious we don't want
the other indentations`

// This string
// should only indent
// right here
// but nowhere else
// as it's obvious we don't want
// the other indentations
```

## Greedy mode

This "mode" makes the internal regex nice and hungry, so it'll accept an indentation of 0 as the smallest it finds.
This isn't _usually_ what you want, but it fits certain cases.

``` js
const sindent = require('sindent/greedy')

sindent`This line will be matched as the smallest,
so this line will be indented`

// This line will be matched as the smallest
// so this line will be indented
```

## Function mode

If you don't want to use template tags, you can also use _sindent_ as a normal function, accepting `str` and `greedy`.

``` js
const sindent = require('sindent/func')

sindent(`Let's start
a greedy,
greedy
indent`, true)

// Let's start
// a greedy
// greedy
// indent
```