Useful methods for file-related functions.
Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
|
- import numeral from 'numeral'
-
- type FormatRawFileSize = (n: number) => string
-
- const formatRawFileSize: FormatRawFileSize = n => {
- if (typeof n as unknown !== 'number') {
- throw TypeError('Argument should be a number.')
- }
-
- if (isNaN(n)) {
- throw RangeError('Cannot format NaN.')
- }
-
- const absValue = Math.abs(n)
- const base = numeral(absValue < 1000 ? absValue : 999).format('0 b')
- const suffix = base.slice(base.indexOf(' ') + ' '.length)
- return `${n < 0 ? '-' : ''}${numeral(absValue).format('0,0')} ${suffix}`
- }
-
- export default formatRawFileSize
|