locutus
Version:
Locutus other languages' standard libraries to JavaScript for fun and educational purposes
18 lines (17 loc) • 561 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ucfirst = ucfirst;
function ucfirst(str) {
// discuss at: https://locutus.io/perl/ucfirst/
// parity verified: Perl 5.40
// original by: Kevin van Zonneveld (https://kvz.io)
// example 1: ucfirst('hello')
// returns 1: 'Hello'
// example 2: ucfirst('hELLO')
// returns 2: 'HELLO'
const value = String(str);
if (!value) {
return '';
}
return value.charAt(0).toUpperCase() + value.slice(1);
}