@visulima/humanizer
Version:
Humanizer is a library for humanizing data in a human-readable form.
132 lines (131 loc) • 3.85 kB
TypeScript
import type { FormateByteOptions, ParseByteOptions } from "./types.d.ts";
declare const BYTE_SIZES: {
readonly iec: readonly [{
readonly long: "Bytes";
readonly short: "B";
}, {
readonly long: "Kibibytes";
readonly short: "KiB";
}, {
readonly long: "Mebibytes";
readonly short: "MiB";
}, {
readonly long: "Gibibytes";
readonly short: "GiB";
}, {
readonly long: "Tebibytes";
readonly short: "TiB";
}, {
readonly long: "Pebibytes";
readonly short: "PiB";
}, {
readonly long: "Exbibytes";
readonly short: "EiB";
}, {
readonly long: "Zebibytes";
readonly short: "ZiB";
}, {
readonly long: "Yobibytes";
readonly short: "YiB";
}];
readonly iec_octet: readonly [{
readonly long: "Octets";
readonly short: "o";
}, {
readonly long: "Kibioctets";
readonly short: "Kio";
}, {
readonly long: "Mebioctets";
readonly short: "Mio";
}, {
readonly long: "Gibioctets";
readonly short: "Gio";
}, {
readonly long: "Tebioctets";
readonly short: "Tio";
}, {
readonly long: "Pebioctets";
readonly short: "Pio";
}, {
readonly long: "Exbioctets";
readonly short: "Eio";
}, {
readonly long: "Zebioctets";
readonly short: "Zio";
}, {
readonly long: "Yobioctets";
readonly short: "Yio";
}];
readonly metric: readonly [{
readonly long: "Bytes";
readonly short: "Bytes";
}, {
readonly long: "Kilobytes";
readonly short: "KB";
}, {
readonly long: "Megabytes";
readonly short: "MB";
}, {
readonly long: "Gigabytes";
readonly short: "GB";
}, {
readonly long: "Terabytes";
readonly short: "TB";
}, {
readonly long: "Petabytes";
readonly short: "PB";
}, {
readonly long: "Exabytes";
readonly short: "EB";
}, {
readonly long: "Zettabytes";
readonly short: "ZB";
}, {
readonly long: "Yottabytes";
readonly short: "YB";
}];
readonly metric_octet: readonly [{
readonly long: "Octets";
readonly short: "o";
}, {
readonly long: "Kilo-octets";
readonly short: "ko";
}, {
readonly long: "Mega-octets";
readonly short: "Mo";
}, {
readonly long: "Giga-octets";
readonly short: "Go";
}, {
readonly long: "Tera-octets";
readonly short: "To";
}, {
readonly long: "Peta-octets";
readonly short: "Po";
}, {
readonly long: "Exa-octets";
readonly short: "Eo";
}, {
readonly long: "Zetta-octets";
readonly short: "Zo";
}, {
readonly long: "Yotta-octets";
readonly short: "Yo";
}];
};
type ByteSize = (typeof BYTE_SIZES)["iec_octet"][number]["short"] | (typeof BYTE_SIZES)["iec"][number]["short"] | (typeof BYTE_SIZES)["metric_octet"][number]["short"] | (typeof BYTE_SIZES)["metric"][number]["short"];
/**
* Parse the given bytesize string and return bytes.
* @param value The string to parse
* @param options Options for the conversion from string to bytes
* @throws Error if `value` is not a non-empty string or a number
*/
export declare const parseBytes: (value: string, options?: ParseByteOptions) => number;
/**
* Formats the given bytes into a human-readable string.
* Per default, it will use the closest unit to the given value.
* @param bytes The bytes to format
* @param options Options for the conversion from bytes to string
*/
export declare const formatBytes: (bytes: number, options?: FormateByteOptions<ByteSize>) => string;
export {};