| [9af201e] | 1 | // Type definitions for filesize 8.0.3
|
|---|
| 2 | // Project: https://github.com/avoidwork/filesize.js, https://filesizejs.com
|
|---|
| 3 | // Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
|
|---|
| 4 | // Renaud Chaput <https://github.com/renchap>
|
|---|
| 5 | // Roman Nuritdinov <https://github.com/Ky6uk>
|
|---|
| 6 | // Sam Hulick <https://github.com/ffxsam>
|
|---|
| 7 | // Tomoto S. Washio <https://github.com/tomoto>
|
|---|
| 8 |
|
|---|
| 9 | declare var fileSize: Filesize.Filesize;
|
|---|
| 10 | export = fileSize;
|
|---|
| 11 | export as namespace filesize;
|
|---|
| 12 |
|
|---|
| 13 | declare namespace Filesize {
|
|---|
| 14 | interface SiJedecBits {
|
|---|
| 15 | b?: string;
|
|---|
| 16 | Kb?: string;
|
|---|
| 17 | Mb?: string;
|
|---|
| 18 | Gb?: string;
|
|---|
| 19 | Tb?: string;
|
|---|
| 20 | Pb?: string;
|
|---|
| 21 | Eb?: string;
|
|---|
| 22 | Zb?: string;
|
|---|
| 23 | Yb?: string;
|
|---|
| 24 | }
|
|---|
| 25 |
|
|---|
| 26 | interface SiJedecBytes {
|
|---|
| 27 | B?: string;
|
|---|
| 28 | KB?: string;
|
|---|
| 29 | MB?: string;
|
|---|
| 30 | GB?: string;
|
|---|
| 31 | TB?: string;
|
|---|
| 32 | PB?: string;
|
|---|
| 33 | EB?: string;
|
|---|
| 34 | ZB?: string;
|
|---|
| 35 | YB?: string;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | type SiJedec = SiJedecBits & SiJedecBytes & { [name: string]: string };
|
|---|
| 39 |
|
|---|
| 40 | interface Options {
|
|---|
| 41 | /**
|
|---|
| 42 | * Number base, default is 10
|
|---|
| 43 | */
|
|---|
| 44 | base?: number;
|
|---|
| 45 | /**
|
|---|
| 46 | * Enables bit sizes, default is false
|
|---|
| 47 | */
|
|---|
| 48 | bits?: boolean;
|
|---|
| 49 | /**
|
|---|
| 50 | * Specifies the SI suffix via exponent, e.g. 2 is MB for bytes, default is -1
|
|---|
| 51 | */
|
|---|
| 52 | exponent?: number;
|
|---|
| 53 | /**
|
|---|
| 54 | * Enables full form of unit of measure, default is false
|
|---|
| 55 | */
|
|---|
| 56 | fullform?: boolean;
|
|---|
| 57 | /**
|
|---|
| 58 | * Array of full form overrides, default is []
|
|---|
| 59 | */
|
|---|
| 60 | fullforms?: string[];
|
|---|
| 61 | /**
|
|---|
| 62 | * BCP 47 language tag to specify a locale, or true to use default locale, default is ""
|
|---|
| 63 | */
|
|---|
| 64 | locale?: string | boolean;
|
|---|
| 65 | /**
|
|---|
| 66 | * ECMA-402 number format option overrides, default is "{}"
|
|---|
| 67 | */
|
|---|
| 68 | localeOptions?: Intl.NumberFormatOptions;
|
|---|
| 69 | /**
|
|---|
| 70 | * Output of function (array, exponent, object, or string), default is string
|
|---|
| 71 | */
|
|---|
| 72 | output?: "array" | "exponent" | "object" | "string";
|
|---|
| 73 | /**
|
|---|
| 74 | * Decimal place end padding, default is false
|
|---|
| 75 | */
|
|---|
| 76 | pad?: boolean;
|
|---|
| 77 | /**
|
|---|
| 78 | * Sets precision of numerical output, default is 0
|
|---|
| 79 | */
|
|---|
| 80 | precision?: number;
|
|---|
| 81 | /**
|
|---|
| 82 | * Decimal place, default is 2
|
|---|
| 83 | */
|
|---|
| 84 | round?: number;
|
|---|
| 85 | /**
|
|---|
| 86 | * Rounding method, can be round, floor, or ceil, default is round
|
|---|
| 87 | */
|
|---|
| 88 | roundingMethod?: "round" | "floor" | "ceil";
|
|---|
| 89 | /**
|
|---|
| 90 | * Decimal separator character, default is `.`
|
|---|
| 91 | */
|
|---|
| 92 | separator?: string;
|
|---|
| 93 | /**
|
|---|
| 94 | * Character between the result and suffix, default is ` `
|
|---|
| 95 | */
|
|---|
| 96 | spacer?: string;
|
|---|
| 97 | /**
|
|---|
| 98 | * Standard unit of measure, can be iec or jedec, default is iec; can be overruled by base
|
|---|
| 99 | */
|
|---|
| 100 | standard?: "iec" | "jedec";
|
|---|
| 101 | /**
|
|---|
| 102 | * Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
|
|---|
| 103 | */
|
|---|
| 104 | symbols?: SiJedec;
|
|---|
| 105 | /**
|
|---|
| 106 | * Enables unix style human readable output, e.g ls -lh, default is false
|
|---|
| 107 | */
|
|---|
| 108 | unix?: boolean;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | // Result type inference from the output option
|
|---|
| 112 | interface ResultTypeMap {
|
|---|
| 113 | array: [number, string];
|
|---|
| 114 | exponent: number;
|
|---|
| 115 | object: {
|
|---|
| 116 | value: number,
|
|---|
| 117 | symbol: string,
|
|---|
| 118 | exponent: number,
|
|---|
| 119 | unit: string,
|
|---|
| 120 | };
|
|---|
| 121 | string: string;
|
|---|
| 122 | }
|
|---|
| 123 | type DefaultOutput<O extends Options> = Exclude<O["output"], keyof ResultTypeMap> extends never ? never : "string"
|
|---|
| 124 | type CanonicalOutput<O extends Options> = Extract<O["output"], keyof ResultTypeMap> | DefaultOutput<O>
|
|---|
| 125 |
|
|---|
| 126 | interface Filesize {
|
|---|
| 127 | (bytes: number): string;
|
|---|
| 128 | <O extends Options>(bytes: number, options: O): ResultTypeMap[CanonicalOutput<O>];
|
|---|
| 129 | partial: <O extends Options>(options: O) => ((bytes: number) => ResultTypeMap[CanonicalOutput<O>]);
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|