byte-size

Isomorphic function to convert a bytes value (e.g. 3456) to a human-readable string ('3.5 kB')

MIT License

Downloads
7.3M
Stars
70
Committers
5
byte-size - v9.0.0 Latest Release

Published by 75lb 3 months ago

Whether this is a breaking change or not is debatable so it has been released as a major version just in case.

Non-breaking change since v8.2.1

These changes affect the output only, there are no changes to the API or minimum supported Node version (still v12.17).

  • Fixed an issue where precision and Intl formatting was not applied to small numbers. #15
  • Removed minimumFractionDigits from unit number formatting. This removes superfluous precision, some examples:
    • byteSize(1000).toString() now returns 1 kB instead of 1.0 kB, removing the superfluous one decimal place of precision.
    • byteSize(1500000, { precision: 5 }).toString() now returns 1.5 MB instead of 1.50000 MB, again removing superfluous precision.
    • However, byteSize(1500010, { precision: 5 }).toString() will return 1.50001 MB as there is meaningful, non-zero precision to display.
byte-size - v8.1.0

Published by 75lb about 3 years ago

New features since v8.0.0

  • Support extended back to Node.js v12.17
    • This is because support for exports, conditional exports and exports patterns have been retro-fitted into v12 (see the Package module history)

Upgrade notes

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 - v8.0.0

Published by 75lb over 3 years ago

Breaking changes since v7.0.1

  • Dropped support for Node.js versions < v14

New feature: localisation

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' }
byte-size - v7.0.0

Published by 75lb over 4 years ago

Breaking changes since v6.2.0

  • Dropped support for Node.js versions < v10

Other improvements

  • The test suite is now isomorphic, run in both Node.js and the browser.
byte-size - v6.2.0

Published by 75lb almost 5 years ago

Features added since v6.1.0

  • Added the byteSize.defaultOptions() method - see the synopsis for an explaination.
  • Added options.toStringFn to enable overriding the default toString output - also see the synopsis.
byte-size - v6.1.0

Published by 75lb about 5 years ago

Features added since v6.0.0

  • Added support for custom units. See the synopsis for an example.
  • Added validation: byteSize will now throw if you specify an invalid options.units value.
  • Added long unit names (e.g. kilobytes) to the output.

Other improvements

  • Improved the readme and documentation
  • More tests added
  • Refactored the code.
byte-size - v6.0.0

Published by 75lb about 5 years ago

Breaking changes since v5.0.1

  • Support for Node versions less than v8 has been dropped.

Upgrade advice

Users of node v8 and above can safely upgrade to byte-size v6.0.0. There have been no changes to the byte-size source code or API, only to the dev dependencies and test suite.

byte-size - v5.0.0

Published by 75lb almost 6 years ago

Breaking changes since v4.0.4

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.

New features

This library is now compatible with Node.js, the Web and any style of module loader. See the readme for examples.

Upgrade notes

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.

byte-size - v4.0.0

Published by 75lb about 6 years ago

Breaking since v3.0.0

Support was removed for versions of Node.js older than v4.0.0.

byte-size - v3.0.0

Published by 75lb about 8 years ago

Breaking since v2

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.

New feature

@adrai added support for the octet unit.

Package Rankings
Top 2.35% on Npmjs.org
Top 28.04% on Repo1.maven.org
Badges
Extracted from project README
view on npm npm module downloads Gihub repo dependents Gihub package dependents Node.js CI js-standard-style
Related Projects