String manipulation and transformation utilities for TypeScript.
Converts a string to camelCase format.
Converts a string to kebab-case format.
Converts a string to PascalCase format.
Converts a string to snake_case format.
Converts a string to Title Case format.
Converts identifiers to natural language words.
Converts a singular word to its plural form.
Converts a plural word to its singular form.
Formats a number with a unit, automatically pluralizing based on count.
import {
toCamelCase,
toKebabCase,
toPascalCase,
toSnakeCase,
toTitleCase,
toWords,
toPlural,
toSingular,
quantify
} from '@agape/string';
// Case conversion
toCamelCase('user name') // "userName"
toCamelCase('email-address') // "emailAddress"
toKebabCase('Display Name') // "display-name"
toKebabCase('userProfileId') // "user-profile-id"
toPascalCase('user id') // "UserId"
toPascalCase('api_response_code') // "ApiResponseCode"
toSnakeCase('userName') // "user_name"
toSnakeCase('APIResponseCode') // "api_response_code"
toTitleCase('the lord of the rings') // "The Lord of the Rings"
toTitleCase('war and peace') // "War and Peace"
// Natural language
toWords('user-profile-id') // "User profile id"
toWords('XMLHttpRequest') // "XML Http Request"
// Pluralization
toPlural('city') // "cities"
toPlural('analysis') // "analyses"
toPlural('API') // "APIs"
toSingular('cities') // "city"
toSingular('analyses') // "analysis"
toSingular('APIs') // "API"
// Quantification
quantify(1, 'item') // "1 item"
quantify(3, 'box') // "3 boxes"
quantify(1, 'child', 'children') // "1 child"
quantify(2, 'child', 'children') // "2 children"
quantify(5, 'CPU') // "5 CPUs"Converts a string to camelCase by removing non-alphanumeric separators and capitalizing each word except the first.
Examples:
"hello world"β"helloWorld""API_response_code"β"apiResponseCode""user-42-profile"β"user42Profile"
Converts a string to kebab-case by replacing spaces, underscores, and camelCase transitions with dashes. Preserves version tokens like "v2".
Examples:
"hello world"β"hello-world""UserProfileV2"β"user-profile-v2""HTML5 Parser"β"html-5-parser"
Converts a string to PascalCase by removing non-alphanumeric characters, splitting on casing and digits, and capitalizing each word.
Examples:
"hello world"β"HelloWorld""user42Profile"β"User42Profile""API response code"β"ApiResponseCode"
Converts a string to snake_case by replacing spaces, dashes, and camelCase transitions with underscores. Preserves version tokens.
Examples:
"hello world"β"hello_world""UserProfileV2"β"user_profile_v2""HTML5 Parser"β"html_5_parser"
Converts a string to Title Case by capitalizing the first letter of each word, except for small words (like "of", "and", "the") unless they appear at the beginning.
Examples:
"the quick brown fox"β"The Quick Brown Fox""a tale of two cities"β"A Tale of Two Cities""API reference guide"β"API Reference Guide"
Converts identifiers to natural language words by splitting camelCase, PascalCase, snake_case, and kebab-case into space-separated words.
Examples:
"userProfileId"β"User profile id""XMLHttpRequest"β"XML Http Request""api_v2_response"β"Api v2 response"
Converts a singular word to its plural form using common English pluralization rules.
Features:
- Handles irregular plurals (child β children, person β people)
- Preserves acronyms (API β APIs, ID β IDs)
- Maintains original casing
Examples:
"city"β"cities""box"β"boxes""child"β"children""API"β"APIs"
Converts a plural word to its singular form using common English patterns.
Features:
- Handles irregular plurals (children β child, people β person)
- Preserves original casing
- Smart about double letters (boss β boss, not bo)
Examples:
"cities"β"city""boxes"β"box""children"β"child""APIs"β"API"
Formats a number with a unit, automatically pluralizing the unit based on the count.
Parameters:
count: Number of units (number or string)unit: Label for the singular unitplural: Optional plural label (auto-generated if not provided)
Examples:
quantify(1, 'item')β"1 item"quantify(3, 'box')β"3 boxes"quantify(1, 'child', 'children')β"1 child"quantify(2, 'child', 'children')β"2 children"
See the full API documentation at agape.dev/api.
This package is part of the Agape Toolkit - a comprehensive collection of TypeScript utilities and libraries for modern web development.