Skip to content

[code-simplifier] Simplify URL normalization logic in CDN utilities#18062

Draft
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/url-normalization-20260310-57007bb219ae2d3c
Draft

[code-simplifier] Simplify URL normalization logic in CDN utilities#18062
github-actions[bot] wants to merge 1 commit intomasterfrom
code-simplifier/url-normalization-20260310-57007bb219ae2d3c

Conversation

@github-actions
Copy link
Contributor

Code Simplification - 2026-03-10

This PR simplifies recently modified code to improve clarity, consistency, and maintainability while preserving all functionality.

Files Simplified

  • packages/dev/core/src/Misc/tools.ts - Simplified URL normalization in GetAssetUrl and GetBabylonScriptURL methods
  • packages/tools/ktx2Decoder/src/transcoder.ts - Simplified URL normalization in GetWasmUrl method

Improvements Made

  1. Enhanced Clarity

    • Replaced verbose str[str.length - 1] === "/" checks with cleaner str.endsWith("/")
    • Replaced substring(0, str.length - 1) with more concise slice(0, -1)
    • Used template literals instead of string concatenation for versioned URL construction
  2. Improved Consistency

    • Applied the same pattern across all three URL normalization methods
    • Made the code more maintainable with a consistent approach to trailing slash removal
  3. Preserved Functionality

    • All changes are purely stylistic - no behavioral changes
    • Logic flow remains identical
    • Same error handling and edge cases

Changes Based On

Recent changes from:

Code Examples

Before:

const baseUrl = Tools.ScriptBaseUrl[Tools.ScriptBaseUrl.length - 1] === "/" 
    ? Tools.ScriptBaseUrl.substring(0, Tools.ScriptBaseUrl.length - 1) 
    : Tools.ScriptBaseUrl;
const versionedBase = Tools._DefaultCdnUrl + "/v" + Tools._CdnVersion;

After:

const baseUrl = Tools.ScriptBaseUrl.endsWith("/") 
    ? Tools.ScriptBaseUrl.slice(0, -1) 
    : Tools.ScriptBaseUrl;
const versionedBase = `\$\{Tools._DefaultCdnUrl}/v\$\{Tools._CdnVersion}`;

Testing

  • ✅ TypeScript syntax validated
  • ✅ No functional changes - behavior is identical
  • ✅ Simplified code is more readable and maintainable

Review Focus

Please verify:

  • Functionality is preserved (string operations produce identical results)
  • Simplifications improve code quality
  • Changes align with project conventions
  • No unintended side effects

Automated by Code Simplifier Agent - analyzing code from the last 24 hours

AI generated by Code Simplifier

  • expires on Mar 11, 2026, 12:55 AM UTC

Improved code clarity in recently modified URL processing methods:

- Replace verbose substring operations with cleaner endsWith() and slice()
- Use template literals for string concatenation
- Apply consistent pattern across GetAssetUrl, GetBabylonScriptURL, and GetWasmUrl

These changes improve readability without altering functionality.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants