Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hustcc/filesize.js
:fire: filesize.js is a simple(~360 b) module to make file size human-readable.
https://github.com/hustcc/filesize.js
bytes filesize jedec
Last synced: 3 months ago
JSON representation
:fire: filesize.js is a simple(~360 b) module to make file size human-readable.
- Host: GitHub
- URL: https://github.com/hustcc/filesize.js
- Owner: hustcc
- License: mit
- Created: 2016-09-22T12:13:41.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-10-20T10:35:35.000Z (about 5 years ago)
- Last Synced: 2024-10-17T16:04:16.495Z (3 months ago)
- Topics: bytes, filesize, jedec
- Language: TypeScript
- Homepage: https://github.com/hustcc/filesize.js
- Size: 11.7 KB
- Stars: 27
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# filesize.js
> **filesize.js** is a nano(350 b) library to make file size bytes **human-readable**. e.g. 20.4 Kb.
[![Build Status](https://travis-ci.org/hustcc/filesize.js.svg?branch=master)](https://travis-ci.org/hustcc/filesize.js)
[![npm](https://img.shields.io/npm/v/filesize.js.svg)](https://www.npmjs.com/package/filesize.js)
[![npm](https://img.shields.io/npm/dm/filesize.js.svg)](https://www.npmjs.com/package/filesize.js)
[![npm](https://img.shields.io/npm/l/filesize.js.svg)](https://www.npmjs.com/package/filesize.js)## Install
> npm install filesize.js
## Usage
The unique API is: **fileSize(bytes[, fixed=1, spec='jedec']);**.
- `bytes`: Number of file size bytes.
- `fixed`: Number of decimal, default is `1`.
- `spec`: String of file size spec, default is `jedec`.```js
// bytes.
filesize(123456); // '120.6 Kb'// fixed, `1` is default.
filesize(123456, 0); // '121 Kb'
filesize(123456, 4); // '1120.5625 Kb'// specs, `jedec` / `iec / si`.
// `jedec` is default.
filesize(123456, 2, 'iec'); // '120.56 Kib'
filesize(123456, 0, 'si'); // '123 kb'
```## Test
> npm install
> npm test
## Spec
- [jedec](http://www.jedec.org/): Unit is `['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb']`, and the power is **1024**.
- [iec](http://www.electropedia.org/iev/iev.nsf/index?openform&part=112): Unit is `['b', 'Kib', 'Mib', 'Gib', 'Tib', 'Pib', 'Eib', 'Zib', 'Yib']`, and the power is **1024**.
- [si](https://zh.wikipedia.org/wiki/%E5%9B%BD%E9%99%85%E5%8D%95%E4%BD%8D%E5%88%B6): Unit is `['b', 'kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb']`, and the power is **1000**.More specs **waiting for your issues / pull requests**.
## LICENSE
MIT@[hustcc](https://github.com/hustcc).