How to use the camelCase function from lodash

Find comprehensive JavaScript lodash.camelCase code examples handpicked from public code repositorys.

lodash.camelCase converts a string to camel case, which capitalizes the first letter of each word in the string except for the first word.

71
72
73
74
75
76
77
78
79
80
	os_v: os.release(),
	client: pjson.version,
	canUpdateHistory: true,
};

this.id = _.camelCase(this.info.name);

this.stats = {
	active: false,
	mining: false,
fork icon353
star icon327
watch icon28

2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
)

const rows = Object.keys(entities).map(name => {
  const group = lodash.sortBy(entities[name], "languageRank")
  const person = wikipediaLinks.nodesThatStartWith(name)[0]
  const anchorTag = lodash.camelCase(name)

  return {
    name: !person
      ? `<a name='${anchorTag}' />${name}`
fork icon73
star icon647
watch icon6

+ 3 other calls in file

How does lodash.camelCase work?

lodash.camelCase is a function that takes a string as input and converts it to a camelCase string by removing any non-alphanumeric characters and capitalizing the first letter of each subsequent word. For example, "hello_world" would become "helloWorld".

41
42
43
44
45
46
47
48
49
50
module.exports.bitwiseOr           = _.bitwiseOr;
module.exports.bitwiseRight        = _.bitwiseRight;
module.exports.bitwiseXor          = _.bitwiseXor;
module.exports.bitwiseZ            = _.bitwiseZ;
module.exports.bound               = _.bound;
module.exports.camelCase           = _.camelCase;
module.exports.capitalize          = _.capitalize;
module.exports.castArray           = _.castArray;
module.exports.cat                 = _.cat;
module.exports.ceil                = _.ceil;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

12
13
14
15
16
17
18
19
20
21
  this.properties = {};
}

before() {
  if (this.name === undefined && this.object === undefined) {
    this.key = _.camelCase(this.class.name) + this.class.sequence++;
    this.name = this.key;
  } else {
    this.key = Id.serialize(this);
  }
fork icon7
star icon447
watch icon8

Ai Example

1
2
3
const _ = require("lodash");

const camelCaseString = _.camelCase("hello world"); // returns 'helloWorld'

In this example, we first import lodash and then call the _.camelCase() function with the argument 'hello world'. The function returns the string 'helloWorld', which is the same string with spaces removed and the first letter of each word capitalized.

41
42
43
44
45
46
47
48
49
50
  ),
);

// TODO: Check if this should this be &&
libraries.forEach((library) => {
  const libHandleName = _.camelCase(library.name);
  if (extractedLibraries.includes(libHandleName)) {
    librariesMap[libHandleName] = library.code;
  }
});
fork icon77
star icon54
watch icon20

122
123
124
125
126
127
128
129
130
131
 */
exports.loadEnvs = prefix => _(process.env)
  // Only muck with prefix_ variables
  .pickBy((value, key) => _.includes(key, prefix))
  // Prep the keys for consumption
  .mapKeys((value, key) => _.camelCase(key.replace(prefix, '')))
  // If we have a JSON string as a value, parse that and assign its sub-keys
  .mapValues(exports.tryConvertJson)
  // Resolve the lodash wrapper
  .value();
fork icon35
star icon29
watch icon4

+ 5 other calls in file

27
28
29
30
31
32
33
34
35
    units_per_em: 1000,
    ascent: 850,
    glyphs,
};

const formatToPascalCase = (str) => _.camelCase(str).replace(/^(.)/, _.toUpper);

// write to root for fontelle-cli to retrieve
writeJSONToDisk('config.json', configData);
fork icon7
star icon2
watch icon42

784
785
786
787
788
789
790
791
792
793
794
795
796
797
console.log(prototypeValueOf); // => [Function: wrapperValue]




// String


const camelCase = _.camelCase('--foo-bar--');
console.log(camelCase); // => 'fooBar'


const capitalize = _.capitalize('FRED');
console.log(capitalize); // => 'Fred'
fork icon0
star icon4
watch icon0

+ 15 other calls in file

4
5
6
7
8
9
10
11
12
13
14
15
16
17


const base = path.resolve(__dirname, './react');
const dirs = fs.readdirSync(base);


const pascalCase = (str) =>
  lodash.camelCase(str).replace(/^(.)/, lodash.toUpper);


const items = [];


dirs.forEach((dir) => {
fork icon0
star icon1
watch icon0

110
111
112
113
114
115
116
117
118
119
  this.logger.warn("wrong path param name", paramName);
}

pathParams.push({
  $match: match,
  name: _.camelCase(paramName),
  required: true,
  type: "string",
  description: "",
  schema: {
fork icon236
star icon0
watch icon12

+ 4 other calls in file

174
175
176
177
178
179
180
181
182
183

const referencesDefinition = references.map(reference => ({
  ...reference,
  isBelongsToMany: reference.association === 'belongsToMany',
  targetKey: _.camelCase(reference.targetKey),
  sourceKey: _.camelCase(reference.sourceKey),
}));

this.copyHandleBarsTemplate(
  `models/${config.dbConfig.dbDialect === 'mongodb' ? 'mongo' : 'sequelize'}-model.hbs`,
fork icon2
star icon51
watch icon12

+ 27 other calls in file

522
523
524
525
526
527
528
529
530
531
532
533
    return selects
  }
}


function fieldNameForModel(modelClass) {
  return _.camelCase(utils.typeNameForModel(modelClass))
}


function toJson(result) {
  if (_.isArray(result)) {
fork icon0
star icon3
watch icon2

19
20
21
22
23
24
25
26
27
28
29
30
    return arg;
};


const normalizeFields = fields => fields.map(field => ({
    ...field,
    key: _.camelCase(field.name.toLowerCase()),
}));


const removeEmptyValues = obj => Object.fromEntries(
    Object.entries(obj).filter(([_, val]) => !["", undefined, null].includes(val))
fork icon0
star icon3
watch icon2

335
336
337
338
339
340
341
342
343
344
    const config = _.cloneDeep(this.rspackConfig);
    config.entry = {
      [entryFunc.entry.key]: entryFunc.entry.value,
    };
    const compileName =
      entryFunc.funcName || _.camelCase(entryFunc.entry.key);
    config.output.path = path.join(config.output.path, compileName);
    return config;
  });
} else {
fork icon0
star icon1
watch icon0

262
263
264
265
266
267
268
269
270
271

if (regex.isInvalidIdentifierName.test(part)) {
  attrName = part.replace(regex.invalidIdentifierName, "$1"); // '["x.y"]' => 'x.y'
  checkLimit(attrName);
  attrNameAlias = `#${truncate(
    _.camelCase([prefix, attrName]),
    maxAttrNameLen - 1,
    aliasContext
  )}`; // #xY
  pathPart = attrNameAlias; // #xY
fork icon0
star icon0
watch icon0

+ 35 other calls in file

412
413
414
415
416
417
418
419
420
421
    }
  }
  return { env, missingEnvs, presentEnvs };
}
const envCase = (string) => _.snakeCase(string).toUpperCase();
const unEnvCase = _.camelCase;
function envKeys(dict) {
  return _.mapKeys(dict, (value, key) => envCase(key));
}
function unEnvKeys(dict) {
fork icon0
star icon0
watch icon1

+ 3 other calls in file

309
310
311
312
313
314
315
316
317
318
yaml: (arg) => yaml.dump(arg),
parsedJson: (arg) => JSON.parse(arg),
parsedYaml: (arg) => yaml.load(arg),
lowerCase: (arg) => arg.toLowerCase(),
upperCase: (arg) => arg.toUpperCase(),
camelCase: (arg) => _.camelCase(arg),
snakeCase: (arg) => _.snakeCase(arg),
kebabCase: (arg) => _.kebabCase(arg),
startCase: (arg) => _.startCase(arg),
format: (format) => (insert) => format.replace(/(?<!\\)%s/g, insert),
fork icon0
star icon0
watch icon1

+ 7 other calls in file

86
87
88
89
90
91
92
93
94
95

describe('columnInfo with wrapIdentifier and postProcessResponse', () => {
  before('setup hooks', () => {
    knex.client.config.postProcessResponse = (response) => {
      return _.mapKeys(response, (val, key) => {
        return _.camelCase(key);
      });
    };

    knex.client.config.wrapIdentifier = (id, origImpl) => {
fork icon0
star icon0
watch icon1

+ 2 other calls in file

80
81
82
83
84
85
86
87
88
89
const factory = ts.factory;
const sortedFields = Object.keys(fields)
  .map((key) => {
    return {
      ...fields[key],
      name: camelCase(key),
      required: requiredFields ? requiredFields.indexOf(key) > 0 : false,
      type: fields[key].type === 'integer' ? 'number' : fields[key].type,
    };
  })
fork icon0
star icon0
watch icon1

+ 2 other calls in file

154
155
156
157
158
159
160
161
162
163
});

last.forEach((el) => {
  let data = {};
  if (
    camelCase(decodeURIComponent(el[0].R[0].T)) === "additionalInformation"
  ) {
    el = getRawTexts(el);
    const [head, ...texts] = el;
    data.label = head.T;
fork icon0
star icon0
watch icon0

Other functions in lodash

Sorted by popularity

function icon

lodash.get is the most popular function in lodash (7670 examples)