esamattis / esamattis/underscore.string
Hande empty lines in dedent
- Dominant language
- JavaScript
- Stars
- 3.4k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
When reading #46, I figured the dedent function should behave similar to Python's `textwrap.dedent` function.
In Python's `textwrap.dedent` blank lines are ignored towards indentation count.
``` py
>>> import textwrap
>>> textwrap.dedent("""
... foo
...
... bar
... baz
... """)
'\nfoo\n\nbar\nbaz\n'
```
In the `dedent` function from `underscore.string`, blank lines count as an indentation of `0`.
``` js
> var s = require('underscore.string');
undefined
> s.dedent(`
... foo
...
... bar
... baz
... `)
'\n foo\n\n bar\n baz\n'
```
There are many cases in which ignoring blank lines is useful. I think this would be a better default behaviour, but it should at least be possible to make it behave this way by passing a parameter.
Contributor guide
Assessment
This issue has not been assessed yet.