Skip to content

fix(util): replace all underscores in snakeToTitleCase - #2845

Open
Mohd Quamar Tyagi (Tyagiquamar) wants to merge 1 commit into
braintrustdata:mainfrom
Tyagiquamar:fix/snake-to-title-case
Open

Mohd Quamar Tyagi (Tyagiquamar) wants to merge 1 commit into
braintrustdata:mainfrom
Tyagiquamar:fix/snake-to-title-case

Conversation

@Tyagiquamar

Copy link
Copy Markdown
Contributor

Summary

Fix snakeToTitleCase in js/util/string_util.ts so all underscores in multi-word snake_case strings are replaced with spaces instead of only the first underscore.

Root Cause & Problem

snakeToTitleCase previously called capitalize(s, "_").replace("_", " "). Because String.prototype.replace with a string pattern only replaces the first match, any input containing two or more underscores (such as "my_variable_name") retained the remaining underscores ("My Variable_Name" instead of "My Variable Name").

Technical Solution

  • Updated snakeToTitleCase in js/util/string_util.ts to use .replace(/_/g, " ") so every underscore is converted to a space.
  • Added a unit test for snakeToTitleCase in js/util/string_util.test.ts covering empty strings, single words, two-word inputs, and multi-underscore inputs.

Test Plan

  • pnpm exec vitest run util/string_util.test.ts (from js/): verified the new snakeToTitleCase test fails before the fix ("My Variable_Name" vs "My Variable Name") and passes after the fix (3/3 tests passing).
  • pnpm run check:typings (from js/): verified TypeScript typechecking passes for source and test files.
  • pnpm run formatting and pnpm run lint (from repo root): verified formatting and linting pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant