mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-23 12:56:46 +08:00
Added Filesize definitions (#8908)
* filesize definition file added. * Updated filesize definition. * Added SiJedec type to suffixes * Created filesize tests file. * Added definition file reference in tests.
This commit is contained in:
committed by
Masahiro Wakame
parent
92b2c03c29
commit
abe95c4057
15
filesize/filesize-tests.ts
Normal file
15
filesize/filesize-tests.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
/// <reference path="filesize.d.ts" />
|
||||
|
||||
import filesize = require("filesize");
|
||||
|
||||
filesize(500); // "500 B"
|
||||
filesize(500, { bits: true }); // "4 Kb"
|
||||
filesize(265318, { base: 10 }); // "265.32 kB"
|
||||
filesize(265318); // "259.1 KB"
|
||||
filesize(265318, { round: 0 }); // "259 KB"
|
||||
filesize(265318, { output: "array" }); // [259.1, "KB"]
|
||||
filesize(265318, { output: "object" }); // {value: 259.1, suffix: "KB", symbol: "KB"}
|
||||
filesize(1, { symbols: { B: "Б" } }); // "1 Б"
|
||||
filesize(1024); // "1 KB"
|
||||
filesize(1024, { exponent: 0 }); // "1024 B"
|
||||
filesize(1024, { output: "exponent" }); // 1
|
||||
84
filesize/filesize.d.ts
vendored
Normal file
84
filesize/filesize.d.ts
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
// Type definitions for filesize 3.2.1
|
||||
// Project: https://github.com/avoidwork/filesize.js
|
||||
// Definitions by: Giedrius Grabauskas <https://github.com/GiedriusGrabauskas>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare namespace Filesize {
|
||||
|
||||
export interface SiJedecBits {
|
||||
b?: string;
|
||||
Kb?: string;
|
||||
Mb?: string;
|
||||
Gb?: string;
|
||||
Tb?: string;
|
||||
Pb?: string;
|
||||
Eb?: string;
|
||||
Zb?: string;
|
||||
Yb?: string;
|
||||
}
|
||||
|
||||
export interface SiJedecBytes {
|
||||
B?: string;
|
||||
KB?: string;
|
||||
MB?: string;
|
||||
GB?: string;
|
||||
TB?: string;
|
||||
PB?: string;
|
||||
EB?: string;
|
||||
ZB?: string;
|
||||
YB?: string;
|
||||
}
|
||||
|
||||
type SiJedec = SiJedecBits & SiJedecBytes & { [name: string]: string };
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* Enables bit sizes, default is false
|
||||
*/
|
||||
bits?: boolean;
|
||||
/**
|
||||
* Number base, default is 2
|
||||
*/
|
||||
base?: number;
|
||||
/**
|
||||
* Decimal place, default is 2
|
||||
*/
|
||||
round?: number;
|
||||
/**
|
||||
* Output of function (array, exponent, object, or string), default is string
|
||||
*/
|
||||
output?: string;
|
||||
/**
|
||||
* Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
|
||||
* @deprecated: use 'symbols'
|
||||
*/
|
||||
suffixes?: SiJedec;
|
||||
/**
|
||||
* Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found
|
||||
*/
|
||||
symbols?: SiJedec;
|
||||
/**
|
||||
* Specifies the SI suffix via exponent, e.g. 2 is MB for bytes, default is -1
|
||||
*/
|
||||
exponent?: number;
|
||||
/**
|
||||
* Enables unix style human readable output, e.g ls -lh, default is false
|
||||
*/
|
||||
unix?: boolean;
|
||||
/**
|
||||
* Character between the result and suffix, default is " "
|
||||
*/
|
||||
spacer?: string;
|
||||
}
|
||||
|
||||
export interface IFilesize {
|
||||
(bytes: number): string;
|
||||
(bytes: number, options: Options): string;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
declare module "filesize" {
|
||||
let fileSize: Filesize.IFilesize;
|
||||
export = fileSize;
|
||||
}
|
||||
Reference in New Issue
Block a user