Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/jpwilliams/sindent
- Owner: jpwilliams
- License: mit
- Created: 2017-07-28T09:18:51.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-01-06T09:13:34.000Z (almost 5 years ago)
- Last Synced: 2024-09-26T03:17:37.190Z (about 1 month ago)
- Topics: indent, literals, spaces, string, tabs, tags, template
- Language: JavaScript
- Size: 3.91 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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
```