Isomorphic function to convert a bytes value (e.g. 3456) to a human-readable string ('3.5 kB')
exports
, conditional exports and exports patterns have been retro-fitted into v12 (see the Package module history)Users of Node.js v12.17 and above may now use the latest version (previously, you needed a minimum of node v14). There are no further changes.
Byte-size now supports localised number formatting using your system locale by default (#9). For example, if you're in Deutschland you'll now see your native numeric formatting:
> byteSize(1000)
ByteSize { value: '1,0', unit: 'kB', long: 'kilobytes' }
Or you can set the locale manually:
> byteSize(1000, { locale: 'en-GB' })
ByteSize { value: '1.0', unit: 'kB', long: 'kilobytes' }
byteSize.defaultOptions()
method - see the synopsis for an explaination.options.toStringFn
to enable overriding the default toString
output - also see the synopsis.byteSize
will now throw if you specify an invalid options.units
value.long
unit names (e.g. kilobytes
) to the output.Support for Node.js versions less than v6 has been dropped. Technically, this is not a breaking change since byte-size v5.0.0 still works with node v4 (the byte-size API and code has not changed) but future releases will be tested in node v6 and above only.
This library is now compatible with Node.js, the Web and any style of module loader. See the readme for examples.
If you're using Node.js v6 or above, since there have been no API changes to byte-size you can safely upgrade to v5.0.0.
The library no longer assumes you require a formatted string (e.g. '2.4 Kib'
) . It returns an object containing the raw values (e.g. { value: '1.6', unit: 'ko' }
and you can format them however you please.
@adrai added support for the octet unit.