将字节转换为人类可读的字符串: 1337 → 1.34 kB
将字节转换为人类可读的字符串:
1337→1.34 kB对于人类来说,显示文件大小很有用。 请注意,它使用基数 10 (例如,千字节)。 了解 kilobyte 和 kibibyte 之间的区别。
npm install pretty-bytesimport prettyBytes from 'pretty-bytes';
prettyBytes(1337);
//=> '1.34 kB'
prettyBytes(100);
//=> '100 B'
// Display with units of bits
prettyBytes(1337, {bits: true});
//=> '1.34 kbit'
// Display file size differences
prettyBytes(42, {signed: true});
//=> '+42 B'
// Localized output using German locale
prettyBytes(1337, {locale: 'de'});
//=> '1,34 kB'
// Fixed width for alignment (useful for progress bars and tables)
prettyBytes(1337, {fixedWidth: 8});
//=> ' 1.34 kB'类型: number | bigint
要格式化的数字。
类型: object
类型: boolean
默认值: false
对于正数,包含加号。如果差值为零,则会预先添加空格字符,以便更好地对齐。
类型: boolean
默认值: false
暂无开放 Issues,或尚未同步最近议题。