All Projects → avoidwork → Filesize.js

avoidwork / Filesize.js

Licence: bsd-3-clause
JavaScript library to generate a human readable String describing the file size

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Filesize.js

files
Useful methods to manage files and directories
Stars: ✭ 27 (-97.29%)
Mutual labels:  filesystem, file
replace-in-files
Replace text in one or more files or globs.
Stars: ✭ 21 (-97.89%)
Mutual labels:  filesystem, file
xbytes
Parse bytes to human readable sizes (4747) → ('4.75 KB') and vice versa.
Stars: ✭ 17 (-98.29%)
Mutual labels:  bytes, size
ansible-role-glusterfs
Ansible Role - GlusterFS
Stars: ✭ 95 (-90.47%)
Mutual labels:  filesystem, file
Compressed Size Action
GitHub Action that adds compressed size changes to your PRs.
Stars: ✭ 300 (-69.91%)
Mutual labels:  size, bytes
flysystem-sync
Filesystem sync using Flysystem project.
Stars: ✭ 26 (-97.39%)
Mutual labels:  filesystem, file
FireFiles
Powerful Android File Manager for everything that runs on Android OS (Android TV, Android Watch, Mobile, etc)
Stars: ✭ 37 (-96.29%)
Mutual labels:  filesystem, file
gtree
Output tree🌳 or Make directories📁 from #Markdown or Programmatically. Provide CLI, Golang library and Web (using #Wasm ).
Stars: ✭ 88 (-91.17%)
Mutual labels:  filesystem, file
magic-bytes
A library for detecting file types.
Stars: ✭ 20 (-97.99%)
Mutual labels:  file, bytes
parallel-disk-usage
Highly parallelized, blazing fast directory tree analyzer
Stars: ✭ 145 (-85.46%)
Mutual labels:  filesystem, size
cache
🥌 Deno cache library
Stars: ✭ 38 (-96.19%)
Mutual labels:  filesystem, file
Filer
Node-like file system for browsers
Stars: ✭ 389 (-60.98%)
Mutual labels:  filesystem, file
fsify
Convert an array of objects into a persistent or temporary directory structure.
Stars: ✭ 24 (-97.59%)
Mutual labels:  filesystem, file
watcher
The file system watcher that strives for perfection, with no native dependencies and optional rename detection support.
Stars: ✭ 37 (-96.29%)
Mutual labels:  filesystem, file
PHP-FileUpload
Simple and convenient file uploads — secure by default
Stars: ✭ 53 (-94.68%)
Mutual labels:  filesystem, file
TLightFileStream
Implements a lightweight, high-performance, non-allocating advanced-record-based wrapper around the SysUtils file handling routines as an alternative to Classes.TFileStream.
Stars: ✭ 21 (-97.89%)
Mutual labels:  filesystem, file
FileRenamerDiff
A File Renamer App featuring a difference display before and after the change.
Stars: ✭ 32 (-96.79%)
Mutual labels:  filesystem, file
flutter file utils
Flutter package for managing files on Android
Stars: ✭ 35 (-96.49%)
Mutual labels:  filesystem, file
HumanBytes
A library to convert byte sizes to a human readable form
Stars: ✭ 28 (-97.19%)
Mutual labels:  bytes, size
Chonky
😸 A File Browser component for React.
Stars: ✭ 313 (-68.61%)
Mutual labels:  filesystem, file

filesize.js

build status downloads CDNJS version

filesize.js provides a simple way to get a human readable file size string from a number (float or integer) or string.

Optional settings

filesize() accepts an optional descriptor Object as a second argument, so you can customize the output.

base

(number) Number base, default is 2

bits

(boolean) Enables bit sizes, default is false

exponent

(number) Specifies the symbol via exponent, e.g. 2 is MB for base 2, default is -1

fullform

(boolean) Enables full form of unit of measure, default is false

fullforms

(array) Array of full form overrides, default is []

locale (overrides 'separator')

(string || boolean) BCP 47 language tag to specify a locale, or true to use default locale, default is ""

localeOptions (overrides 'separator', requires string for 'locale' option)

(object) Dictionary of options defined by ECMA-402 (Number.prototype.toLocaleString). Requires locale option to be explicitly passed as a string, otherwise is ignored.

output

(string) Output of function (array, exponent, object, or string), default is string

round

(number) Decimal place, default is 2

separator

(string) Decimal separator character, default is .

spacer

(string) Character between the result and symbol, default is " "

standard

(string) Standard unit of measure, can be iec or jedec, default is jedec; can be overruled by base

symbols

(object) Dictionary of SI/JEDEC/IEC symbols to replace for localization, defaults to english if no match is found

unix

(boolean) Enables unix style human readable output, e.g ls -lh, default is false

Examples

filesize(500);                        // "500 B"
filesize(500, {bits: true});          // "4 Kb"
filesize(265318, {base: 10});         // "265.32 kB"
filesize(265318);                     // "259.1 KB"
filesize(265318, {round: 0});         // "259 KB"
filesize(265318, {output: "array"});  // [259.1, "KB"]
filesize(265318, {output: "object"}); // {value: 259.1, symbol: "KB", exponent: 1}
filesize(1, {symbols: {B: "Б"}});     // "1 Б"
filesize(1024);                       // "1 KB"
filesize(1024, {exponent: 0});        // "1024 B"
filesize(1024, {output: "exponent"}); // 1
filesize(265318, {standard: "iec"});  // "259.1 KiB"
filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes"
filesize(12, {fullform: true, fullforms: ["байтов"]});  // "12 байтов"
filesize(265318, {separator: ","});   // "259,1 KB"
filesize(265318, {locale: "de"});   // "259,1 KB"

Partial Application

filesize.partial() takes the second parameter of filesize() and returns a new function with the configuration applied upon execution. This can be used to reduce Object creation if you call filesize() without caching the descriptor in lexical scope.

const size = filesize.partial({standard: "iec"});

size(265318); // "259.1 KiB"

How can I load filesize.js?

filesize.js supports AMD loaders (require.js, curl.js, etc.), node.js & npm (npm install filesize), or using a script tag.

An ES6 version is bundled with an npm install, but requires you load it with the full path, e.g. require(path.join(__dirname, 'node_modules', 'filesize', 'lib', 'filesize.es6.js')).

License

Copyright (c) 2019 Jason Mulligan Licensed under the BSD-3 license.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].