or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash--capitalize

The lodash method _.capitalize exported as a standalone module for capitalizing strings.

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/lodash.capitalize@3.1.x

To install, run

npx @tessl/cli install tessl/npm-lodash--capitalize@3.1.0

index.mddocs/

lodash.capitalize

The 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.

Package Information

  • Package Name: lodash.capitalize
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install lodash.capitalize

Core Imports

var capitalize = require('lodash.capitalize');

Basic Usage

var capitalize = require('lodash.capitalize');

capitalize('FRED');
// => 'Fred'

capitalize('hello world');
// => 'Hello world'

capitalize('');
// => ''

Capabilities

String Capitalization

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]'

Type Conversion Behavior

The function internally converts all input values to strings before applying capitalization:

  • Strings: Used directly
  • null/undefined: Converted to empty string ''
  • Numbers: Converted to string representation (e.g., 123'123')
  • Booleans: Converted to 'true' or 'false'
  • Arrays: Converted using default toString (e.g., [1,2,3]'1,2,3')
  • Objects: Converted to '[object Object]' unless they have custom toString
  • Symbols: Converted using Symbol.prototype.toString when available

Error Handling

The 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.