How to use the titleize function from underscore.string

Find comprehensive JavaScript underscore.string.titleize code examples handpicked from public code repositorys.

underscore.string.titleize is a function that capitalizes the first letter of each word in a given string.

31
32
33
34
35
36
37
38
39
40
41
/**
 * 
 * @param str 
 */
function titleize(str) {
    return _s.titleize(str);
}


/**
 * 
fork icon183
star icon970
watch icon0

+ 4 other calls in file

41
42
43
44
45
46
47
48
49
50
51
52
exports.unescapeHTML = function(value, options, callback){
    callback(null, str.unescapeHTML(String(value)));
};


exports.titleize = function(value, options, callback){
    callback(null, str.titleize(String(value)));
};


exports.camelize = function(value, options, callback){
    callback(null, str.camelize(String(value)));
fork icon2
star icon2
watch icon0

+ 2 other calls in file

How does underscore.string.titleize work?

underscore.string.titleize is a function in the Underscore.string library that capitalizes the first letter of each word in a given string. To use underscore.string.titleize(), you pass a string as its parameter. The method splits the string into words using white space as a delimiter and then capitalizes the first letter of each word. It returns the resulting string with the first letter of each word capitalized. For example, if you pass the string "the quick brown fox jumps over the lazy dog" to underscore.string.titleize(), it will return "The Quick Brown Fox Jumps Over The Lazy Dog". underscore.string.titleize() is particularly useful for formatting text in a more readable way, such as for titles, headings, or labels in user interfaces. Overall, underscore.string.titleize() provides a simple way to capitalize the first letter of each word in a string, making it more readable and visually appealing.

1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
ActiveResource.Collection.build(['email', 'firstName', 'lastName', 'zip']).select(function (q) {
  return !order.customer()[q];
}).each(function (q) {
  missingAnswers.push({
    id: q,
    label: 'Customer ' + s.titleize(s.humanize(q))
  });
});
order.answers().target().select(function (a) {
  return !a.valid();
fork icon1
star icon2
watch icon3

+ 4 other calls in file

41
42
43
44
45
46
47
48
49
50
51
52
}


// Convert a slug to a title
function slugToTitle (slug) {
  slug = slug.replace('.md', '').trim();
  return _s.titleize(_s.humanize(path.basename(slug)));
}


// Strip meta from Markdown content
function stripMeta (markdownContent) {
fork icon449
star icon0
watch icon97

+ 3 other calls in file

Ai Example

1
2
3
4
5
6
7
const _ = require("underscore.string");

const myString = "this is a test string";
const titleizedString = _.titleize(myString);

console.log(titleizedString);
// Output: This Is A Test String

In this example, we first import the underscore.string library and assign a test string to the myString variable. We then call _.titleize(myString) to capitalize the first letter of each word in the string. The resulting string is stored in the titleizedString variable. Finally, we log the titleizedString variable to the console, which outputs "This Is A Test String". Overall, this example demonstrates how to use underscore.string.titleize() to format a string by capitalizing the first letter of each word.

233
234
235
236
237
238
239
240
241
242
  }
}

filesProcessed.push({
  slug     : shortPath,
  title    : dirMetadata.title || _s.titleize(_s.humanize(path.basename(shortPath))),
  show_on_home: dirMetadata.show_on_home ? (dirMetadata.show_on_home === 'true') : this.config.show_on_home_default,
  is_index : false,
  is_directory: true,
  active   : activePageSlug.startsWith('/' + fileSlug),
fork icon0
star icon0
watch icon2

+ 43 other calls in file