Repository navigation
v8.4.0
Changes
- feat(file-size): ✨ Add FileSize, FileSizeUnit and PositiveInteger value objects
Release details
- npm: https://www.npmjs.com/package/@haskou/value-objects/v/8.4.0
- Pull request: #98
- Source branch:
feat/file-size - Version bump:
minor
Pull request notes
What
PositiveInteger(extendsInteger, accepts0).FileSizeUnit(extendsEnum): SI (kB..PB, base 1000) and IEC (KiB..PiB, base 1024) units, with a single typed bytes-per-unit table andFileSizeUnit.SI/FileSizeUnit.IECsets.FileSize(extendsPositiveInteger, stored in bytes):fromBytes,from(value, unit),parse,toBytes,to(unit),toHumanReadable(units), plus inherited arithmetic.
Behaviour worth reviewing
toHumanReadablereturns{ value, unit }: no formatting or rounding in the domain.fromandparseround to the nearest byte.multiply/dividedo not round and throwInvalidIntegerErroron non-integer results.subtractbelow zero throwsInvalidPositiveNumberError.- Static factories use the
this: new (...) => Tpattern from #94, so subclasses get their own type (covered inSubclassFactories.spec.ts). parseunits are exact and case-sensitive (KBis 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).