您当前的位置: 首页 > 

彭世瑜

暂无认证

  • 3浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

js:filesize.js将文件大小转换为人类可读的格式

彭世瑜 发布时间:2022-05-15 15:30:50 ,浏览量:3

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

文档:

  • https://filesizejs.com/

  • https://www.npmjs.com/package/filesize

  • https://github.com/avoidwork/filesize.js

NPM

安装

npm i -S filesize

使用示例

const filesize = require('filesize');

console.log(filesize(1024)); // 1.02 kB

console.log(filesize(1024 * 1024)); // 1.05 MB

console.log(filesize(1024 * 1024 * 1024)); // 1.07 GB

console.log(filesize(1024 * 1024 * 1024 * 1024)); // 1.1 TB

CDN
# 生产环境
https://cdnjs.cloudflare.com/ajax/libs/filesize/8.0.7/filesize.min.js

# 开发环境
https://cdnjs.cloudflare.com/ajax/libs/filesize/8.0.7/filesize.js

使用示例




    console.log(filesize(1024)); // 1.02 kB

    console.log(filesize(1024 * 1024)); // 1.05 MB

    console.log(filesize(1024 * 1024 * 1024)); // 1.07 GB

    console.log(filesize(1024 * 1024 * 1024 * 1024)); // 1.1 TB

关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0732s