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:
Giedrius Grabauskas
2016-04-12 17:04:48 +03:00
committed by Masahiro Wakame
parent 92b2c03c29
commit abe95c4057
2 changed files with 99 additions and 0 deletions

View 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
View 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;
}