diff --git a/types/file-size/file-size-tests.ts b/types/file-size/file-size-tests.ts new file mode 100644 index 0000000000..ea8a804070 --- /dev/null +++ b/types/file-size/file-size-tests.ts @@ -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 diff --git a/types/file-size/index.d.ts b/types/file-size/index.d.ts new file mode 100644 index 0000000000..72359e1bb5 --- /dev/null +++ b/types/file-size/index.d.ts @@ -0,0 +1,39 @@ +// Type definitions for file-size 1.0 +// Project: https://github.com/Nijikokun/file-size +// Definitions by: Richie Bendall +// 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(bytes: number, options?: T): Required & Result; + +export as namespace filesize; + +export = fileSize; diff --git a/types/file-size/tsconfig.json b/types/file-size/tsconfig.json new file mode 100644 index 0000000000..0fcc7d5f02 --- /dev/null +++ b/types/file-size/tsconfig.json @@ -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" + ] +} diff --git a/types/file-size/tslint.json b/types/file-size/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/file-size/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }