Repository navigation
fix(util): replace all underscores in snakeToTitleCase - #2845
Open
Mohd Quamar Tyagi (Tyagiquamar) wants to merge 1 commit into
Open
Mohd Quamar Tyagi (Tyagiquamar) wants to merge 1 commit into
Mohd Quamar Tyagi (Tyagiquamar) wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix
snakeToTitleCaseinjs/util/string_util.tsso all underscores in multi-word snake_case strings are replaced with spaces instead of only the first underscore.Root Cause & Problem
snakeToTitleCasepreviously calledcapitalize(s, "_").replace("_", " "). BecauseString.prototype.replacewith 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
snakeToTitleCaseinjs/util/string_util.tsto use.replace(/_/g, " ")so every underscore is converted to a space.snakeToTitleCaseinjs/util/string_util.test.tscovering empty strings, single words, two-word inputs, and multi-underscore inputs.Test Plan
pnpm exec vitest run util/string_util.test.ts(fromjs/): verified the newsnakeToTitleCasetest fails before the fix ("My Variable_Name"vs"My Variable Name") and passes after the fix (3/3 tests passing).pnpm run check:typings(fromjs/): verified TypeScript typechecking passes for source and test files.pnpm run formattingandpnpm run lint(from repo root): verified formatting and linting pass.