Skip to content

String Functions

A collection of utility functions for working with strings.

truncate

Truncates a string if it’s longer than the maximum length.

const longText = "This is a very long text that needs to be truncated";
const truncated = truncate(longText, 20);
console.log(truncated); // "This is a very long..."

slugify

Converts a string to a URL-friendly slug.

const title = "Hello World! This is a Test";
const slug = slugify(title);
console.log(slug); // "hello-world-this-is-a-test"

capitalize

Capitalizes the first letter of a string.

const text = "hello world";
const capitalized = capitalize(text);
console.log(capitalized); // "Hello world"