TypeScript example

Convert snake_case to camelCase in TypeScript

A typed TypeScript helper can split underscore-delimited tokens, normalize their casing, and return a predictable camelCase string.

By Camel Case Converter Editorial TeamPublished Sep 12, 2026Last reviewed

TypeScript code

function snakeToCamel(value: string): string {
  const parts = value.trim().replace(/^_+|_+$/g, "").split(/_+/).filter(Boolean)
  if (parts.length === 0) return ""
  return parts[0].toLowerCase() + parts.slice(1).map((part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()).join("")
}

snakeToCamel("user_profile_image")
// "userProfileImage"

The helper accepts and returns string values, making it easy to reuse in typed utilities, adapters, and mapping code.

Runtime conversion and type-level object-key remapping are separate concerns; converting a network payload still requires runtime logic.

Edge cases to consider

  • Acronyms may require apiResponseURL instead of apiResponseUrl.
  • Recursive object conversion also requires deciding how deeply TypeScript types reflect the runtime result.
  • Mixed separators need broader tokenization.
  • Different source keys can normalize to one key and must not be silently overwritten.

Example

BeforeAfter
user_profile_imageuserProfileImage
__user__profile__userProfile
api_response_urlapiResponseUrl
created_atcreatedAt

TypeScript code

const cases: Array<[string, string]> = [
  ["user_profile_image", "userProfileImage"],
  ["__user__profile__", "userProfile"],
  ["api_response_url", "apiResponseUrl"],
  ["created_at", "createdAt"],
]

for (const [input, expected] of cases) {
  if (snakeToCamel(input) !== expected) throw new Error(input)
}

Try the conversion online

Use the browser-based converter for quick checks, batch values, acronym handling, or inputs that mix several naming conventions.

Detected: snake_case
camelCase output
userProfileImageUrl

All naming formats

camelCase
userProfileImageUrl
PascalCase
UserProfileImageUrl
snake_case
user_profile_image_url
kebab-case
user-profile-image-url
CONSTANT_CASE
USER_PROFILE_IMAGE_URL
dot.case
user.profile.image.url
path/case
user/profile/image/url

Conversion happens locally in your browser. Your input is not sent to a conversion server.