Would you like to clone this notebook?

When you clone a notebook you are able to make changes without affecting the original notebook.

Cancel

Format your strings to Camel Case with Lodash

node v14.17.6
version: 1.0.0
endpointsharetweet
These examples show you how to format any string to camelCase using Lodash's `_.camelCase` function.
const _ = require("lodash");
It works out-of-the-box with dashes and underscores:
_.camelCase("my_string");
_.camelCase("another-string");
However, you may not have the desired result with weird casings in you string:
_.camelCase("mY-STrInG_iS-AwEsOmE");
To fix this, ensure to format your string to lower case **before** applying the `camelcase` function:
_.camelCase("mY-STrInG_iS-AwEsOmE".toLowerCase());
Note that the function works smoothly with dot notation (for example, flattened object keys):
_.camelCase("foo.bar");
Loading…

no comments

    sign in to comment