@usesummit/utils
v0.5.1
Published
Useful methods for handling numbers, mostly.
Downloads
53
Readme
Summit JS Utils
Useful methods for handling numbers, mostly.
Came out of the need for re-using some helper methods across multiple codebases at Summit.
Contents
calculateHumanReadableNumber
turns a number into a[number, abbreviation]
tuple, so that you can pass thenumber
to any number formatter and then add theabbreviation
as a suffix. You can use this to pretty-print47965012.48
to47.96MM
. This doesn't handle rounding or fraction digits, use your regular number formatter for that (i.e.Intl.NumberFormat
)parseHumanReadableNumber
can parse numbers like1.52MM
and1,234,456.78
to floatsgetIdentifier
generates and stores a unique identifier so you can anonymously identify users or sessions