Skip to content

引入

ts
import { IFormatBiteOptions, formatBite } from 't-comm';

// 不支持 tree-shaking 的项目
import { IFormatBiteOptions, formatBite} from 't-comm/lib/bite/index';

// 只支持 ESM 的项目
import { IFormatBiteOptions, formatBite} from 't-comm/es/bite/index';

IFormatBiteOptions

描述formatBite 入参(可选)

参数

iFormatBiteOptions.space : boolean

数值与单位之间是否加空格,默认 false(原行为)

Kind: instance property of IFormatBiteOptions
Optional:

iFormatBiteOptions.fixed : number

保留小数位数,默认 2

Kind: instance property of IFormatBiteOptions
Optional:

formatBite(size, options)

描述:格式化 bite 单位,最多保留2位小数,最大单位为BB

参数

参数名描述
sizebite 单位
options配置项(可选)

返回: 格式化的字符

示例

typescript
formatBite(1)
// 1B

formatBite(100)
// 100B

formatBite(1000)
// 1000B

formatBite(10000)
// 9.77KB

formatBite(10000, { space: true })
// '9.77 KB'

formatBite(10000, { fixed: 1 })
// '9.8KB'

formatBite(10000, { space: true, fixed: 1 })
// '9.8 KB'