Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

String manipulation and transformation utilities for case conversion, pluralization, and formatting.

License

Notifications You must be signed in to change notification settings

AgapeToolkit/agape-string

Repository files navigation

@agape/string

String manipulation and transformation utilities for TypeScript.

✨ Functions

toCamelCase(input: string)

Converts a string to camelCase format.

toKebabCase(input: string)

Converts a string to kebab-case format.

toPascalCase(input: string)

Converts a string to PascalCase format.

toSnakeCase(input: string)

Converts a string to snake_case format.

toTitleCase(input: string)

Converts a string to Title Case format.

toWords(input: string)

Converts identifiers to natural language words.

toPlural(word: string)

Converts a singular word to its plural form.

toSingular(word: string)

Converts a plural word to its singular form.

quantify(count: number | string, unit: string, plural?: string)

Formats a number with a unit, automatically pluralizing based on count.


πŸš€ Example

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"

πŸ”§ Function Details

toCamelCase(input: string)

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"

toKebabCase(input: string)

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"

toPascalCase(input: string)

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"

toSnakeCase(input: string)

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"

toTitleCase(input: string)

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"

toWords(input: string)

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"

toPlural(word: string)

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"

toSingular(word: string)

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"

quantify(count: number | string, unit: string, plural?: string)

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 unit
  • plural: 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"

πŸ“š Documentation

See the full API documentation at agape.dev/api.

πŸ“¦ Agape Toolkit

This package is part of the Agape Toolkit - a comprehensive collection of TypeScript utilities and libraries for modern web development.

About

String manipulation and transformation utilities for case conversion, pluralization, and formatting.

Topics

Resources

License

Stars

Watchers

Forks

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /