mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #6491 from danny8002/master
add definitions and tests for merge-descriptors/ms/bytes/depd package
This commit is contained in:
@@ -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));
|
||||
Vendored
+62
@@ -0,0 +1,62 @@
|
||||
// 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' {
|
||||
|
||||
/**
|
||||
*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?: { thousandsSeparator: string }): 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 {BytesFormatOptions} [options]
|
||||
*/
|
||||
|
||||
function format(value: number, options?: { thousandsSeparator: string }): 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;
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
/// <reference path="./depd.d.ts"/>
|
||||
|
||||
import depd = require('depd');
|
||||
|
||||
var deprecate = depd("depd-tests");
|
||||
|
||||
function assert(condition: boolean, message: string): void {
|
||||
if (!condition) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
function testDepdMessage(...args: string[]): boolean {
|
||||
if (arguments.length < 1) {
|
||||
deprecate('testDepdMessage argument.lenth<1');
|
||||
return true;
|
||||
} else {
|
||||
console.log('normal logic');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
assert(testDepdMessage() === true, "Deprecated code must be triggered!");
|
||||
assert(testDepdMessage('a') === false, "Deprecated code must be triggered!");
|
||||
|
||||
interface ITestObject {
|
||||
p1: string;
|
||||
p2: string;
|
||||
}
|
||||
|
||||
var obj = <ITestObject>{ p1: 'deprecated property', p2: 'normal property' };
|
||||
deprecate.property(obj, 'p1', 'property [p1] is deprecated!');
|
||||
|
||||
console.log(obj.p1);
|
||||
|
||||
interface ITestDeprecatedFunction {
|
||||
func1?: Function;
|
||||
func2?: Function;
|
||||
}
|
||||
|
||||
var obj2 = <ITestDeprecatedFunction>{};
|
||||
|
||||
// message automatically derived from function name
|
||||
obj2.func1 = deprecate.function(function func1() {
|
||||
console.log('all calls to [func1] are deprecated ');
|
||||
});
|
||||
|
||||
// specific message
|
||||
obj2.func2 = deprecate.function(function () {
|
||||
console.log('all calls to [func2] are deprecated ');
|
||||
}, 'func2');
|
||||
|
||||
obj2.func1();
|
||||
obj2.func2();
|
||||
Vendored
+17
@@ -0,0 +1,17 @@
|
||||
// Type definitions for depd 1.1.0
|
||||
// Project: https://github.com/dougwilson/nodejs-depd
|
||||
// Definitions by: Zhiyuan Wang <https://github.com/danny8002/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
|
||||
declare module 'depd' {
|
||||
function depd(namespace: string): Deprecate;
|
||||
|
||||
interface Deprecate {
|
||||
(message: string): void;
|
||||
function(fn: Function, message?: string): Function;
|
||||
property(obj: Object, prop: string, message: string): void;
|
||||
}
|
||||
|
||||
export = depd;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/// <reference path="merge-descriptors.d.ts"/>
|
||||
import mixin = require('merge-descriptors');
|
||||
|
||||
function testAssertion(condition: boolean, errorMessage: string) {
|
||||
if (!condition) {
|
||||
throw new Error(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
interface IMergedObject {
|
||||
InSrc?: string;
|
||||
name: string;
|
||||
InTarget: string;
|
||||
}
|
||||
|
||||
var src = {
|
||||
InSrc: 'src',
|
||||
get name(): string {
|
||||
return 'from src name';
|
||||
}
|
||||
}
|
||||
|
||||
var target: IMergedObject = { name: 'my target name', InTarget: 'target' };
|
||||
|
||||
var target2 = mixin(target, src, true);
|
||||
|
||||
console.log(JSON.stringify(target));
|
||||
|
||||
testAssertion(target2 === target, "Returned object should refer to input [destination] object");
|
||||
testAssertion(target.name === 'from src name', "[redfine]=true, source member will overwrite destination member");
|
||||
testAssertion(target.InTarget === 'target', "overwrite do not affect members only in [destination]");
|
||||
testAssertion(target['InSrc'] === 'src', "members from [source] must be copied to [destination]");
|
||||
|
||||
var nameProperty:PropertyDescriptor = Object.getOwnPropertyDescriptor(target, "name");
|
||||
testAssertion(nameProperty.set === undefined, "member descriptor must be overwritten");
|
||||
@@ -0,0 +1 @@
|
||||
--noImplicitAny --module commonjs --target es5
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
// Type definitions for merge-descriptors
|
||||
// Project: https://github.com/component/merge-descriptors
|
||||
// Definitions by: Zhiyuan Wang <https://github.com/danny8002/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'merge-descriptors' {
|
||||
|
||||
function merge(destination: Object, source: Object): Object;
|
||||
|
||||
function merge(destination: Object, source: Object, redefine: boolean): Object;
|
||||
|
||||
export = merge;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
/// <reference path="./ms.d.ts"/>
|
||||
|
||||
import ms = require('ms');
|
||||
|
||||
ms('2 days') // 172800000
|
||||
ms('1d') // 86400000
|
||||
|
||||
ms(60000) // "1m"
|
||||
ms(2 * 60000) // "2m"
|
||||
ms(ms('10 hours')) // "10h"
|
||||
|
||||
ms(60000, { long: true }) // "1 minute"
|
||||
ms(2 * 60000, { long: true }) // "2 minutes"
|
||||
ms(ms('10 hours'), { long: true }) // "10 hours"
|
||||
Vendored
+26
@@ -0,0 +1,26 @@
|
||||
// Type definitions for ms v0.7.1
|
||||
// Project: https://github.com/guille/ms.js
|
||||
// Definitions by: Zhiyuan Wang <https://github.com/danny8002/>
|
||||
// Definitions: https://github.com/borisyankov/DefinitelyTyped
|
||||
|
||||
declare module 'ms' {
|
||||
|
||||
/**
|
||||
* Short/Long format for `value`.
|
||||
*
|
||||
* @param {Number} value
|
||||
* @param {{long: boolean}} options
|
||||
* @return {String}
|
||||
*/
|
||||
function ms(value: number, options?: { long: boolean }): string;
|
||||
|
||||
/**
|
||||
* Parse the given `value` and return milliseconds.
|
||||
*
|
||||
* @param {String} value
|
||||
* @return {Number}
|
||||
*/
|
||||
function ms(value: string): number;
|
||||
|
||||
export = ms;
|
||||
}
|
||||
Reference in New Issue
Block a user