10 examples of 'capitalize js' in JavaScript

Every line of 'capitalize js' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
7capitalize(str) {
8 if (!str) {
9 return str;
10 }
11 return str.replace(/^(.)/, c => c.toUpperCase());
12}
28function uncapitalize(str) {
29 return (str.charAt(0).toLowerCase() + str.slice(1));
30}
145function capitalize(string) {
146 return string.replace(/^[a-z]/, function(str) {
147 return str.toUpperCase();
148 });
149}
1export default function capitalize(str) {
2 return str.replace(/\b\w/g, function (l) {
3 return l.toUpperCase()
4 });
5}
63function capitalize(str) {
64 return str.replace(/^[a-z]/, char => char.toUpperCase());
65}
1export default function capitalize(str: string) {
2 return `${str.slice(0, 1).toUpperCase()}${str.slice(1)}`;
3}
7function capitalize(str) {
8 return str && str[0].toUpperCase() + str.slice(1);
9}
21export function capitalize(str) {
22 return ucFirst(str);
23}
277export function capitalize(str: string): string {
278 return CAPITALIZE_CACHE.get(str);
279}
1function capitalize(str) {
2 'use strict';
3 // var firstLetter = str[0].toUpperCase();
4 // console.log(str.charAt(0));
5 var firstLetter = str.charAt(0).toUpperCase();
6 var rest = str.slice(1).toLowerCase();
7
8 return firstLetter + rest;
9}

Related snippets