Skip to content

v8.4.0

Choose a tag to compare

@github-actions github-actions released this 13 Oct 07:39
· 12 commits to master since this release
3a94555

Changes

  • feat(file-size): ✨ Add FileSize, FileSizeUnit and PositiveInteger value objects

Release details

Pull request notes

What

  • PositiveInteger (extends Integer, accepts 0).
  • FileSizeUnit (extends Enum): SI (kB..PB, base 1000) and IEC (KiB..PiB, base 1024) units, with a single typed bytes-per-unit table and FileSizeUnit.SI / FileSizeUnit.IEC sets.
  • FileSize (extends PositiveInteger, stored in bytes): fromBytes, from(value, unit), parse, toBytes, to(unit), toHumanReadable(units), plus inherited arithmetic.

Behaviour worth reviewing

  • toHumanReadable returns { value, unit }: no formatting or rounding in the domain.
  • from and parse round to the nearest byte. multiply/divide do not round and throw InvalidIntegerError on non-integer results. subtract below zero throws InvalidPositiveNumberError.
  • Static factories use the this: new (...) => T pattern from #94, so subclasses get their own type (covered in SubclassFactories.spec.ts).
  • parse units are exact and case-sensitive (KB is invalid).

Docs

Reference pages for the three classes, plus sidebar, reference index, docs home and README entries. The README table was re-aligned by prettier.

Verification

yarn test, yarn build and yarn docs:build pass. Coverage is 100% (statements, branches, functions, lines).