From dbccba291108088e2b6257d75712d13c2e3fd5ea Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Mon, 11 Nov 2019 20:47:30 +0100 Subject: [PATCH] [bytes] Update to v3.1.0 (#40285) --- types/bytes/bytes-tests.ts | 36 +++++++++++++++++------------------- types/bytes/index.d.ts | 23 +++++++++++++---------- types/bytes/tsconfig.json | 4 ++-- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/types/bytes/bytes-tests.ts b/types/bytes/bytes-tests.ts index d296f0b28f..92d829e496 100644 --- a/types/bytes/bytes-tests.ts +++ b/types/bytes/bytes-tests.ts @@ -1,23 +1,21 @@ import bytes = require('bytes'); -// 1024*1024 = 1048576 -console.log(bytes(undefined)); -console.log(bytes(null)); +bytes(104857); +bytes(104857, { thousandsSeparator: ' ' }); +bytes(104857, { decimalPlaces: 2 }); +bytes(104857, { fixedDecimals: true }); +bytes(104857, { unitSeparator: '-' }); +bytes(104857, { unit: 'GB' }); +bytes(104857, { unit: 'B' }); -console.log(bytes(104857)); -console.log(bytes(104857, { thousandsSeparator: ' ' })); -console.log(bytes(104857, { decimalPlaces: 2 })); -console.log(bytes(104857, { fixedDecimals: true })); -console.log(bytes(104857, { unitSeparator: '-' })); -console.log(bytes(104857, { unit: 'GB' })); +bytes.format(104857); +bytes.format(104857, { thousandsSeparator: ' ' }); +bytes.format(104857, { decimalPlaces: 2 }); +bytes.format(104857, { fixedDecimals: true }); +bytes.format(104857, { unitSeparator: '-' }); +bytes.format(104857, { unit: 'GB' }); +bytes.format(104857, { unit: 'pb' }); -console.log(bytes.format(104857)); -console.log(bytes.format(104857, { thousandsSeparator: ' ' })); -console.log(bytes.format(104857, { decimalPlaces: 2 })); -console.log(bytes.format(104857, { fixedDecimals: true })); -console.log(bytes.format(104857, { unitSeparator: '-' })); -console.log(bytes.format(104857, { unit: 'GB' })); - -console.log(bytes('1024kb')); -console.log(bytes.parse('1024kb')); -console.log(bytes.parse(1024)); +bytes('1024kb'); +bytes.parse('1024kb'); +bytes.parse(1024); diff --git a/types/bytes/index.d.ts b/types/bytes/index.d.ts index 68a45413c9..5624e001fd 100644 --- a/types/bytes/index.d.ts +++ b/types/bytes/index.d.ts @@ -1,21 +1,14 @@ -// Type definitions for bytes 3.0 +// Type definitions for bytes 3.1 // Project: https://github.com/visionmedia/bytes.js // Definitions by: Zhiyuan Wang // Rickard Laurin +// Florian Keller // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -interface BytesOptions { - decimalPlaces?: number; - thousandsSeparator?: string; - unitSeparator?: string; - fixedDecimals?: boolean; - unit?: string; -} - /** * Convert the given value in bytes into a string. */ -declare function bytes(value: number, options?: BytesOptions): string; +declare function bytes(value: number, options?: bytes.BytesOptions): string; /** * Parse string to an integer in bytes. @@ -23,6 +16,16 @@ declare function bytes(value: number, options?: BytesOptions): string; declare function bytes(value: string): number; declare namespace bytes { + type Unit = 'b' | 'gb' | 'kb' | 'mb' | 'pb' | 'tb' | 'B' | 'GB' | 'KB' | 'MB' | 'PB' | 'TB'; + + interface BytesOptions { + decimalPlaces?: number; + fixedDecimals?: boolean; + thousandsSeparator?: string; + unit?: Unit; + unitSeparator?: string; + } + /** * Format the given value in bytes into a string. * diff --git a/types/bytes/tsconfig.json b/types/bytes/tsconfig.json index 4de1fdb57a..64a9dc5f14 100644 --- a/types/bytes/tsconfig.json +++ b/types/bytes/tsconfig.json @@ -7,7 +7,7 @@ ], "noImplicitAny": true, "noImplicitThis": true, - "strictNullChecks": false, + "strictNullChecks": true, "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ @@ -21,4 +21,4 @@ "index.d.ts", "bytes-tests.ts" ] -} \ No newline at end of file +}