feat(replace): add replace#8
Conversation
WalkthroughThis update introduces new conditional types to perform compile-time string replacement operations in TypeScript. A private utility type ( Changes
Possibly related PRs
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (4)
src/string/replace/index.ts (1)
3-10: Fix typos in JSDoc documentation.The JSDoc documentation contains several issues:
- "oryginal" is misspelled multiple times (should be "original")
- Return type should be a type literal instead of {string} since this is a type-level operation
Apply this diff to fix the documentation:
/** - * Replace substring on a type level. If substring is not a part of string, the oryginal strnig will be returned. + * Replace substring on a type level. If substring is not a part of string, the original string will be returned. * * @template Str - The string type to check against. - * @template StrToReplace - Part of the oryginal string. + * @template StrToReplace - Part of the original string. * @template Replacement - String that will replace second arg. - * @returns {string} - Returns string with replaced substring or oryginal string if the substring to replace was not found in oryginal string. + * @returns Returns string type with replaced substring or original string type if the substring to replace was not found in original string. */src/string/replace/index.test.ts (3)
36-43: Consider renaming test case for consistency.The test case uses T5 while previous tests use T1-T3. Consider renaming it to T4 for better readability and consistency.
- type T5 = _ReplaceString< + type T4 = _ReplaceString< "hello world", "goodbye", "universe" > - expectTypeOf<T5>().toEqualTypeOf<"hello world">() + expectTypeOf<T4>().toEqualTypeOf<"hello world">()
89-96: Enhance comment clarity for empty replacement.The current comment could be more descriptive about the two-step process needed for complete word removal.
- // this would make sense if user would like to remove a word from literal, than he can do it again for tailing space + // Replacing with empty string allows word removal. Note: Trailing space can be removed in a separate operation if needed
107-114: Improve comment for empty search string case.The current comment "this would make no sense" could be more descriptive about why this behavior is implemented.
- expectTypeOf<T8>().toEqualTypeOf<"hello world">() // this would make no sense + expectTypeOf<T8>().toEqualTypeOf<"hello world">() // Empty search string is treated as no-op to prevent unintended replacements
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
src/string/replace/algo.ts(1 hunks)src/string/replace/index.test.ts(1 hunks)src/string/replace/index.ts(1 hunks)
🔇 Additional comments (2)
src/string/replace/algo.ts (1)
3-15: LGTM! Well-structured type implementation.The conditional type implementation elegantly handles all edge cases for string replacement. The use of template literal types and type inference with
inferis appropriate here.src/string/replace/index.test.ts (1)
8-115: LGTM! Comprehensive test coverage.The test suite thoroughly covers all edge cases including:
- Position-based replacements (start, middle, end)
- Special characters and multibyte characters
- Length variations (longer/shorter replacements)
- Empty string scenarios
Summary by CodeRabbit