Lodash: Add a string function to remove double spaces

Created on 19 Nov 2015  路  3Comments  路  Source: lodash/lodash

This is a fairly common requirement.

http://stackoverflow.com/questions/3286874/remove-all-multiple-spaces-in-javascript-and-replace-with-single-space

It is as simple as input.replace(/\s\s+/g, ''), but:

  • as evident in Stack Overflow, developers come up with inventive (and not necessarily good) ways to do it.
  • no one likes to read regex written by other developers, regardless of how simple it is.

A simple _.despace function would be convenient.

enhancement wontfix

Most helpful comment

It's been 3 years since last comment. I think adding this feature should be re-evaluated.
My suggestion - Please add this.

All 3 comments

Hi @gajus, thanks for the suggestion!

This looks like something that could _.words(string).join(' ') in some cases. I'd like to hold off on adding until I get a better gauge on user demand for such a method. Until then _.mixin.

It's been 3 years since last comment. I think adding this feature should be re-evaluated.
My suggestion - Please add this.

4 years. Could use a simple despace.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dengyaolong picture dengyaolong  路  3Comments

aj0strow picture aj0strow  路  3Comments

ryyppy picture ryyppy  路  3Comments

thoraage picture thoraage  路  3Comments

JoMas971 picture JoMas971  路  3Comments