How to use the startCase function from lodash

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

lodash.startCase is a function that converts a string into a new string with words in title case format, where the first letter of each word is capitalized and there are spaces between words.

9
10
11
12
13
14
15
16
17
18
const capitalize = (str) => {
    if (str === 'aria') {
        return 'ARIA';
    }

    return startCase(str).replace(/\band\b/i, 'and');
};

/**
 * @param {string} category
fork icon577
star icon0
watch icon0

58
59
60
61
62
63
64
65
66
67
    if (entry.isFile()) {
      shell.sed('-i', /\$module\$/g, moduleName, entry.name);
      shell.sed('-i', /\$_module\$/g, decamelize(moduleName), entry.name);
      shell.sed('-i', /\$-module\$/g, decamelize(moduleName, { separator: '-' }), entry.name);
      shell.sed('-i', /\$Module\$/g, Module, entry.name);
      shell.sed('-i', /\$MoDuLe\$/g, startCase(moduleName), entry.name);
      shell.sed('-i', /\$MODULE\$/g, moduleName.toUpperCase(), entry.name);
    }
  });
}
fork icon338
star icon0
watch icon64

+ 7 other calls in file

How does lodash.startCase work?

lodash.startCase is a function provided by the Lodash library which takes a string as input and returns a new string with each word capitalized and separated by a single space. It is similar to lodash.capitalize but applies the capitalization to each word in the string.

360
361
362
363
364
365
366
367
368
369
module.exports.splat               = _.splat;
module.exports.split               = _.split;
module.exports.splitAt             = _.splitAt;
module.exports.splitWith           = _.splitWith;
module.exports.spread              = _.spread;
module.exports.startCase           = _.startCase;
module.exports.startsWith          = _.startsWith;
module.exports.strContains         = _.strContains;
module.exports.stripTags           = _.stripTags;
module.exports.sub                 = _.sub;
fork icon19
star icon122
watch icon0

+ 92 other calls in file

110
111
112
113
114
115
116
117
118
self.template = self.options.template || 'widget';

self.name = self.__meta.name.replace(/-widget$/, '');

if (!self.options.label) {
  self.options.label = _.startCase(self.name);
}

self.label = self.options.label;
fork icon540
star icon0
watch icon0

Ai Example

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

const myString = "hello_world";
const formattedString = _.startCase(myString);
console.log(formattedString);
// Output: Hello World

In this example, lodash.startCase is used to convert a string from hello_world to Hello World. The function capitalizes the first letter of each word in the string and separates each word with a space.

519
520
521
522
523
524
525
526
527
528
}

get typeName() {
  let { type } = this
  type = typeNames[type] || type
  return lodash.startCase(type).toLowerCase()
}

get lastActivity() {
  return lodash.max(
fork icon73
star icon647
watch icon6

+ 6 other calls in file

198
199
200
201
202
203
204
205
206
207

writeRoute(dbDialect, modelName) {
  const routesPath = `routes/${ForestExpress.tableToFilename(modelName)}.js`;

  const modelNameDasherized = _.kebabCase(modelName);
  const readableModelName = _.startCase(modelName);

  this.copyHandleBarsTemplate('routes/route.hbs', routesPath, {
    modelName: ForestExpress.getModelNameFromTableName(modelName),
    modelNameDasherized,
fork icon2
star icon51
watch icon12

+ 13 other calls in file

7
8
9
10
11
12
13
14
15
16
		description: 'enforce writing React components consistently',
	},
	fixable: 'code',
},
create: function (context) {
	const componentName = _.startCase(
		path
			.basename(context.getFilename())
			.replace(/\..+/, '')
	).replace(/\s/g, '')
fork icon2
star icon3
watch icon1

+ 4 other calls in file

1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
}
if (!field.name) {
  fail('name property is missing.');
}
if (!field.label && !field.contextual) {
  field.label = _.startCase(field.name.replace(/^_/, ''));
}
if (field.if && field.if.$or && !Array.isArray(field.if.$or)) {
  fail(`$or conditional must be an array of conditions. Current $or configuration: ${JSON.stringify(field.if.$or)}`);
}
fork icon540
star icon0
watch icon125

2
3
4
5
6
7
8
9
10
11
12
13
const _ = require('lodash');
const tripleRegex =
  /^(?<subject>(<([^<>]+)>|^_:c14n\d+)) (?<predicate>(<([^<>]+)>)) (?<object>(.+))/;


const getLabelFromIri = (iri) => {
  return _.startCase(iri.split('/').pop().split('#').pop());
};


const isDidUrl = (iri) => {
  return (
fork icon1
star icon5
watch icon0

835
836
837
838
839
840
841
842
843
844
845
846
847
console.log(snakeCase); // => 'foo_bar'


const split = _.split('a-b-c', '-', 2);
console.log(split); // => ['a', 'b']


const startCase = _.startCase('--foo-bar--');
console.log(startCase); // => 'Foo Bar'


const startsWith = _.startsWith('abc', 'a');
console.log(startsWith); // => true
fork icon0
star icon4
watch icon0

+ 15 other calls in file

46
47
48
49
50
51
52
53
54
55
  .offset(offset);
const OldLeadsPromisedArr = OldLeads.map(async (lead) => {
  const payload = {
    lead_id: parseInt(lead.int_lead_id, 10),
    patient_name: lead.txt_lead_name
      ? _.startCase(_.toLower(_.trim(lead.txt_lead_name)))
      : "DEMO",
    patient_email: _.toLower(_.trim(lead.txt_lead_email)),
    patient_contact: _.trim(lead.int_contact),
    patient_city_id: getNewMappedCityId(lead.txt_current_city),
fork icon0
star icon1
watch icon0

178
179
180
181
182
183
184
185
186
187
if (!self.options.name) {
  throw new Error('@apostrophecms/pieces require name option');
}
if (!self.options.label) {
  // Englishify it
  self.options.label = _.startCase(self.options.name);
}
self.options.pluralLabel = self.options.pluralLabel || self.options.label + 's';

self.name = self.options.name;
fork icon539
star icon0
watch icon124

+ 2 other calls in file

430
431
432
433
434
435
436
437
438
439
for (const [stateName, data] of _.sortBy(_.toPairs(report), ([k, ]) => k)) {
    rows.push({label: stateName, value: null});

    for (const [key, value] of _.toPairs(data)) {
        if(key === 'stateName') continue;
        rows.push({label: _.startCase(key), value: value });
    }

    if(stateName !== 'ZAMFARA') rows.push({label: '', value: null });
}
fork icon0
star icon0
watch icon2

+ 9 other calls in file

307
308
309
310
311
312
313
314
315
316
lowerCase: (arg) => arg.toLowerCase(),
upperCase: (arg) => arg.toUpperCase(),
camelCase: (arg) => _.camelCase(arg),
snakeCase: (arg) => _.snakeCase(arg),
kebabCase: (arg) => _.kebabCase(arg),
startCase: (arg) => _.startCase(arg),
formatted: (format) => (insert) => format.replace(/(?<!\\)%s/g, insert),
first: (arg) => arg[0],
last: (arg) => arg[arg.length - 1],
prop: getProp,
fork icon0
star icon0
watch icon1

+ 2 other calls in file

Other functions in lodash

Sorted by popularity

function icon

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