[bytes] Update to v3.1.0 (#40285)

This commit is contained in:
Florian Keller 2019-11-11 20:47:30 +01:00 committed by Pranav Senthilnathan
parent 8c1bc9265b
commit dbccba2911
3 changed files with 32 additions and 31 deletions

View File

@ -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);

View File

@ -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 <https://github.com/danny8002>
// Rickard Laurin <https://github.com/believer>
// Florian Keller <https://github.com/ffflorian>
// 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.
*

View File

@ -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"
]
}
}