Skip to content

Audit: src #296

Description

@avoidwork

Audit: src

Scope: Root-level files only (3 files audited)
Date: 2026-06-26

Findings

# File Type Severity Summary
1 helpers.js bug medium applyNumberFormatting padding logic does not truncate when separator is used with pad — excess decimal places are preserved instead of being trimmed to round
2 filesize.js code-smell low isNaN(arg) should be isNaN(num) for clarity — functionally equivalent here but misleading
3 filesize.js fragility low partial uses JSON.parse(JSON.stringify()) for deep cloning — loses functions, undefined, Dates, RegExps

Details

1. Padding with separator (medium)

File: helpers.jsapplyNumberFormatting

When both separator and pad options are set, the padding logic runs after the separator replacement. The padEnd call only adds trailing zeros — it does not truncate excess decimal places. If the value has more decimal digits than round, the output will exceed the requested precision.

Example: filesize(1234.567, {separator: ",", pad: true, round: 2})"1,234.567" (expected "1,234.57" or similar)

2. isNaN clarity (low)

File: filesize.jsfilesize function

isNaN(arg) is used after num = Number(arg). While functionally equivalent in this context (both coerce to number), isNaN(num) would be clearer and more intentional.

3. JSON deep clone fragility (low)

File: filesize.jspartial function

JSON.parse(JSON.stringify(localeOptions)) etc. is used for deep cloning. This works for plain objects/arrays but silently drops functions, undefined, Dates, RegExps, and circular references. Fine for current use case but fragile if options evolve.

Files Audited

  • constants.js — Pure data exports, no issues found
  • filesize.js — Main entry point, 2 low-severity findings
  • helpers.js — Helper functions, 1 medium-severity finding

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions