diff --git a/types/filesize/filesize-tests.ts b/types/filesize/filesize-tests.ts index 135a0f9baa..6980ac892d 100644 --- a/types/filesize/filesize-tests.ts +++ b/types/filesize/filesize-tests.ts @@ -1,15 +1,20 @@ - - 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 +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 +filesize(265318, {standard: "iec"}); // "259.1 KiB" +filesize(265318, {standard: "iec", fullform: true}); // "259.1 kibibytes" +filesize(12, {fullform: true, fullforms: ["байтов"]}); // "12 байтов" +filesize(265318, {separator: ","}); // "259,1 KB" + +const size = filesize.partial({standard: "iec"}); +size(265318); diff --git a/types/filesize/index.d.ts b/types/filesize/index.d.ts index 374db62ec8..511e2373af 100644 --- a/types/filesize/index.d.ts +++ b/types/filesize/index.d.ts @@ -1,15 +1,15 @@ -// Type definitions for filesize 3.2.1 +// Type definitions for filesize 3.6 // Project: https://github.com/avoidwork/filesize.js // Definitions by: Giedrius Grabauskas +// Renaud Chaput // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare var fileSize: Filesize.IFilesize; +declare var fileSize: Filesize.Filesize; export = fileSize; export as namespace filesize; declare namespace Filesize { - - export interface SiJedecBits { + interface SiJedecBits { b?: string; Kb?: string; Mb?: string; @@ -21,7 +21,7 @@ declare namespace Filesize { Yb?: string; } - export interface SiJedecBytes { + interface SiJedecBytes { B?: string; KB?: string; MB?: string; @@ -35,48 +35,64 @@ declare namespace Filesize { type SiJedec = SiJedecBits & SiJedecBytes & { [name: string]: string }; - export interface Options { + interface Options { /** - * Enables bit sizes, default is false - */ - bits?: boolean; - /** - * Number base, default is 2 - */ + * Number base, default is 2 + */ base?: number; /** - * Decimal place, default is 2 - */ - round?: number; + * Enables bit sizes, default is false + */ + bits?: boolean; /** - * 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 - */ + * 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; + * Enables full form of unit of measure, default is false + */ + fullform?: boolean; /** - * Character between the result and suffix, default is " " - */ + * Array of full form overrides, default is [] + */ + fullforms?: string[]; + /** + * Output of function (array, exponent, object, or string), default is string + */ + output?: "array" | "exponent" | "object" | "string"; + /** + * Decimal place, default is 2 + */ + round?: number; + /** + * Decimal separator character, default is `.` + */ + separator?: string; + /** + * Character between the result and suffix, default is ` ` + */ spacer?: string; + /** + * Standard unit of measure, can be iec or jedec, default is jedec; can be overruled by base + */ + standard?: "iec" | "jedec"; + /** + * Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found + */ + symbols?: SiJedec; + /** + * Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found + * @deprecated: use `symbols` + */ + suffixes?: SiJedec; + /** + * Enables unix style human readable output, e.g ls -lh, default is false + */ + unix?: boolean; } - export interface IFilesize { - (bytes: number): string; - (bytes: number, options: Options): string; + interface Filesize { + (bytes: number, options?: Options): string; + partial: (options: Options) => ((bytes: number) => string); } } diff --git a/types/filesize/tslint.json b/types/filesize/tslint.json index a41bf5d19a..f93cf8562a 100644 --- a/types/filesize/tslint.json +++ b/types/filesize/tslint.json @@ -1,79 +1,3 @@ { - "extends": "dtslint/dt.json", - "rules": { - "adjacent-overload-signatures": false, - "array-type": false, - "arrow-return-shorthand": false, - "ban-types": false, - "callable-types": false, - "comment-format": false, - "dt-header": false, - "eofline": false, - "export-just-namespace": false, - "import-spacing": false, - "interface-name": false, - "interface-over-type-literal": false, - "jsdoc-format": false, - "max-line-length": false, - "member-access": false, - "new-parens": false, - "no-any-union": false, - "no-boolean-literal-compare": false, - "no-conditional-assignment": false, - "no-consecutive-blank-lines": false, - "no-construct": false, - "no-declare-current-package": false, - "no-duplicate-imports": false, - "no-duplicate-variable": false, - "no-empty-interface": false, - "no-for-in-array": false, - "no-inferrable-types": false, - "no-internal-module": false, - "no-irregular-whitespace": false, - "no-mergeable-namespace": false, - "no-misused-new": false, - "no-namespace": false, - "no-object-literal-type-assertion": false, - "no-padding": false, - "no-redundant-jsdoc": false, - "no-redundant-jsdoc-2": false, - "no-redundant-undefined": false, - "no-reference-import": false, - "no-relative-import-in-test": false, - "no-self-import": false, - "no-single-declare-module": false, - "no-string-throw": false, - "no-unnecessary-callback-wrapper": false, - "no-unnecessary-class": false, - "no-unnecessary-generics": false, - "no-unnecessary-qualifier": false, - "no-unnecessary-type-assertion": false, - "no-useless-files": false, - "no-var-keyword": false, - "no-var-requires": false, - "no-void-expression": false, - "no-trailing-whitespace": false, - "object-literal-key-quotes": false, - "object-literal-shorthand": false, - "one-line": false, - "one-variable-per-declaration": false, - "only-arrow-functions": false, - "prefer-conditional-expression": false, - "prefer-const": false, - "prefer-declare-function": false, - "prefer-for-of": false, - "prefer-method-signature": false, - "prefer-template": false, - "radix": false, - "semicolon": false, - "space-before-function-paren": false, - "space-within-parens": false, - "strict-export-declare-modifiers": false, - "trim-file": false, - "triple-equals": false, - "typedef-whitespace": false, - "unified-signatures": false, - "void-return": false, - "whitespace": false - } + "extends": "dtslint/dt.json" }