or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

index.md
tile.json

tessl/npm-lodash-upperfirst

Converts the first character of string to upper case with Unicode support

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

To install, run

npx @tessl/cli install tessl/npm-lodash-upperfirst@4.3.0

index.mddocs/

lodash.upperfirst

lodash.upperfirst provides the upperFirst utility function that converts the first character of a string to uppercase while preserving the rest unchanged. It includes sophisticated Unicode handling with support for astral plane characters, combining marks, and zero-width joiners, making it ideal for internationalization and proper text formatting.

Package Information

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

Core Imports

var upperFirst = require('lodash.upperfirst');

Basic Usage

var upperFirst = require('lodash.upperfirst');

// Basic string capitalization
upperFirst('fred');
// => 'Fred'

// Already uppercase
upperFirst('FRED');
// => 'FRED'

// Empty string
upperFirst('');
// => ''

// Unicode characters
upperFirst('émilie');
// => 'Émilie'

// Works with null/undefined
upperFirst(null);
// => ''

upperFirst(undefined);
// => ''

Capabilities

String Case Conversion

Converts the first character of string to upper case with full Unicode support.

/**
 * Converts the first character of `string` to upper case.
 * 
 * @param {string} [string=''] The string to convert.
 * @returns {string} Returns the converted string.
 */
function upperFirst(string)

Parameters:

  • string (string, optional): The string to convert. Defaults to empty string if not provided.

Returns:

  • (string): Returns the converted string with first character in uppercase

Key Features:

  • Unicode-aware: Properly handles complex Unicode sequences including emojis, accented characters, and combining marks
  • Astral plane support: Correctly processes characters from the astral planes (U+10000 to U+10FFFF)
  • Zero-width joiner handling: Preserves zero-width joiners and variation selectors in complex scripts
  • Null-safe: Gracefully handles null, undefined, and non-string inputs by converting them to empty strings first
  • Performance optimized: Uses efficient regex patterns and optimized string processing for both ASCII and Unicode text

Unicode Examples:

// Emoji with skin tone modifiers - emoji stays unchanged (no uppercase form)
upperFirst('👨🏽‍💻developer');
// => '👨🏽‍💻developer' (emoji treated as single character, has no uppercase)

// Complex Unicode sequences
upperFirst('नमस्ते world');
// => 'नमस्ते world'

// Arabic with combining marks
upperFirst('أهلاً');
// => 'أهلاً'

// Accented characters
upperFirst('naïve');
// => 'Naïve'

Type Conversion Examples:

// Numbers are converted to strings first
upperFirst(123);
// => '123'

// Booleans are converted to strings first
upperFirst(true);
// => 'True'

// Arrays are converted to strings first
upperFirst([1, 2, 3]);
// => '1,2,3'