Repository navigation
feat(file-size): ✨ Add FileSize, FileSizeUnit and PositiveInteger value objects - #98
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.this: new (...) => Tpattern from Static factory methods return the base class instead of the subclass (UUID.generate, ShortId.generate, Timestamp.now, Duration.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 buildandyarn docs:buildpass. Coverage is 100% (statements, branches, functions, lines).