Skip to content

Refactor: Extract URL parsing logic and improve code organization - #1

Merged
sak0a merged 4 commits into
masterfrom
claude/refactor-cs2-inspect-lib-y9i6D
Feb 13, 2026
Merged

sak0a merged 4 commits into
masterfrom
claude/refactor-cs2-inspect-lib-y9i6D

Conversation

@sak0a

@sak0a sak0a commented Feb 13, 2026

Copy link
Copy Markdown
Owner

Summary

This PR refactors the codebase to improve maintainability and code organization by extracting shared URL parsing logic into reusable helper functions, consolidating duplicate code, and improving error handling consistency.

Key Changes

Code Extraction & Deduplication

  • New helper function decodeMaskedFromAnalyzed(): Extracted common masked URL decoding logic that was duplicated across CS2Inspect.decodeMaskedUrl() and the standalone decodeMaskedUrl() function. This eliminates code duplication and ensures consistent error handling.
  • URL parsing delegation: UrlAnalyzer now delegates to pure functions in utils/url-parser.ts (parseInspectUrl() and formatInspectUrl()), removing ~200 lines of duplicated parsing logic from the class.

Improved Error Handling & Logging

  • Consistent error messages: Simplified and standardized error messages across the codebase, removing emoji decorations and verbose examples from JSDoc comments for cleaner documentation.
  • Debug logging refactor: Replaced scattered console.log() calls in SteamClient and SteamClientManager with a centralized debugLog() method that respects the enableLogging configuration flag.
  • Better timeout handling: Extracted waitForReady() method in SteamClient to reduce code duplication in connection logic.

Performance Optimizations

  • Pre-computed CRC32 table: Moved CRC32 lookup table generation to module load time in ProtobufWriter, eliminating redundant table generation on every crc32() call.
  • Optimized queue cleanup: Changed cleanExpiredItems() in SteamClient to iterate backwards when removing items, avoiding index shifting issues.

Code Quality Improvements

  • Simplified inspectItem() function: Refactored argument parsing logic to be more straightforward and maintainable, with clearer separation between options format and config-only format.
  • Removed redundant comments: Cleaned up JSDoc comments by removing performance optimization notes that are now implicit in the code structure.
  • Fixed deprecated method usage: Replaced substr() with slice() in ProtobufReader for better compatibility.
  • Improved rarity validation: Enhanced processRarity() to throw descriptive errors for invalid rarity values instead of silently defaulting.

Documentation Cleanup

  • Removed verbose code examples from JSDoc comments while keeping essential documentation
  • Simplified warning messages in function documentation
  • Removed performance optimization markers that are now implicit in the refactored code

Implementation Details

  • The decodeMaskedFromAnalyzed() helper maintains the same error handling behavior as the original implementations, ensuring backward compatibility
  • All refactored functions maintain their original signatures and behavior
  • The CRC32 table is now a module-level constant, improving performance for repeated calls
  • Debug logging is now consistently controlled via configuration rather than always-on console output

https://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW

…moved)

- Centralize INSPECT_BASE constant: defined once in url-parser.ts, imported elsewhere
- Eliminate URL parsing duplication: UrlAnalyzer class delegates to pure functions
  in url-parser.ts instead of duplicating ~200 lines of identical parsing/formatting logic
- Consolidate URL dispatch logic: extract decodeMaskedFromAnalyzed() helper in
  index.ts, collapse two inspectItem() code paths into one by normalizing args
- Extract waitForReady() helper in steam-client.ts to deduplicate promise timeout pattern
- Fix cleanExpiredItems() O(n^2) algorithm: use single reverse-iteration pass
- Fix redundant hex validation: remove unreachable >2000 check (>4096 is correct)
- Fix deprecated substr() usage: replace with slice() in protobuf-reader.ts

All existing tests pass. No public API changes.

https://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW
…sRarity

- Cache CRC32 lookup table as module-level constant instead of regenerating
  the 256-entry table on every createInspectUrl() call
- Replace all bare console.log/error/warn calls in steam-client.ts and
  steam-client-manager.ts with debugLog() that respects enableLogging config
- Fix processRarity() to throw EncodingError on unknown string values instead
  of silently returning STOCK (0), and remove unreachable final return
- Remove no-op ternary `typeof item.defindex === 'number' ? item.defindex : item.defindex`

https://claude.ai/code/session_01Ur7bfZrcaiPGhM6N8AQehW
@sak0a sak0a self-assigned this Feb 13, 2026
@sak0a
sak0a merged commit c645e52 into master Feb 13, 2026
2 checks passed
@sak0a
sak0a deleted the claude/refactor-cs2-inspect-lib-y9i6D branch February 13, 2026 14:56
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.

2 participants