This is a part one of lodash series.
lodash has a lot of hidden gems and by using them you can avoid copy-pasting untested snippets from StackOverflow!
In the first post of the series we'll look at useful string manipulation functions.
_.kebabCase, _.snakeCase, _.camelCase and _.deburr
We often need to convert a text given by a user to a technical identifier. This might be the case when the user inputs name for an object and we need to represent that in a human-readable form in the URL. In the case of the URL we want to avoid letters that require encoding as that would ruin readability. For example: empty space would be %20.
_.kebabCase('Why Nikola Tesla was the greatest geek who ever lived') -> "why-nikola-tesla-was-the-greatest-geek-who-ever-lived"
How about an array?
_.kebabCase(['Jean-luc', 'Picard']) -> "jean-luc-picard"
Let me quote the documentation of the
Deburrs string by converting latin-1 supplementary letters to basic latin letters and removing combining diacritical marks.
This basically means that if you have a word like Ääliö (which is moron in Finnish) it would be converted like this:
_.deburr('ääliö') -> "aalio"
More (hopefully) helpful tips coming in the next post. Stay tuned!