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.
@tsmx/human-readable
Advanced tools
Easily create human-readable strings from byte sizes, e.g. 17238 --> 17.24 kB. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.
Easily create human-readable strings from byte sizes, e.g.
17238
→17.24 kB
. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.
For details about the differences of decimal (SI) and binary (IEC) units please refer to Wikipedia.
Also check out the full documentation. Type declarations for seamless usage in TypeScript projects are included. If you need to use this package on the client-side in the browser using plain JavaScript, refer to this article.
const hr = require('@tsmx/human-readable');
hr.fromBytes(17238);
// '17.24 kB'
hr.fromBytes(17238, { mode: 'IEC' });
// '16.83 KiB'
hr.fromBytes(17238, { numberOnly: true });
// '17.24'
hr.fromBytes(17238, { fixedPrecision: 1 });
// '17.2 kB'
hr.fromBytes(17238, { fullPrecision: true });
// '17.238 kB'
hr.fromTo(17, 'GBYTE', 'KBYTE');
// '17000000 kB'
hr.fromTo(17, 'GBYTE', 'KBYTE', { mode: 'IEC' });
// '17825792 KiB'
hr.availableSizes();
// [ 'BYTE', 'KBYTE', 'MBYTE', 'GBYTE', 'TBYTE', 'PBYTE' ]
Automatically creates a human-readable string out of a given number of bytes. E.g. 71255
→ 71.26 kB
Type: Number
Amount of bytes.
Type: Object
Optional.
Type: String
Default: none (use decimal mode)
Can be set to IEC
to use binary conversion (factor 1.024) and units (KiB,MiB,...). If not set or to any other value, decimal conversion (factor 1.000) and units (kB, MB,...) are used.
Type: Boolean
Default: false
If set to true, conversion only returns the number and omits the unit. Overrides noWhitespace
.
Type: Number
If set the returned number string is formatted to the given fixed decimal places. If not set, the default behaviour of the conversion is to use a dynamic number of decimal places from zero up to two.
Type: Boolean
Default: false
If set to true, the returned number value will be presented with full available decimal places. Overrides fixedPrecision
.
Type: Boolean
Default: false
If set to true, the whitespace between the number and unit string is omitted. E.g. 10MB
instead of 10 MB
.
Converts a value from a given size unit to a human-readable string of the target size. E.g. converting Gigabytes to Megabytes.
Type: Number
The value to be converted.
Type: String
The size value
has. Must be one out of availableSizes
.
Type: String
The size value
should be converted to. Must be one out of availableSizes
.
Type: Object
See options description under fromBytes
.
Returns an array of strings of all available sizes.
FAQs
Easily create human-readable strings from byte sizes, e.g. 17238 --> 17.24 kB. Supports decimal (MB,GB,..) and binary (MiB, GiB,..) units as well as user-defined conversion from/to other sizes.
We found that @tsmx/human-readable 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.