https://github.com/superbytess/superbytes
Convert bytes to a human readable string format
https://github.com/superbytess/superbytes
1024 bytes convert convert-bytes convertion file filesize format human readable si size super
Last synced: 29 days ago
JSON representation
Convert bytes to a human readable string format
- Host: GitHub
- URL: https://github.com/superbytess/superbytes
- Owner: superbytess
- License: mit
- Created: 2018-04-01T15:15:43.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T12:23:28.000Z (over 1 year ago)
- Last Synced: 2024-04-14T05:39:42.568Z (about 1 year ago)
- Topics: 1024, bytes, convert, convert-bytes, convertion, file, filesize, format, human, readable, si, size, super
- Language: TypeScript
- Homepage:
- Size: 356 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Superbytes
Superbytes is a Node.js library for converting bytes to human readable string format
   
## Description
Superbytes will help you convert bytes into other units understandable for humans. The library automatically converts bytes and returns a string with the most optimal unit representation. The library also allows you to set the precision of numbers following the decimal point and choose the output metric in the form of either the IEC standard (1024 bytes = 1 kibibyte) or SI (1000 bytes = 1 kilobyte).By default superbytes converts to IEC units.
The current version supports loading library using both CommonJS and ESModules.
## Installation
Latest version:
```bash
npm i superbytes@latest
```## Usage
### Loading using CommonJS
```javascript
const { superbytes } = require('superbytes');superbytes(423551030);
// returns '403.93 MiB'
superbytes(423551030, 3);
// returns '403.930 MiB'
superbytes(72355103011, { metric: 'si'});
// returns '72.36 GB'
superbytes(3123123, { precision: 5});
// returns '2.97844 MiB'
superbytes(912839123, { metric: 'si', precision: 5});
// returns '912.83912 MB'
```### Loading using ES modules
```javascript
import { superbytes } from 'superbytes';superbytes(423551030);
// returns '403.93 MiB'
superbytes(423551030, 3);
// returns '403.930 MiB'
superbytes(72355103011, { metric: 'si'});
// returns '72.36 GB'
superbytes(3123123, { precision: 5});
// returns '2.97844 MiB'
superbytes(912839123, { metric: 'si', precision: 5});
// returns '912.83912 MB'
```## License
MIT © Damian Polak