Skip to content

refactor: extract delegate functions from filesize for better SRP#257

Merged
avoidwork merged 11 commits intomasterfrom
audit
Apr 20, 2026
Merged

refactor: extract delegate functions from filesize for better SRP#257
avoidwork merged 11 commits intomasterfrom
audit

Conversation

@avoidwork
Copy link
Copy Markdown
Owner

@avoidwork avoidwork commented Apr 19, 2026

-- By @avoidwork --
Summary

Refactor filesize() to extract responsibility into dedicated delegate functions, improving adherence to SOLID principles (specifically SRP - Single Responsibility Principle).

Changes

  • Extract 5 new delegate functions in helpers.js: calculateExponent(), applyRounding(), resolveSymbol(), decorateResult(), formatOutput()
  • Reduce filesize() from 285 to 242 lines with clear pipeline of delegate calls
  • Move exponent calculation, rounding, symbol resolution, decoration, and output dispatch out of the main function
  • All 149 tests pass with 100% coverage maintained
  • Build includes generated distributions

Before

filesize() handled: validation, base config, exponent calculation, rounding, auto-increment, precision, symbol lookup, negation, custom symbols, locale/separator/padding formatting, full names, and output dispatch -- ~14 responsibilities.

After

filesize() sequences delegates: validate → getBaseConfig → handleZero → calculateExponent → calculateOptimizedValue → applyRounding → applyPrecision → resolveSymbol → decorateResult → formatOutput.

@augmentcode
Copy link
Copy Markdown

augmentcode bot commented Apr 19, 2026

🤖 Augment PR Summary

Summary: Refactors filesize() into a delegate-driven pipeline to better isolate responsibilities and improve maintainability.

Changes:

  • Extracts exponent calculation, rounding, symbol resolution, result decoration, and output dispatch into new helpers
  • Simplifies src/filesize.js to orchestrate validation → exponent/value calc → rounding/precision → formatting → output
  • Updates TypeScript helper declarations to expose the new delegate APIs
  • Refreshes architecture/docs to describe the new orchestrator + delegates flow
  • Regenerates distribution bundles and updates package metadata description
Technical Notes: The refactor aims to preserve existing output behavior while making each step independently reusable/testable.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/helpers.js Outdated
Comment thread src/helpers.js Outdated
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread types/helpers.d.ts Outdated
Comment thread types/helpers.d.ts Outdated
Comment thread src/helpers.js Outdated
@avoidwork
Copy link
Copy Markdown
Owner Author

augment review

Copy link
Copy Markdown

@augmentcode augmentcode bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestion posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread src/helpers.js Outdated
@avoidwork avoidwork merged commit 1200c28 into master Apr 20, 2026
2 checks passed
@avoidwork avoidwork deleted the audit branch April 20, 2026 01:04
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