human-format

Converts a number to/from a human readable string: 1337
↔ 1.34kB
Installation
Installation of the npm package:
> npm install --save human-format
Then require the package:
var humanFormat = require("human-format");
Browser
You can directly use the build provided at unpkg.com:
<script src="https://unpkg.com/human-format@1/index.js"></script>
Usage
Formatting
humanFormat(1337);
humanFormat(1337, {
maxDecimals: 1,
});
humanFormat(1337, {
maxDecimals: "auto",
});
humanFormat(13337, {
maxDecimals: "auto",
});
humanFormat(1337, {
decimals: 4,
});
humanFormat(65536, {
scale: "binary",
unit: "B",
});
humanFormat.bytes(65536);
humanFormat(1337, {
separator: " - ",
});
var timeScale = new humanFormat.Scale({
seconds: 1,
minutes: 60,
hours: 3600,
days: 86400,
months: 2592000,
});
humanFormat(26729235, { scale: timeScale });
var binaryScale = humanFormat.Scale.create(["", "Ki", "Mi", "Gi", "Ti"], 1024);
humanFormat(173559053, { scale: binaryScale });
humanFormat(100, { unit: "m", prefix: "k" });
humanFormat.raw(100, { prefix: "k" });
Parsing
humanFormat.parse("1.34 kiB", { scale: "binary" });
humanFormat.parse("1 g");
humanFormat.parse.raw("1.34 kB");
Contributions
Contributions are very welcomed, either on the documentation or on
the code.
You may:
- report any issue
you've encountered;
- fork and create a pull request.
Contributors:
- @djulien
- @qrohlf
- @Itay289
- @sweetpi
License
ISC © Julien Fontanet