mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add definitions and tests for NodeJs package bytes v2.1.0
This commit is contained in:
parent
cb16d9359e
commit
b1956785d6
16
bytes/bytes-tests.ts
Normal file
16
bytes/bytes-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
/// <reference path="./bytes.d.ts"/>
|
||||
|
||||
import bytes = require('bytes');
|
||||
|
||||
// 1024*1024 = 1048576
|
||||
console.log(bytes(104857));
|
||||
console.log(bytes(104857, { thousandsSeparator: ' ' }));
|
||||
|
||||
console.log(bytes.format(104857));
|
||||
console.log(bytes.format(104857, { thousandsSeparator: ' ' }));
|
||||
|
||||
console.log(bytes('1024kb'));
|
||||
console.log(bytes(1024));
|
||||
|
||||
console.log(bytes.parse('1024kb'));
|
||||
console.log(bytes.parse(1024));
|
||||
66
bytes/bytes.d.ts
vendored
Normal file
66
bytes/bytes.d.ts
vendored
Normal file
@ -0,0 +1,66 @@
|
||||
// Type definitions for bytes v2.1.0
|
||||
// Project: https://github.com/visionmedia/bytes.js
|
||||
// Definitions by: Zhiyuan Wang <https://github.com/danny8002/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'bytes' {
|
||||
|
||||
interface IBytesFormatOptions {
|
||||
thousandsSeparator: string
|
||||
}
|
||||
|
||||
/**
|
||||
*Convert the given value in bytes into a string.
|
||||
*
|
||||
* @param {number} value
|
||||
* @param {{
|
||||
* thousandsSeparator: [string]
|
||||
* }} [options] bytes options.
|
||||
*
|
||||
* @returns {string}
|
||||
*/
|
||||
function bytes(value: number, options?: IBytesFormatOptions): string;
|
||||
|
||||
/**
|
||||
*Parse string to an integer in bytes.
|
||||
*
|
||||
* @param {string} value
|
||||
* @returns {number}
|
||||
*/
|
||||
function bytes(value: string): number;
|
||||
|
||||
module bytes {
|
||||
|
||||
/**
|
||||
* Format the given value in bytes into a string.
|
||||
*
|
||||
* If the value is negative, take Math.abs(). If it is a float,
|
||||
* it is rounded.
|
||||
*
|
||||
* @param {number} value
|
||||
* @param {IBytesFormatOptions} [options]
|
||||
*/
|
||||
|
||||
function format(value: number, options?: IBytesFormatOptions): string;
|
||||
|
||||
/**
|
||||
* Just return the input number value.
|
||||
*
|
||||
* @param {number} value
|
||||
* @return {number}
|
||||
*/
|
||||
function parse(value: number): number;
|
||||
|
||||
/**
|
||||
* Parse the string value into an integer in bytes.
|
||||
*
|
||||
* If no unit is given, it is assumed the value is in bytes.
|
||||
*
|
||||
* @param {string} value
|
||||
* @return {number}
|
||||
*/
|
||||
function parse(value: string): number;
|
||||
}
|
||||
|
||||
export = bytes;
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user