diff --git a/bytes/bytes-tests.ts b/bytes/bytes-tests.ts new file mode 100644 index 000000000..4a981aee4 --- /dev/null +++ b/bytes/bytes-tests.ts @@ -0,0 +1,16 @@ +/// + +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)); \ No newline at end of file diff --git a/bytes/bytes.d.ts b/bytes/bytes.d.ts new file mode 100644 index 000000000..0d8a63cf7 --- /dev/null +++ b/bytes/bytes.d.ts @@ -0,0 +1,62 @@ +// Type definitions for bytes v2.1.0 +// Project: https://github.com/visionmedia/bytes.js +// Definitions by: Zhiyuan Wang +// 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; +} \ No newline at end of file diff --git a/depd/depd-tests.ts b/depd/depd-tests.ts new file mode 100644 index 000000000..14dfbe72c --- /dev/null +++ b/depd/depd-tests.ts @@ -0,0 +1,54 @@ +/// + +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 = { 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 = {}; + +// 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(); \ No newline at end of file diff --git a/depd/depd.d.ts b/depd/depd.d.ts new file mode 100644 index 000000000..1af4eaa8d --- /dev/null +++ b/depd/depd.d.ts @@ -0,0 +1,17 @@ +// Type definitions for depd 1.1.0 +// Project: https://github.com/dougwilson/nodejs-depd +// Definitions by: Zhiyuan Wang +// 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; +} \ No newline at end of file diff --git a/merge-descriptors/merge-descriptors-tests.ts b/merge-descriptors/merge-descriptors-tests.ts new file mode 100644 index 000000000..81376320f --- /dev/null +++ b/merge-descriptors/merge-descriptors-tests.ts @@ -0,0 +1,35 @@ +/// +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"); \ No newline at end of file diff --git a/merge-descriptors/merge-descriptors-tests.ts.tscparams b/merge-descriptors/merge-descriptors-tests.ts.tscparams new file mode 100644 index 000000000..4169d3605 --- /dev/null +++ b/merge-descriptors/merge-descriptors-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny --module commonjs --target es5 \ No newline at end of file diff --git a/merge-descriptors/merge-descriptors.d.ts b/merge-descriptors/merge-descriptors.d.ts new file mode 100644 index 000000000..8e3212edd --- /dev/null +++ b/merge-descriptors/merge-descriptors.d.ts @@ -0,0 +1,13 @@ +// Type definitions for merge-descriptors +// Project: https://github.com/component/merge-descriptors +// Definitions by: Zhiyuan Wang +// 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; +} \ No newline at end of file diff --git a/ms/ms-tests.ts b/ms/ms-tests.ts new file mode 100644 index 000000000..75312e927 --- /dev/null +++ b/ms/ms-tests.ts @@ -0,0 +1,14 @@ +/// + +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" \ No newline at end of file diff --git a/ms/ms.d.ts b/ms/ms.d.ts new file mode 100644 index 000000000..fe26e03e3 --- /dev/null +++ b/ms/ms.d.ts @@ -0,0 +1,26 @@ +// Type definitions for ms v0.7.1 +// Project: https://github.com/guille/ms.js +// Definitions by: Zhiyuan Wang +// 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; +} \ No newline at end of file