Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
better-bytes
Advanced tools
Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3). 更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算
Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3).
Reference link: https://physics.nist.gov/cuu/Units/binary.html
更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算
https://github.com/CaoMeiYouRen/better-bytes#readme
npm install better-bytes
import { format, parse } from 'better-bytes'
format(1024) // '1.00 KiB'
format(1073741824) // '1.00 GiB'
format(1125899906842624n) // '1.00 PiB'
format(1572864, { standard: 'kilobinary' }) // '1.50 MiB'
format(1500000, { standard: 'kilo' }) // '1.50 MB'
format(1234, { decimal: 3, standard: 'kilobinary' }) // '1.205 KiB'
format(1234, { decimal: 3, standard: 'kilo' }) // '1.234 KB
format(1.1) // Error: 'Data must be integer'
format(-1) // Error: 'Data must be greater than or equal to 0'
format('invalid') // Error: 'Data must be a number or bigint'
format(NaN) // Error: 'Data must be finite'
parse('1KiB') // 1024
parse('1GiB') // 1073741824
parse('1KB') // 1000
parse('1GB') // 1000000000
parse('1KB', { forceKilobinary: true }) // 1024
parse('1GB', { forceKilobinary: true }) // 1073741824
parse('1.5KiB') // 1536
parse('1.5KB') // 1500
parse('1024') // 1024
parse('1000.5') // 1000
parse('1.123456789012345GiB') // 1206302541
parse('1.123456789012345GB') // 1123456789
parse('9007199254740991YiB') // 10633823966279325802638835764831453184n
parse('9007199254740991YB') // 9007199254740991000000000000000000000n
parse('+1KiB') // 1024
parse('-1KiB') // null
parse('1XB') // null
parse('invalid') // null
parse('Infinity') // null
parse(123) // Error: Data must be a string
Format the given value in bytes into a string.
将给定的字节值格式化为字符串。
Arguments
Name | Type | Description |
---|---|---|
data | number |bigint | Number value to format. 要格式化的数值 |
options | object | Conversion options for format . 格式化的选项。 |
Options
Property | Type | Description |
---|---|---|
decimal | number |undefined | Maximum number of decimal places to include in output. Default: 2 . 输出中包含的最大小数位数。默认值:2 。 |
standard | kilobinary |kilo | base. kilobinary = 2^10 ; kilo = 10^3. Default: kilobinary . 进制规范。千位二进制=2^10;千位=10^3。默认值:kilobinary |
unitSeparator | string |undefined | Separator to use between number and unit. Default: ' ' . 用于数字和单位之间的分隔符。默认值:' ' |
Returns
Name | Type | Description |
---|---|---|
results | string | Return string. For non number or bigint, as well as cases less than 0, exceptions are thrown. 返回 string。对于非 number 或 bigint,以及小于 0 的情况,均抛出异常。 |
Parse the string value into an integer in bytes. If no unit is given, it is assumed the value is in bytes.
将字符串值解析为以字节为单位的整数。如果没有给出单位,则假定该值以字节为单位。
Arguments
Name | Type | Description |
---|---|---|
data | string | String value to parse. 要解析的字符串。 |
options | object | Parsed options. 解析的选项。 |
Options
Property | Type | Description |
---|---|---|
forceKilobinary | boolean |undefined | If true, consider kilo as kilobinary, i.e. using 2 ^ 10 base. 如果为真,则将千位进制视为千位二进制,即使用 2^10 进制换算。 |
Returns
Name | Type | Description |
---|---|---|
results | number |bigint |null | Returns null on error. Otherwise, return the value of number or bigint in bytes. 出错时返回 null。否则以字节为单位返回 number 或 bigint 的数值。 |
npm run dev
npm run build
npm run test
npm run lint
npm run commit
CaoMeiYouRen
Website: https://blog.cmyr.ltd/
GitHub: @CaoMeiYouRen
Welcome to contribute, ask questions or propose new features!
If you have any questions, please check the issues page.
For contributions or new feature proposals, please refer to the contributing guide.
欢迎 贡献、提问或提出新功能!
如有问题请查看 issues page.
贡献或提出新功能可以查看contributing guide.
If you find this project useful, please give it a ⭐️. Thank you very much.
如果觉得这个项目有用的话请给一颗⭐️,非常感谢
Copyright © 2024 CaoMeiYouRen.
This project is MIT licensed.
This README was generated with ❤️ by cmyr-template-cli
FAQs
Better byte base conversion. Supports two base conversions: kilo binary byte (2^10) and kilobyte (10^3). 更好的字节进制换算。支持 千位二进制字节(2^10) 和 千字节(10^3) 两种进制换算
We found that better-bytes demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.