mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
feat: Add typings for file-size (#41824)
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
bc1087ecf1
commit
84fe8dca51
10
types/file-size/file-size-tests.ts
Normal file
10
types/file-size/file-size-tests.ts
Normal 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
39
types/file-size/index.d.ts
vendored
Normal 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;
|
||||
23
types/file-size/tsconfig.json
Normal file
23
types/file-size/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/file-size/tslint.json
Normal file
1
types/file-size/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user