feat: Add typings for file-size (#41824)

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
Richie Bendall 2020-01-25 13:25:35 +13:00 committed by Ben Lichtman
parent bc1087ecf1
commit 84fe8dca51
4 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,10 @@
import fileSize = require("file-size");
const fz = fileSize(14235235);
fz.fixed; // $ExpectType number
fz.spacer; // $ExpectType string
fz.human(); // $ExpectType string
fz.calculate(); // $ExpectType Calculated
fz.to("KB"); // $ExpectType string

39
types/file-size/index.d.ts vendored Normal file
View File

@ -0,0 +1,39 @@
// Type definitions for file-size 1.0
// Project: https://github.com/Nijikokun/file-size
// Definitions by: Richie Bendall <https://github.com/Richienb>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
interface Options {
fixed?: number;
spacer?: string;
}
type Spec = "si" | "iec" | "jedec";
type Unit = "B" | "KB" | "MB" | "GB" | "TB" | "PB" | "EB" | "ZB" | "YB";
interface Bits {
result: number;
fixed: string;
}
interface Calculated {
suffix: string;
magnitude: number;
result: number;
fixed: string;
bits: Bits;
}
interface Result {
human(spec?: Spec): string;
to(unit: Unit, spec?: Spec): string;
calculate(spec?: Spec): Calculated;
}
declare function fileSize<T extends Options>(bytes: number, options?: T): Required<T> & Result;
export as namespace filesize;
export = fileSize;

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"file-size-tests.ts"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }