diff options
| author | Rinpatch <rinpatch@sdf.org> | 2018-12-10 09:50:04 +0300 |
|---|---|---|
| committer | Rinpatch <rinpatch@sdf.org> | 2018-12-10 09:50:04 +0300 |
| commit | c69a8dc197c87eb69272c28c1c1501e3c6d6d9aa (patch) | |
| tree | f8d466d8082c3021bd35da4b3230510233d9462f /src/services/file_size_format | |
| parent | 4fde987e34c6b76c67d73ff1d163e8a5fed53069 (diff) | |
Add file size formating
Diffstat (limited to 'src/services/file_size_format')
| -rw-r--r-- | src/services/file_size_format/.file_size_format.js.swp | bin | 0 -> 12288 bytes | |||
| -rw-r--r-- | src/services/file_size_format/file_size_format.js | 17 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/services/file_size_format/.file_size_format.js.swp b/src/services/file_size_format/.file_size_format.js.swp Binary files differnew file mode 100644 index 00000000..ec2e601a --- /dev/null +++ b/src/services/file_size_format/.file_size_format.js.swp diff --git a/src/services/file_size_format/file_size_format.js b/src/services/file_size_format/file_size_format.js new file mode 100644 index 00000000..5d22b473 --- /dev/null +++ b/src/services/file_size_format/file_size_format.js @@ -0,0 +1,17 @@ +const fileSizeFormat = (num, t) => { + var exponent + var unit + var units = [t('file_size_units.B'), t('file_size_units.KB'), t('file_size_units.MB'), t('file_size_units.GB'), t('file_size_units.TB')] + if (num < 1) { + return num + ' ' + units[0] + } + + exponent = Math.min(Math.floor(Math.log(num) / Math.log(1000)), units.length - 1) + num = (num / Math.pow(1000, exponent)).toFixed(2) * 1 + unit = units[exponent] + return num + ' ' + unit +} +const fileSizeFormatService = { + fileSizeFormat +} +export default fileSizeFormatService |
