esamattis / esamattis/underscore.string

Hande empty lines in dedent

Open
#462 1 comment 0 reactions 0 assignees View on GitHub
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.