-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
93 lines (76 loc) · 1.8 KB
/
index.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
type BinaryPrefix = "" | "Ki" | "Mi" | "Gi" | "Ti" | "Pi" | "Ei" | "Zi" | "Yi";
type SIPrefix =
| "y"
| "z"
| "a"
| "f"
| "p"
| "n"
| "µ"
| "m"
| ""
| "k"
| "M"
| "G"
| "T"
| "P"
| "E"
| "Z"
| "Y";
export type ScaleName = "binary" | "SI";
export type Scale<T extends string> = humanFormat.Scale<T>;
export type ScaleLike = Scale<string> | ScaleName;
export type Prefix<S extends ScaleLike> = S extends Scale<infer U>
? U
: S extends "binary"
? BinaryPrefix
: S extends "SI"
? SIPrefix
: never;
export declare interface Options<S extends ScaleLike> {
maxDecimals?: number | "auto";
separator?: string;
unit?: string;
scale?: S;
strict?: boolean;
prefix?: Prefix<S>;
decimals?: number;
}
export declare interface Info<S extends ScaleLike> {
value: number;
prefix: Prefix<S>;
unit?: string;
}
export declare interface ParsedInfo<S extends ScaleLike> {
value: number;
factor: number;
prefix: Prefix<S>;
unit?: string;
}
export declare function humanFormat<S extends ScaleLike>(
value: number,
opts?: Options<S>
): string;
export declare namespace humanFormat {
function bytes<S extends ScaleLike>(value: number, opts?: Options<S>): string;
function parse<S extends ScaleLike>(str: string, opts?: Options<S>): number;
namespace parse {
function raw<S extends ScaleLike>(
str: string,
opts?: Options<S>
): ParsedInfo<S>;
}
function raw<S extends ScaleLike>(value: number, opts?: Options<S>): Info<S>;
class Scale<P extends string> {
constructor(prefixes: Record<P, number>);
}
namespace Scale {
function create<P extends string>(
prefixes: P[],
base: number,
initExp?: number
): Scale<P>;
}
export { bytes, parse, raw, Prefix, BinaryPrefix, Scale };
}
export default humanFormat;