esamattis/underscore.string

Hande empty lines in dedent

remcohaszing opened this issue · 1 comments

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.

>>> 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.

> 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.

Agreed blank lines should be ignored. IMO we should change the current behaviour instead of introducing a 3rd parameter. @epeli what's your opinion?