Skip to main content

Strings

String transformation and generation utilities.

toPascalCase

Converts a camelCase string to PascalCase by inserting spaces before uppercase letters and capitalizing the first character.

import { toPascalCase } from '@repo/utils'

function toPascalCase(value: string): string

Example

import { toPascalCase } from '@repo/utils'

toPascalCase('helloWorld')
// 'Hello World'

toPascalCase('firstName')
// 'First Name'

toPascalCase('already')
// 'Already'

slugify

Converts a string into a URL-friendly slug. Lowercases, trims, removes special characters, and replaces spaces/underscores with hyphens.

import { slugify } from '@repo/utils'

function slugify(value: string): string

Example

import { slugify } from '@repo/utils'

slugify('Hello World!')
// 'hello-world'

slugify(' Some Article Title ')
// 'some-article-title'

slugify('foo_bar--baz')
// 'foo-bar-baz'

slugify('Price: $100 (USD)')
// 'price-100-usd'

generateUUID

Generates a UUID v7 string. UUID v7 is timestamp-based, so generated IDs are sortable by creation time.

import { generateUUID } from '@repo/utils'

function generateUUID(): string

Example

import { generateUUID } from '@repo/utils'

generateUUID()
// '01937a3c-b4f2-7a3c-8f12-4a6b8c9d0e1f'

// IDs generated later sort after earlier ones
const id1 = generateUUID()
const id2 = generateUUID()
id1 < id2 // true (when generated sequentially)