How to use the classify function from underscore.string
Find comprehensive JavaScript underscore.string.classify code examples handpicked from public code repositorys.
underscore.string.classify is a function that converts a string to a class name in TitleCase.
24 25 26 27 28 29 30 31 32 33
}]); const template = { appName: props.appName, slugifiedAppName: _s.slugify(props.appName), classifiedAppName: _s.classify(props.appName), githubUsername: props.githubUsername, repoUrl: `https://github.com/${props.githubUsername}/${props.slugifiedAppName}`, name: this.user.git.name(), email: this.user.git.email(),
109 110 111 112 113 114 115 116 117 118
) ], [ path.join('test/spec', targetDirectory, name + '.js'), new RegExp( 'describe\\(\'' + _.classify(specType) + ': ' + specNameFn(name) + suffix + '\'', 'g' ) ] ]);
How does underscore.string.classify work?
underscore.string.classify is a method in the Underscore.string library that converts a string to CamelCase, capitalizing the first letter of each word and removing any non-alphanumeric characters. It is often used for generating class or variable names based on a string input. Internally, the method uses underscore.string.titleize to capitalize the first letter of each word and then removes any spaces or underscores, resulting in a string in CamelCase format.
84 85 86 87 88 89 90 91 92
var fileExt = templateFilename ? templateFilename.split('.').pop() : ''; mkdirp(dest + templatePathWithoutFileName, function () { var injectedData = { name: options.componentName, Name: _s.classify(options.componentName), Name_: _.snakeCase(options.componentName).toUpperCase(), name_: _.snakeCase(options.componentName) };
+ 3 other calls in file
49 50 51 52 53 54 55 56 57 58 59 60
exports.camelize = function(value, options, callback){ callback(null, str.camelize(String(value))); }; exports.classify = function(value, options, callback){ callback(null, str.classify(String(value))); }; exports.underscored = function(value, options, callback){ callback(null, str.underscored(String(value)));
+ 2 other calls in file
Ai Example
1 2 3 4 5
const _ = require("underscore.string"); console.log(_.classify("hello world")); // output: HelloWorld console.log(_.classify("user_profile")); // output: UserProfile console.log(_.classify("search_term")); // output: SearchTerm
In this example, we're using underscore.string.classify to convert a string to a class name format. The function takes a string as input and converts it to a camel-cased version with the first letter capitalized.
157 158 159 160 161 162 163 164 165 166
}); angular.run([], function (){ angularGenerator.run([], function () { helpers.assertFiles([ [path.join('app/scripts', targetDirectory, name + '.js'), new RegExp(generatorType + '\\(\'' + scriptNameFn(name) + suffix + '\'', 'g')], [path.join('test/spec', targetDirectory, name + '.js'), new RegExp('describe\\(\'' + _.classify(specType) + ': ' + specNameFn(name) + suffix + '\'', 'g')] ]); done(); }); });
52 53 54 55 56 57 58 59 60 61
this.fs.copyTpl( this.templatePath('.'), this.destinationPath('.'), { FIELD_NAMESPACE: this.props.project_namespace.replace(/(\/)/g, '\\'), FIELD_NAME: s.dasherize(this.props.project_name), FIELD_NAME_JS: s.classify(this.props.project_name).toLowerCase(), FIELD_NAME_PHP: field_name_php_camel_case, FIELD_NAME_CLASS_PHP: field_name_class_php, FIELD_NAME_PHP_PATH: 'CARBON_' + s.underscored(this.props.project_name).toUpperCase() + '_DIR', FIELD_NAME_COMPOSER: this.props.composer.replace('\\', '/'),
+ 2 other calls in file
23 24 25 26 27 28 29 30 31 32
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'); let settings; settings = {
+ 2 other calls in file
149 150 151 152 153 154 155 156 157 158
} } } }); } return new SdkEndpoint_1.SdkEndpoint(operationKey, api.info.title || '', api.info.description || '', api.info.version, _.classify(operation.summary || '') + _.classify(operationKey), operation.description || '', sdkParameters, sdkResponse, sdkErrors); } function getName(path) { let parts = path.split('/'); return parts[parts.length - 1];
+ 2 other calls in file
81 82 83 84 85 86 87 88 89 90
}]; this.prompt(prompts, function(props) { this.componentNameRaw = props.componentName.trim(); this.componentName = str.slugify(this.componentNameRaw); this.componentClassName = str.classify(this.componentNameRaw); this.description = props.description.trim(); this.license = props.license; this.contrib = props.contrib; this.strict = props.strict;
underscore.string.slugify is the most popular function in underscore.string (323 examples)