Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suggestion: also provide String.prototype.dedent() #84

Open
atk opened this issue Jan 16, 2024 · 2 comments
Open

Suggestion: also provide String.prototype.dedent() #84

atk opened this issue Jan 16, 2024 · 2 comments

Comments

@atk
Copy link

atk commented Jan 16, 2024

Like this:

String.dedent(`
  Whatever
`)
// vs
`
  Whatever
`.dedent()
@bakkot
Copy link
Contributor

bakkot commented Jan 16, 2024

See some previous discussion.

I think these ought to behave slightly differently, as they would serve different use cases: String.dedent as a template tag should be the thing you use whenever you have a literal string in source, and would enforce the constraint that the first line is empty and the last line is whitespace (and would remove them), whereas String.prototype.dedent should be used for strings acquired from elsewhere (e.g. read from a file), and would not have the constraint on the first/last lines (and would not remove them).

@Zamralik
Copy link

would not have the constraint on the first/last lines (and would not remove them).

Which is no issue as you can do text.dedent().trim() to have them removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants