Capitalize

Capitalizes the first letter of a string. This is a utility Typescript function that can be copy & pasted into your codebase.

Step-By-Step Guide

1. Copy the Source Code

@/lib/utils.ts

1/**
2 * Capitalizes the first letter of a string.
3 *
4 * @param str - The string to capitalize.
5 * @returns The capitalized string.
6 */
7export function capitalize(str: string) {
8	if (!str || typeof str !== 'string') return str;
9	return str.charAt(0).toUpperCase() + str.slice(1);
10}

2. Use it in a file

/page.tsx

1import { capitalize } from '@/lib/utils';
2
3export default function SomeComponent(){
4	const lowercaseTitle = "title";
5
6	return (
7		<div>{capitalize(lowercaseTitle)}</div>
8	)
9}

Tech Stack

Only the finest ingredients are used in our products. We made sure that we only use the best technologies available which offer a free tier! Yes, you read that right. Everything can be set up for FREE!

TypeScript

TypeScript

TypeScript ensures that your code is always correct. It is the best way to write JavaScript.

Programming Language

You May Also Like

Didn't find what you were looking for? Check out these other items.

Ui Component Library Template
Internal link to /templates/ui-component-library
Templates

Ui Component Library

Want to create your own Ui Component Library like shadcn/ui? This is your template!

Product Image
Internal link to /functions/cn
Functions

cn

Combines multiple Tailwind class names into a single string.

Product Image
Internal link to /functions/is-base-64
Functions

isBase64

Checks if a string is a valid base64 encoded string.

Frequently Asked Questions

We have compiled a list of frequently asked questions. If you have any other questions, please do not hesitate to contact us via email or using the chat function. We are here to help!

Interested in kickstarting your next project?

Get the latest boilerplates, components, and news straight to your inbox.

By signing up, you agree to our Privacy Policy