The lodash method _.capitalize exported as a standalone module for capitalizing strings.
npx @tessl/cli install tessl/npm-lodash--capitalize@3.1.0The lodash method _.capitalize exported as a standalone Node.js module. This utility converts the first character of a string to uppercase and the remaining characters to lowercase, with robust type handling and edge case support.
npm install lodash.capitalizevar capitalize = require('lodash.capitalize');var capitalize = require('lodash.capitalize');
capitalize('FRED');
// => 'Fred'
capitalize('hello world');
// => 'Hello world'
capitalize('');
// => ''Converts the first character of a string to upper case and the remaining characters to lower case. Handles various data types through robust type conversion, including null/undefined values, numbers, and symbols.
/**
* Converts the first character of `string` to upper case and the remaining
* to lower case.
*
* @param {string} [string=''] The string to capitalize.
* @returns {string} Returns the capitalized string.
* @example
*
* capitalize('FRED');
* // => 'Fred'
*/
function capitalize(string);Usage Examples:
var capitalize = require('lodash.capitalize');
// Basic string capitalization
capitalize('FRED');
// => 'Fred'
capitalize('hello world');
// => 'Hello world'
capitalize('tEST');
// => 'Test'
// Edge cases - null and undefined
capitalize(null);
// => ''
capitalize(undefined);
// => ''
capitalize('');
// => ''
// Type conversion - numbers
capitalize(123);
// => '123'
capitalize(0);
// => '0'
// Special values
capitalize(-0);
// => '-0'
// Boolean conversion
capitalize(true);
// => 'True'
capitalize(false);
// => 'False'
// Array conversion
capitalize([1, 2, 3]);
// => '1,2,3'
capitalize(['hello', 'world']);
// => 'Hello,world'
// Object conversion
capitalize({});
// => '[object Object]'The function internally converts all input values to strings before applying capitalization:
''123 → '123')'true' or 'false'[1,2,3] → '1,2,3')'[object Object]' unless they have custom toStringThe function is designed to never throw errors. All input types are handled gracefully through internal type conversion, making it safe to use with any JavaScript value.