How to use the capitalize function from underscore.string

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

underscore.string.capitalize is a method in the Underscore.string library that capitalizes the first letter of a string, making the string appear as a proper noun or sentence.

7
8
9
10
11
12
13
14
15
16
17
/**
   * 将字符串的第一个字母转换为大写。
   * @param str 
   */
function capitalize(str) {
    return _s.capitalize(str);
}


/**
 * 
fork icon183
star icon970
watch icon0

+ 4 other calls in file

124
125
126
127
128
129
130
131
132
133
if (req.query.denied) {
  return next(new Error(`${provider} denied`))
}
// Determine if we're linking the account and handle any Gravity errors
// that we can do a better job explaining and redirecting for.
const providerName = capitalize(provider)
const linkingAccount = req.user != null

passport.authenticate(provider)(req, res, function (err) {
  let msg
fork icon145
star icon534
watch icon65

+ 12 other calls in file

How does underscore.string.capitalize work?

underscore.string.capitalize is a method in the Underscore.string library that capitalizes the first letter of a string, making the string appear as a proper noun or sentence. When you call _.capitalize(string), the function takes a string as an argument and returns a new string with the first letter capitalized. The remaining characters in the string are preserved. For example, if you call _.capitalize('hello, world!'), the function will return the string "Hello, world!". Note that _.capitalize only capitalizes the first letter of the string. If you need to capitalize the first letter of each word in a string, you can use _.titleize instead. In essence, _.capitalize provides a simple way to capitalize the first letter of a string, which can be useful for formatting strings in a more readable or standardized way.

193
194
195
196
197
198
199
200
201
202
consumes: [
  'application/json',
  'application/xml'
],
info: {
  title: _.map(_str.words(_str.humanize(concurSwagger.resourcePath)), w => { return _str.capitalize(w); }).join(' '),
  description: '',
  version: concurSwagger.apiVersion
},
tags: [{
fork icon76
star icon8
watch icon0

71
72
73
74
75
76
77
78
79
80
var logLevelsLowerCase = _.map(service.logLevels, function(level) {
  return level.toLowerCase()
})

var logLevelsCapitalized = _.map(logLevelsLowerCase, function(level) {
  return _s.capitalize(level)
})

for (var i = 2; i < 8; ++i) {
  service.filters.levelNumbers.push({number: i, name: logLevelsCapitalized[i]})
fork icon16
star icon22
watch icon10

+ 2 other calls in file

Ai Example

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

const str = "the quick brown fox jumps over the lazy dog";

const capitalizedStr = _.capitalize(str);

console.log(capitalizedStr);

In this example, we first import the underscore.string library. We then define a string to capitalize: 'the quick brown fox jumps over the lazy dog'. Next, we call _.capitalize(str) to create a new string with the first letter of the original string capitalized. The resulting string, capitalizedStr, will be "The quick brown fox jumps over the lazy dog", with the first letter capitalized. Note that _.capitalize only capitalizes the first letter of the string, leaving the rest of the characters unchanged.

103
104
105
106
107
108
109
110
111
112
113


module.exports.afterSocialAuth = provider => (function(req, res, next) {
  if (req.query.denied) { return next(new Error(`${provider} denied`)); }
  // Determine if we're linking the account and handle any Gravity errors
  // that we can do a better job explaining and redirecting for.
  const providerName = capitalize(provider);
  const linkingAccount = (req.user != null);
  passport.authenticate(provider)(req, res, function(err) {
    let msg;
    if (err && err.response && err.response.body && err.response.body.error === 'User Already Exists') {
fork icon18
star icon10
watch icon55

90
91
92
93
94
95
96
97
98
99
},
getterSetterName: function(columnName) {
  return columnName.trim().replace(/\s/g, '_');
},
validatorSanitizerName: function(operation, columnName) {
  var name = nm_s.capitalize(columnName.trim().replace(/\s/g, '_'));
  return operation + name;
},
typeSpecificSetterName: function(operation, columnName) {
  var name = nm_s.capitalize(columnName.trim().replace(/\s/g, '_'));
fork icon3
star icon17
watch icon4

+ 9 other calls in file

124
125
126
127
128
129
130
131
132
133
134
// =============
// = Callbacks =
// =============


nm_.each(Schema._CALLBACK_KEYS, function(key, index) {
  var methodName = 'add' + nm_s.capitalize(key) + 'Callback';
  Schema.prototype[methodName] = function(callback) {
    addCallback.call(this, key, callback);
  };
});
fork icon3
star icon17
watch icon4

+ 3 other calls in file

25
26
27
28
29
30
31
32
33
34
35
36
exports.lowerCase = function(value, options, callback){
    callback(null, String(value).toLowerCase());
};


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


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

+ 2 other calls in file

154
155
156
157
158
159
160
161
162
163
164
165
    };
    return `#${color.r}${color.g}${color.b}`;
};


const cleanAll = (str) => {
    return capitalize(cleanDiacritics(str), true);
};


module.exports.returnMonth = (str) => {
    const m = cleanAll(str);
fork icon0
star icon2
watch icon0

16
17
18
19
20
21
22
23
24
25
parseFilters: {
	left: function(value, args) {
		return value.substring(0, args[0] && args[0] <= value.length ? args[0] : value.length);
	},
	ucfirst: function(value) {
		return _string.capitalize(value);
	},
	strtoupper: function(value) {
		return value.toUpperCase();
	},
fork icon0
star icon1
watch icon0

+ 2 other calls in file

21
22
23
24
25
26
27
28
29
30
 */
let getAllSettingsFromComponentName = (componentName) => {
  const style = 'css';
  let cleanedPaths = getCleanedPathName(componentName);
  let componentParts = cleanedPaths.split('/');
  let componentBaseName = _.capitalize(componentParts.pop());
  let componentPartPath = componentParts.join('/');
  let componentFullName = _.classify(_.replaceAll(componentName, '/', '_'));
  let styleSettings = configUtils.getChoiceByKey('style', style);
  let componentPath = configUtils.getChoiceByKey('path', 'component');
fork icon0
star icon1
watch icon0

+ 5 other calls in file

94
95
96
97
98
99
100
101
102
103
/**
 * Sets the concrete API Service (e.g. TwitterService) and its overrides
 */
_setupConcreteService() {
  sails.log.info('BaseAppService: _setupConcreteService()');
  // var serviceName = s.capitalize(this.playlistitem.appType)+'Service';

  // if(_.isUndefined(global[serviceName])) {
  //   sails.log.error('No Service "'+serviceName+'" found.');
  // }
fork icon0
star icon0
watch icon2

+ 3 other calls in file

91
92
93
94
95
96
97
98
99
100
/**
 * Sets the concrete API Service (e.g. TwitterService) and its overrides
 */
_setupConcreteService: function() {
  sails.log.info('AppService: _setupConcreteService()');
  var serviceName = s.capitalize(this.playlistitem.appType)+'Service';

  if(_.isUndefined(global[serviceName])) {
    sails.log.error('No Service "'+serviceName+'" found.');
  }
fork icon0
star icon0
watch icon2

+ 3 other calls in file

157
158
159
160
161
162
163
164
165
166
167
168
// and should be translated into N.(N.N.) Last


function fix_author(a) {
  let name = a.name;
  let components = $.words(name, ",");
  let first_name = $.capitalize($.clean(components[1]), true);
  let last_name = $.capitalize($.clean(components[0]), true);


  if (_.isPlainObject(patt[last_name])) {
    ({ name } = patt[last_name]);
fork icon0
star icon0
watch icon2

+ 3 other calls in file

149
150
151
152
153
154
155
156
157
158
_.each(resume.skills, function (skill_info) {
  var levels = ['Beginner', 'Intermediate', 'Advanced', 'Master'];

  if (skill_info.level) {
    skill_info.skill_class = skill_info.level.toLowerCase();
    skill_info.level = _s.capitalize(skill_info.level.trim());
    skill_info.display_progress_bar = _.contains(levels,
      skill_info.level);
  }
});
fork icon0
star icon0
watch icon0

189
190
191
192
193
194
195
196
197
198
// do not try to match verbs, levenhstain could confuse "off" with "on" in phrasal verbs, also
// it doesn't catch infinitive, checked in a following rule
if (this.type === 'verb' || this.type === 'date') {
  return false;
}
var capitalizedType = _s.capitalize(this.type);
// if the type is ok, capture the text or verify, nlp-compromise types are always capitalized (like noun),
// while custom lexicons can be in any case (that explains the double or)
if (term.tags[capitalizedType] || term.tags[this.type] || this.type === 'word') {
  if (!_.isEmpty(this.text)) {
fork icon0
star icon0
watch icon0