Skip to content
This repository has been archived by the owner on Jan 24, 2021. It is now read-only.

Strip indentation #7

Closed
sindresorhus opened this issue Mar 26, 2014 · 3 comments
Closed

Strip indentation #7

sindresorhus opened this issue Mar 26, 2014 · 3 comments

Comments

@sindresorhus
Copy link
Owner

Would be nice if this https://github.com/sindresorhus/pageres/blob/50b2a30dbd2335b1e955ad53dc9226bf52ad578d/cli.js#L16-L31 could be indented on the same level as the method, but return a non-indented string.

Should probably be a separate method.

@freethejazz
Copy link
Contributor

I put together a really rough cut of this here: https://github.com/freethejazz/multiline/blob/master/multiline.js

With added test coverage:
https://github.com/freethejazz/multiline/blob/master/test.js

I'm calling the concept of what you're trying to do "normalizing whitespace," because I don't know what the proper name is for it :).

A few notes:

  • It won't work if the user mixes indentation types (tabs with spaces) within a single block(it doesn't discern between tabs and spaces).
  • It will overwrite the user's newline character with a \n
  • Instead of adding a new public method, I changed the existing method signature to have an optional second parameter. true if normalizing the whitespace.

What do you think?

@sindresorhus
Copy link
Owner Author

@freethejazz thanks for exploring this. I went with a slightly simpler solution though. Let me know what you think :)

@freethejazz
Copy link
Contributor

@sindresorhus Yes, much simpler!

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

No branches or pull requests

2 participants