diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 23fbf41c5..60ef278e8 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -85,6 +85,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](bl/bl.d.ts) [BufferList](https://github.com/rvagg/bl) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](bufferstream/bufferstream.d.ts) [bufferstream](https://github.com/dodo/node-bufferstream) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](business-rules-engine/business-rules-engine.d.ts) [business-rules-engine](https://github.com/rsamec/form) by [Roman Samec](https://github.com/rsamec) +* [:link:](byline/byline.d.ts) [byline](https://github.com/jahewson/node-byline) by [Stefan Steinhart](https://github.com/reppners) * [:link:](camljs/camljs.d.ts) [camljs](http://camljs.codeplex.com) by [Andrey Markeev](http://markeev.com) * [:link:](canvasjs/canvasjs.d.ts) [CanvasJS](http://canvasjs.com) by [Mark Overholt](https://github.com/mover5) * [:link:](casperjs/casperjs.d.ts) [CasperJS](http://casperjs.org) by [Jed Mao](https://github.com/jedmao) @@ -174,6 +175,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](es6-promise/es6-promise.d.ts) [es6-promise](https://github.com/jakearchibald/ES6-Promise) by [François de Campredon](https://github.com/fdecampredon), [vvakame](https://github.com/vvakame) * [:link:](esprima/esprima.d.ts) [Esprima](http://esprima.org) by [teppeis](https://github.com/teppeis) * [:link:](eventemitter2/eventemitter2.d.ts) [EventEmitter2](https://github.com/asyncly/EventEmitter2) by [ryiwamoto](https://github.com/ryiwamoto) +* [:link:](event-loop-lag/event-loop-lag.d.ts) [event-loop-lag](https://github.com/pebble/event-loop-lag) by [rogierschouten](https://github.com/rogierschouten) * [:link:](exit/exit.d.ts) [exit](https://github.com/cowboy/node-exit) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](expect.js/expect.js.d.ts) [expect.js](https://github.com/LearnBoost/expect.js) by [Teppei Sato](https://github.com/teppeis) * [:link:](expectations/expectations.d.ts) [expectations.js](https://github.com/spmason/expectations) by [vvakame](https://github.com/vvakame) @@ -293,7 +295,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](ix.js/ix.d.ts) [IxJS 1.0.6 / ix.js](https://github.com/Reactive-Extensions/IxJS) by [Igor Oleinikov](https://github.com/Igorbek) * [:link:](ix.js/l2o.d.ts) [IxJS 1.0.6 / l2o.js](https://github.com/Reactive-Extensions/IxJS) by [Igor Oleinikov](https://github.com/Igorbek) * [:link:](jake/jake.d.ts) [jake](https://github.com/mde/jake) by [Kon](http://phyzkit.net) -* [:link:](jasmine/jasmine.d.ts) [Jasmine](http://pivotal.github.com/jasmine) by [Boris Yankov](https://github.com/borisyankov), [Theodore Brown](https://github.com/theodorejb), [David Pärsson](https://github.com/davidparsson) +* [:link:](jasmine/jasmine.d.ts) [Jasmine](http://jasmine.github.io) by [Boris Yankov](https://github.com/borisyankov), [Theodore Brown](https://github.com/theodorejb), [David Pärsson](https://github.com/davidparsson) * [:link:](jasmine-data_driven_tests/jasmine-data_driven_tests.d.ts) [Jasmine Data Driven Tests](https://github.com/gburghardt/jasmine-data_driven_tests) by [Anthony MacKinnon](https://github.com/AnthonyMacKinnon) * [:link:](jasmine-fixture/jasmine-fixture.d.ts) [Jasmine-fixture](https://github.com/searls/jasmine-fixture) by [Craig Brett](https://github.com/craigbrett17) * [:link:](jasmine-jquery/jasmine-jquery.d.ts) [Jasmine-JQuery](https://github.com/velesin/jasmine-jquery) by [Gregor Stamac](https://github.com/gstamac) @@ -516,6 +518,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](xml2js/xml2js.d.ts) [node-xml2js](https://github.com/Leonidas-from-XIV/node-xml2js) by [Michel Salib](https://github.com/michelsalib), [Jason McNeil](https://github.com/jasonrm) * [:link:](node/node.d.ts) [Node.js](http://nodejs.org) by [Microsoft TypeScript](http://typescriptlang.org), [DefinitelyTyped](https://github.com/borisyankov/DefinitelyTyped) * [:link:](restify/restify.d.ts) [node.js REST framework](https://github.com/mcavage/node-restify) by [Bret Little](https://github.com/blittle) +* [:link:](mdns/mdns.d.ts) [node_mdns](https://github.com/agnat/node_mdns) by [Stefan Steinhart](https://github.com/reppners) * [:link:](node_redis/node_redis.d.ts) [node_redis](https://github.com/mranney/node_redis) by [Boris Yankov](https://github.com/borisyankov) * [:link:](each/each.d.ts) [NodeEach](http://www.adaltas.com/projects/node-each) by [Michael Zabka](https://github.com/misak113) * [:link:](nodemailer/nodemailer.d.ts) [Nodemailer](https://github.com/andris9/Nodemailer) by [Vincent Bortone](https://github.com/vbortone) @@ -579,6 +582,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](qajax/qajax.d.ts) [Qajax](https://github.com/gre/qajax) by [Boltmade](https://github.com/Boltmade) * [:link:](qunit/qunit.d.ts) [QUnit](http://qunitjs.com) by [Diullei Gomes](https://github.com/diullei) * [:link:](rabbit.js/rabbit.js.d.ts) [rabbit.js](https://github.com/squaremo/rabbit.js) by [Wonshik Kim](https://github.com/wokim) +* [:link:](ractive/ractive.d.ts) [Ractive 0.7.0 edge f22ab8ad0a640591b1c263f57e21d1565cb26bf5](http://ractivejs.org) by [Han Lin Yap](http://yap.nu) * [:link:](raphael/raphael.d.ts) [Raphael](http://raphaeljs.com) by [CheCoxshall](https://github.com/CheCoxshall) * [:link:](ravenjs/ravenjs.d.ts) [Raven.js](https://github.com/getsentry/raven-js) by [Santi Albo](https://github.com/santialbo) * [:link:](react/react.d.ts) [React](http://facebook.github.io/react) by [Asana](https://asana.com) @@ -675,6 +679,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](swiz/swiz.d.ts) [swiz](https://github.com/racker/node-swiz) by [Jeff Goddard](https://github.com/jedigo) * [:link:](tape/tape.d.ts) [tape](https://github.com/substack/tape) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](tar/tar.d.ts) [tar](https://github.com/npm/node-tar) by [Maxime LUCE](https://github.com/SomaticIT) +* [:link:](tcomb/tcomb.d.ts) [tcomb](https://github.com/npm/tcomb) by [Jed Mao](https://github.com/jedmao) * [:link:](tedious/tedious.d.ts) [tedious](https://pekim.github.io/tedious) by [Rogier Schouten](https://github.com/rogierschouten) * [:link:](tedious-connection-pool/tedious-connection-pool.d.ts) [tedious-connection-pool](https://github.com/pekim/tedious-connection-pool) by [Cyprien Autexier](https://github.com/sandorfr) * [:link:](teechart/teechart.d.ts) [TeeChart](http://www.steema.com) by [Steema Software](https://steema.com) @@ -709,6 +714,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](tween.js/tween.js.d.ts) [tween.js r12](https://github.com/sole/tween.js) by [sunetos](https://github.com/sunetos), [jzarnikov](https://github.com/jzarnikov) * [:link:](tweenjs/tweenjs.d.ts) [TweenJS](http://www.createjs.com/#!/TweenJS) by [Pedro Ferreira](https://bitbucket.org/drk4), [Chris Smith](https://github.com/evilangelist) * [:link:](twig/twig.d.ts) [twig](https://github.com/justjohn/twig.js) by [Carlos Ballesteros Velasco](https://github.com/soywiz) +* [:link:](twitter/twitter.d.ts) [Twitter for Websites](https://dev.twitter.com/web) by [Chitoku](https://github.com/chitoku-k) * [:link:](jquery.bootstrap.wizard/jquery.bootstrap.wizard.d.ts) [twitter-bootstrap-wizard](https://github.com/VinceG/twitter-bootstrap-wizard) by [Blake Niemyjski](https://github.com/niemyjski) * [:link:](type-detect/type-detect.d.ts) [type-detect](https://github.com/chaijs/type-detect) by [Bart van der Schoor](https://github.com/Bartvds) * [:link:](typeahead/typeahead.d.ts) [typeahead.js](http://twitter.github.io/typeahead.js) by [Ivaylo Gochkov](https://github.com/igochkov), [Gidon Junge](https://github.com/gjunge) diff --git a/README.md b/README.md index 479e04cc8..cf20cf55a 100644 --- a/README.md +++ b/README.md @@ -30,7 +30,7 @@ Please see the [contribution guide](http://definitelytyped.org/guides/contributi ## Requested definitions -Here is an updated list of [definitions people have requested](https://github.com/borisyankov/DefinitelyTyped/issues?labels=Definition%3ARequest). +Here is are the [currently requested definitions](https://github.com/borisyankov/DefinitelyTyped/labels/Definition%3ARequest). ## Licence @@ -38,4 +38,4 @@ This project is licensed under the MIT license. Copyrights on the definition files are respective of each contributor listed at the beginning of each definition file. -[![Analytics](https://ga-beacon.appspot.com/UA-47495295-4/borisyankov/DefinitelyTyped)](https://github.com/igrigorik/ga-beacon) \ No newline at end of file +[![Analytics](https://ga-beacon.appspot.com/UA-47495295-4/borisyankov/DefinitelyTyped)](https://github.com/igrigorik/ga-beacon) diff --git a/angular-file-upload/angular-file-upload.d.ts b/angular-file-upload/angular-file-upload.d.ts index 9c3542888..f2a6bd042 100644 --- a/angular-file-upload/angular-file-upload.d.ts +++ b/angular-file-upload/angular-file-upload.d.ts @@ -9,7 +9,7 @@ declare module ng.angularFileUpload { interface IUploadService { - http(config: IFileUploadConfig): IUploadPromise; + http(config: ng.IRequestConfig): IUploadPromise; upload(config: IFileUploadConfig): IUploadPromise; } @@ -23,4 +23,4 @@ declare module ng.angularFileUpload { file: File; fileName?: string; } -} \ No newline at end of file +} diff --git a/angularjs/angular.d.ts b/angularjs/angular.d.ts index f9ebda120..d764bec6b 100755 --- a/angularjs/angular.d.ts +++ b/angularjs/angular.d.ts @@ -584,6 +584,44 @@ declare module ng { } interface IScope extends IRootScopeService { } + + /** + * $scope for ngRepeat directive. + * see https://docs.angularjs.org/api/ng/directive/ngRepeat + */ + interface IRepeatScope extends IScope { + + /** + * iterator offset of the repeated element (0..length-1). + */ + $index: number; + + /** + * true if the repeated element is first in the iterator. + */ + $first: boolean; + + /** + * true if the repeated element is between the first and last in the iterator. + */ + $middle: boolean; + + /** + * true if the repeated element is last in the iterator. + */ + $last: boolean; + + /** + * true if the iterator position $index is even (otherwise false). + */ + $even: boolean; + + /** + * true if the iterator position $index is odd (otherwise false). + */ + $odd: boolean; + + } interface IAngularEvent { /** diff --git a/big-integer/big-integer.d.ts b/big-integer/big-integer.d.ts index dfadc4962..633432e19 100644 --- a/big-integer/big-integer.d.ts +++ b/big-integer/big-integer.d.ts @@ -1,6 +1,6 @@ // Type definitions for BigInteger.js // Project: https://github.com/peterolson/BigInteger.js -// Definitions by: Ingo Bürk +// Definitions by: Ingo Bürk , Roel van Uden // Definitions: https://github.com/borisyankov/DefinitelyTyped interface BigInteger { @@ -167,6 +167,30 @@ interface BigInteger { /** Checks if two numbers are not equal. */ notEquals( number: string ): boolean; + /** Performs the bitwise AND operation. */ + and( number: number ): BigInteger; + /** Performs the bitwise AND operation. */ + and( number: BigInteger ): BigInteger; + /** Performs the bitwise AND operation. */ + and( number: string ): BigInteger; + + /** Performs the bitwise NOT operation. */ + not(): BigInteger; + + /** Performs the bitwise OR operation. */ + or( number: number ): BigInteger; + /** Performs the bitwise OR operation. */ + or( number: BigInteger ): BigInteger; + /** Performs the bitwise OR operation. */ + or( number: string ): BigInteger; + + /** Performs the bitwise XOR operation. */ + xor( number: number ): BigInteger; + /** Performs the bitwise XOR operation. */ + xor( number: BigInteger ): BigInteger; + /** Performs the bitwise XOR operation. */ + xor( number: string ): BigInteger; + /** Converts a bigInt into a native Javascript number. Loses precision for numbers outside the range. */ toJSNumber(): number; diff --git a/byline/byline-tests.ts b/byline/byline-tests.ts new file mode 100644 index 000000000..42de3d5d9 --- /dev/null +++ b/byline/byline-tests.ts @@ -0,0 +1,47 @@ +/** + * Created by stefansteinhart on 31.01.15. + */ + +/// + +import fs = require( 'fs' ); +import byline = require( 'byline' ); + +//TODO can this be typed in an ambient way? +//var stream = byline( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); + +var stream = byline.createStream( fs.createReadStream( 'sample.txt', {encoding: 'utf8'} ) ); + +stream.on('data', function(line:string) { + console.log(line); +}); + +stream = byline.createStream(stream); + +stream.on('data', function(line:string) { + console.log(line); +}); + +var input = fs.createReadStream('sample.txt'); +stream.pipe(fs.createWriteStream('nolines.txt')); + +var lineStream = byline.createStream(); +input.pipe(lineStream); + +var output = fs.createWriteStream('test.txt'); +lineStream.pipe(output); + +stream.on('readable', function() { + var line:string; + while (null !== (line = stream.read())) { + console.log(line); + } +}); + +var LineStream = require('byline').LineStream; + +var output = fs.createWriteStream('nolines.txt'); + +var lineStream:byline.LineStream = new LineStream(); +input.pipe(lineStream); +lineStream.pipe(output); \ No newline at end of file diff --git a/byline/byline.d.ts b/byline/byline.d.ts new file mode 100644 index 000000000..6dac6ad50 --- /dev/null +++ b/byline/byline.d.ts @@ -0,0 +1,38 @@ +// Type definitions for byline 4.2.1 +// Project: https://github.com/jahewson/node-byline +// Definitions by: Stefan Steinhart +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "byline" { + import stream = require("stream"); + + export interface LineStreamOptions extends stream.TransformOptions { + keepEmptyLines: boolean; + } + + export interface LineStream extends stream.Transform { + } + + export interface LineStreamCreatable extends LineStream { + new (options?:LineStreamOptions):LineStream + } + + //TODO is it possible to declare static factory functions without name (directly on the module) + // + // JS: + // // convinience API + // module.exports = function(readStream, options) { + // return module.exports.createStream(readStream, options); + // }; + // + // TS: + // ():LineStream; // same as createStream():LineStream + // (stream:stream.Stream, options?:LineStreamOptions):LineStream; // same as createStream(stream, options?):LineStream + + export function createStream():LineStream; + export function createStream(stream:NodeJS.ReadableStream, options?:LineStreamOptions):LineStream; + + export var LineStream:LineStreamCreatable; +} \ No newline at end of file diff --git a/chrome/chrome.d.ts b/chrome/chrome.d.ts index a41cfd843..b3b994930 100755 --- a/chrome/chrome.d.ts +++ b/chrome/chrome.d.ts @@ -21,8 +21,8 @@ declare module chrome.alarms { name: string; } - interface AlarmEvent extends chrome.events.Event { - addListener(callback: (alarm: Alarm) => void) : void; + interface AlarmEvent extends chrome.events.Event { + addListener(callback: (alarm: Alarm) => void): void; } export function create(alarmInfo: AlarmCreateInfo): void; @@ -32,7 +32,7 @@ declare module chrome.alarms { export function clear(name?: string): void; export function get(callback: (alarm: Alarm) => void): void; export function get(name: string, callback: (alarm: Alarm) => void): void; - + var onAlarm: AlarmEvent; } @@ -60,7 +60,7 @@ declare module chrome.bookmarks { index: number; oldIndex: number; parentId: string; - oldParentId: string; + oldParentId: string; } interface BookmarkChangeInfo { @@ -72,7 +72,7 @@ declare module chrome.bookmarks { childIds: string[]; } - interface BookmarkRemovedEvent extends chrome.events.Event { + interface BookmarkRemovedEvent extends chrome.events.Event { addListener(callback: (id: string, removeInfo: BookmarkRemoveInfo) => void): void; } @@ -227,10 +227,10 @@ declare module chrome.browsingData { // Commands //////////////////// declare module chrome.commands { - interface CommandEvent extends chrome.events.Event { + interface CommandEvent extends chrome.events.Event { addListener(callback: (command: string) => void): void; } - + var onCommand: CommandEvent; } @@ -471,7 +471,7 @@ declare module chrome.declarativeWebRequest { lowerPriorityThan: number; } - interface RedirectToEmptyDocument {} + interface RedirectToEmptyDocument { } interface RedirectRequest { redirectUrl: string; @@ -497,7 +497,7 @@ declare module chrome.declarativeWebRequest { modification: ResponseCookie; } - interface CancelRequest {} + interface CancelRequest { } interface RemoveRequestHeader { name: string; @@ -523,7 +523,7 @@ declare module chrome.declarativeWebRequest { from: string; } - interface RedirectToTransparentImage {} + interface RedirectToTransparentImage { } interface AddRequestCookie { cookie: RequestCookie; @@ -535,7 +535,7 @@ declare module chrome.declarativeWebRequest { interface RequestedEvent extends chrome.events.Event { addListener(callback: Function): void; - } + } var onRequest: RequestedEvent; } @@ -886,7 +886,7 @@ declare module chrome.fileBrowserHandler { interface FileHandlerExecuteEventDetails { tab_id?: number; entries: any[]; - selectFile(selectionParams: SelectionParams, callback:(result: SelectionResult) => void): void; + selectFile(selectionParams: SelectionParams, callback: (result: SelectionResult) => void): void; } interface FileBrowserHandlerExecuteEvent extends chrome.events.Event { @@ -1043,7 +1043,7 @@ declare module chrome.history { // Identity //////////////////// declare module chrome.identity { - var getAuthToken: (options:any, cb:(token:{})=>void)=>void; + var getAuthToken: (options: any, cb: (token: {}) => void) => void; } @@ -1533,7 +1533,7 @@ declare module chrome.runtime { arch: string; nacl_arch: string; } - + interface Port { postMessage: Function; sender?: MessageSender; @@ -1592,7 +1592,7 @@ declare module chrome.runtime { interface RuntimeUpdateAvailableEvent extends chrome.events.Event { addListener(callback: (details: UpdateAvailableDetails) => void): void; } - + export function connect(connectInfo?: ConnectInfo): Port; export function connect(extensionId: string, connectInfo?: ConnectInfo): Port; export function connectNative(application: string): Port; @@ -1608,7 +1608,7 @@ declare module chrome.runtime { export function sendMessage(message: any, options: MessageOptions, responseCallback?: (response: any) => void): void; export function sendMessage(extensionId: string, message: any, responseCallback?: (response: any) => void): void; export function sendMessage(extensionId: string, message: any, options: MessageOptions, responseCallback?: (response: any) => void): void; - export function sendNativeMessage(application: string, message: any, responseCallback?: (response: any) => void ): void; + export function sendNativeMessage(application: string, message: any, responseCallback?: (response: any) => void): void; export function setUninstallUrl(url: string): void; var onConnect: ExtensionConnectEvent; @@ -2095,88 +2095,59 @@ declare module chrome.webNavigation { interface GetAllFrameDetails { tabId: number; } - + interface GetAllFrameResultDetails extends GetFrameResultDetails { processId: number; frameId: number; } - interface ReferenceFragmentUpdatedDetails { - processId: number; + interface CallbackBasicDetails { tabId: number; - transitionType: string; - url: string; timeStamp: number; - frameId: number; - transitionQualifiers: string; } - interface CompletedDetails { + interface CallbackDetails extends CallbackBasicDetails { processId: number; - tabId: number; url: string; - timeStamp: number; frameId: number; } - interface HistoryStateUpdatedDetails { - processId: number; - tabId: number; + interface CallbackTransitionDetails extends CallbackDetails { transitionType: string; - url: string; - timeStamp: number; - frameId: number; transitionQualifiers: string[]; } - interface CreatedNavigationTargetDetails { - tabId: number; + interface ReferenceFragmentUpdatedDetails extends CallbackTransitionDetails { + } + + interface CompletedDetails extends CallbackDetails { + } + + interface HistoryStateUpdatedDetails extends CallbackTransitionDetails { + } + + interface CreatedNavigationTargetDetails extends CallbackBasicDetails { url: string; - timeStamp: number; sourceTabId: number; sourceProcessId: number; sourceFrameId: number; } - interface TabReplacedDetails { - tabId: number; + interface TabReplacedDetails extends CallbackBasicDetails { replacedTabId: number; - timeStamp: number; } - interface BeforeNavigateDetails { - processId: number; - tabId: number; - url: string; - timeStamp: number; - frameId: number; + interface BeforeNavigateDetails extends CallbackDetails { parentFrameId: number; } - interface CommittedDetails { - processId: number; - tabId: number; - transitionType: string; - url: string; - timeStamp: number; - frameId: number; - transitionQualifiers: string[]; + interface CommittedDetails extends CallbackTransitionDetails { } - interface DomContentLoadedDetails { - processId: number; - tabId: number; - url: string; - timeStamp: number; - frameId: number; + interface DomContentLoadedDetails extends CallbackDetails { } - interface ErrorOccurredDetails { - processId: number; - tabId: number; - url: string; - timeStamp: number; - frameId: number; + interface ErrorOccurredDetails extends CallbackDetails { error: string; } @@ -2185,11 +2156,11 @@ declare module chrome.webNavigation { } interface WebNavigationReferenceFragmentUpdatedEvent extends chrome.events.Event { - addListener(callback: (details: ReferenceFragmentUpdatedDetails) => void, filters? : WebNavigationEventFilters): void; + addListener(callback: (details: ReferenceFragmentUpdatedDetails) => void, filters?: WebNavigationEventFilters): void; } interface WebNavigationCompletedEvent extends chrome.events.Event { - addListener(callback: (details: CompletedDetails) => void, filters? : WebNavigationEventFilters): void; + addListener(callback: (details: CompletedDetails) => void, filters?: WebNavigationEventFilters): void; } interface WebNavigationHistoryStateUpdatedEvent extends chrome.events.Event { @@ -2222,7 +2193,7 @@ declare module chrome.webNavigation { export function getFrame(details: GetFrameDetails, callback: (details?: GetFrameResultDetails) => void): void; export function getAllFrames(details: GetAllFrameDetails, callback: (details?: GetAllFrameResultDetails[]) => void): void; - + var onReferenceFragmentUpdated: WebNavigationReferenceFragmentUpdatedEvent; var onCompleted: WebNavigationCompletedEvent; var onHistoryStateUpdated: WebNavigationHistoryStateUpdatedEvent; @@ -2242,13 +2213,13 @@ declare module chrome.webRequest { username: string; password: string; } - + interface HttpHeader { name: string; value?: string; binaryValue?: ArrayBuffer; } - + interface BlockingResponse { cancel?: boolean; redirectUrl?: string; @@ -2269,9 +2240,9 @@ declare module chrome.webRequest { file?: string; } - interface WebRequestCallbackDetails { + interface CallbackDetails { requestId: string; - url: string; + url: string; method: string; tabId: number; frameId: number; @@ -2280,20 +2251,20 @@ declare module chrome.webRequest { type: string; } - interface OnCompletedDetails extends WebRequestCallbackDetails { + interface OnCompletedDetails extends CallbackDetails { ip?: string; statusLine?: string; responseHeaders?: HttpHeader[]; - fromCache: boolean; + fromCache: boolean; statusCode: number; } - interface OnHeadersReceivedDetails extends WebRequestCallbackDetails { + interface OnHeadersReceivedDetails extends CallbackDetails { statusLine?: string; responseHeaders?: HttpHeader[]; } - interface OnBeforeRedirectDetails extends WebRequestCallbackDetails { + interface OnBeforeRedirectDetails extends CallbackDetails { ip?: string; statusLine?: string; responseHeaders?: HttpHeader[]; @@ -2307,7 +2278,7 @@ declare module chrome.webRequest { port: number; } - interface OnAuthRequiredDetails extends WebRequestCallbackDetails { + interface OnAuthRequiredDetails extends CallbackDetails { statusLine?: string; challenger: Challenger; responseHeaders?: HttpHeader[]; @@ -2316,17 +2287,17 @@ declare module chrome.webRequest { scheme: string; } - interface OnBeforeSendHeadersDetails extends WebRequestCallbackDetails { + interface OnBeforeSendHeadersDetails extends CallbackDetails { requestHeaders?: HttpHeader[]; } - interface OnErrorOccurredDetails extends WebRequestCallbackDetails { + interface OnErrorOccurredDetails extends CallbackDetails { ip?: string; fromCache: boolean; error: string; } - interface OnResponseStartedDetails extends WebRequestCallbackDetails { + interface OnResponseStartedDetails extends CallbackDetails { ip?: string; statusLine?: string; responseHeaders?: HttpHeader[]; @@ -2334,61 +2305,65 @@ declare module chrome.webRequest { statusCode: number; } - interface OnSendHeadersDetails extends WebRequestCallbackDetails { + interface OnSendHeadersDetails extends CallbackDetails { requestHeaders?: HttpHeader[]; } + interface FormData { + [key: string]: string[]; + } + interface RequestBody { raw?: UploadData; error?: string; - formData?: Object; + formData?: FormData; } - interface OnBeforeRequestDetails extends WebRequestCallbackDetails { + interface OnBeforeRequestDetails extends CallbackDetails { requestBody?: RequestBody; } - interface WebRequestCompletedEvent extends chrome.events.Event { + interface WebRequestCompletedEvent extends chrome.events.Event { addListener(callback: (details: OnCompletedDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnCompletedDetails) => BlockingResponse): void; } - interface WebRequestHeadersReceivedEvent extends chrome.events.Event { + interface WebRequestHeadersReceivedEvent extends chrome.events.Event { addListener(callback: (details: OnHeadersReceivedDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnHeadersReceivedDetails) => BlockingResponse): void; } - interface WebRequestBeforeRedirectEvent extends chrome.events.Event { + interface WebRequestBeforeRedirectEvent extends chrome.events.Event { addListener(callback: (details: OnBeforeRedirectDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnBeforeRedirectDetails) => BlockingResponse): void; } - interface WebRequestAuthRequiredEvent extends chrome.events.Event { + interface WebRequestAuthRequiredEvent extends chrome.events.Event { addListener(callback: (details: OnAuthRequiredDetails, callback?: (response: BlockingResponse) => void) => void, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnAuthRequiredDetails, callback?: (response: BlockingResponse) => void) => void): void; } - interface WebRequestBeforeSendHeadersEvent extends chrome.events.Event { + interface WebRequestBeforeSendHeadersEvent extends chrome.events.Event { addListener(callback: (details: OnBeforeSendHeadersDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnBeforeSendHeadersDetails) => BlockingResponse): void; } - interface WebRequestErrorOccurredEvent extends chrome.events.Event { + interface WebRequestErrorOccurredEvent extends chrome.events.Event { addListener(callback: (details: OnErrorOccurredDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnErrorOccurredDetails) => BlockingResponse): void; } - interface WebRequestResponseStartedEvent extends chrome.events.Event { + interface WebRequestResponseStartedEvent extends chrome.events.Event { addListener(callback: (details: OnResponseStartedDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnResponseStartedDetails) => BlockingResponse): void; } - interface WebRequestSendHeadersEvent extends chrome.events.Event { + interface WebRequestSendHeadersEvent extends chrome.events.Event { addListener(callback: (details: OnSendHeadersDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnSendHeadersDetails) => BlockingResponse): void; } - interface WebRequestBeforeRequestEvent extends chrome.events.Event { + interface WebRequestBeforeRequestEvent extends chrome.events.Event { addListener(callback: (details: OnBeforeRequestDetails) => BlockingResponse, filter?: RequestFilter, opt_extraInfoSpec?: string[]): void; removeListener(callback: (details: OnBeforeRequestDetails) => BlockingResponse): void; } @@ -2396,7 +2371,7 @@ declare module chrome.webRequest { var MAX_HANDLER_BEHAVIOR_CHANGED_CALLS_PER_10_MINUTES: number; export function handlerBehaviorChanged(callback?: Function): void; - + var onCompleted: WebRequestCompletedEvent; var onHeadersReceived: WebRequestHeadersReceivedEvent; var onBeforeRedirect: WebRequestBeforeRedirectEvent; diff --git a/event-loop-lag/event-loop-lag-tests.ts b/event-loop-lag/event-loop-lag-tests.ts new file mode 100644 index 000000000..8e20879af --- /dev/null +++ b/event-loop-lag/event-loop-lag-tests.ts @@ -0,0 +1,6 @@ +/// + +import lag = require("event-loop-lag"); + +var fn: () => number = lag(1000); +var n: number = fn(); diff --git a/event-loop-lag/event-loop-lag.d.ts b/event-loop-lag/event-loop-lag.d.ts new file mode 100644 index 000000000..199babd37 --- /dev/null +++ b/event-loop-lag/event-loop-lag.d.ts @@ -0,0 +1,14 @@ +// Type definitions for event-loop-lag 1.0.3 +// Project: https://github.com/pebble/event-loop-lag +// Definitions by: Rogier Schouten +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "event-loop-lag" { + + /** + * Accepts a number of milliseconds representing how often to refresh the event loop lag measurement and returns a function you can call to receive the latest lag measurement in milliseconds. + */ + function lag(interval: number): () => number; + + export = lag; +} diff --git a/i18next/i18next.d.ts b/i18next/i18next.d.ts index 512b3fdd4..3463f2426 100644 --- a/i18next/i18next.d.ts +++ b/i18next/i18next.d.ts @@ -127,3 +127,7 @@ interface JQuery { } declare var i18n: I18nextStatic; + +declare module 'i18next' { + export = i18n; +} \ No newline at end of file diff --git a/iban/iban.d.ts b/iban/iban.d.ts index b39f5908c..6a7bd803d 100644 --- a/iban/iban.d.ts +++ b/iban/iban.d.ts @@ -3,58 +3,56 @@ // Definitions by: Cyril Schumacher // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module ARHS { +/** + * @summary Interface for {@link IBAN} object. + * @author Cyril Schumacher + * @version 1.0 + */ +interface IBANStatic { /** - * @summary Interface for {@link IBAN} object. - * @author Cyril Schumacher - * @version 1.0 + * @summary Returns the IBAN in a electronic format. + * @param {string} iban The IBAN to convert. + * @param {string} The IBAN in electronic format. */ - interface IBANStatic { - /** - * @summary Returns the IBAN in a electronic format. - * @param {string} iban The IBAN to convert. - * @param {string} The IBAN in electronic format. - */ - electronicFormat(iban: string): string; + electronicFormat(iban: string): string; - /** - * @summary Convert the passed BBAN to an IBAN for this country specification. - * @param {string} countryCode The country of the BBAN. - * @param {string} bban The BBAN to convert to IBAN. - * @returns {string} The IBAN. - */ - fromBBAN(countryCode: string, bban: string): string; + /** + * @summary Convert the passed BBAN to an IBAN for this country specification. + * @param {string} countryCode The country of the BBAN. + * @param {string} bban The BBAN to convert to IBAN. + * @returns {string} The IBAN. + */ + fromBBAN(countryCode: string, bban: string): string; - /** - * @summary Check if the passed iban is valid according to this specification. - * @param {string} iban The iban to validate. - * @returns {boolean} True if valid, false otherwise. - */ - isValid(iban: string): boolean; + /** + * @summary Check if the passed iban is valid according to this specification. + * @param {string} iban The iban to validate. + * @returns {boolean} True if valid, false otherwise. + */ + isValid(iban: string): boolean; - /** - * @summary Check of the passed BBAN is valid. - * @param {string} countryCode The country of the BBAN. - * @param {string} bban The BBAN to validate. - * @returns {boolean} True if valid, false otherwise. - */ - isValidBBAN(countryCode: string, bban: string): boolean; + /** + * @summary Check of the passed BBAN is valid. + * @param {string} countryCode The country of the BBAN. + * @param {string} bban The BBAN to validate. + * @returns {boolean} True if valid, false otherwise. + */ + isValidBBAN(countryCode: string, bban: string): boolean; - /** - * @summary Returns the IBAN in a print format. - * @param {string} iban The IBAN to convert. - * @param {string} The IBAN in print format. - */ - printFormat(iban: string, separator: string[]): string; + /** + * @summary Returns the IBAN in a print format. + * @param {string} iban The IBAN to convert. + * @param {string} The IBAN in print format. + */ + printFormat(iban: string, separator: string[]): string; - /** - * @summary Convert the passed IBAN to a country-specific BBAN. - * @param {string} iban The IBAN to convert. - * @param {string[]} Separator the separator to use between BBAN blocks. - * @returns {string} The BBAN - */ - toBBAN(iban: string, separator: string[]): string; - } + /** + * @summary Convert the passed IBAN to a country-specific BBAN. + * @param {string} iban The IBAN to convert. + * @param {string[]} Separator the separator to use between BBAN blocks. + * @returns {string} The BBAN + */ + toBBAN(iban: string, separator: string[]): string; } -declare var IBAN: ARHS.IBANStatic; \ No newline at end of file +declare var IBAN: IBANStatic; \ No newline at end of file diff --git a/java-applet/java-applet-tests.ts b/java-applet/java-applet-tests.ts new file mode 100644 index 000000000..670527999 --- /dev/null +++ b/java-applet/java-applet-tests.ts @@ -0,0 +1,22 @@ +/// + +/** + * @summary Test for the applet status. + */ +function testStatus() { + var java: Java = { + status: AppletStatus.Loading + }; +} + +/** + * @summary Test for the handlers. + */ +function testHandlers() { + var handler: Function = () => {}; + var java: Java = { + onError: handler, + onLoad: handler, + onStop: handler + }; +} diff --git a/java-applet/java-applet-tests.ts.tscparams b/java-applet/java-applet-tests.ts.tscparams new file mode 100644 index 000000000..934bc29ef --- /dev/null +++ b/java-applet/java-applet-tests.ts.tscparams @@ -0,0 +1 @@ +--noImplicitAny \ No newline at end of file diff --git a/java-applet/java-applet.d.ts b/java-applet/java-applet.d.ts new file mode 100644 index 000000000..0102b3b75 --- /dev/null +++ b/java-applet/java-applet.d.ts @@ -0,0 +1,52 @@ +// Type definitions for Java Applet +// Project: https://www.java.com/ +// Definitions by: Cyril Schumacher +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** + * @summary Applet Status. + * {@link http://docs.oracle.com/javase/8/docs/technotes/guides/deploy/applet_dev_guide.html#JSDPG719|Applet Status And Event Handlers} + */ +declare enum AppletStatus { + /** + * @summary Applet is loading. + */ + Loading = 1, + + /** + * @summary Applet has loaded completely and is ready to receive JavaScript calls. + */ + Ready = 2, + + /** + * @summary Error while loading applet. + */ + Error = 3 +} + +/** + * @summary Interface for Java object. + * @author Cyril Schumacher + * @version 1.0 + */ +interface Java { + /** + * Handler if the applet status is ERROR. An error has occurred while loading the applet. + */ + onError?: Function; + + /** + * Handler if the applet status is READY. Applet has finished loading and is ready to receive JavaScript calls. + */ + onLoad?: Function; + + /** + * Handler if the applet has stopped. + */ + onStop?: Function; + + /** + * @summary Applet Status. + */ + status?: AppletStatus; +} diff --git a/jquery.validation/jquery.validation-tests.ts b/jquery.validation/jquery.validation-tests.ts index fcc22d296..5a6a10770 100644 --- a/jquery.validation/jquery.validation-tests.ts +++ b/jquery.validation/jquery.validation-tests.ts @@ -187,6 +187,7 @@ function test_methods() { }); $("#myform").validate().form(); $("#myform").validate().element("#myselect"); + $("#myform").validate().element($("#myselect")); var validator = $("#myform").validate(); validator.resetForm(); validator.showErrors({ "firstname": "I know that your firstname is Pete, Pete!" }); diff --git a/jquery.validation/jquery.validation.d.ts b/jquery.validation/jquery.validation.d.ts index f8b6ca70c..118b19ef6 100644 --- a/jquery.validation/jquery.validation.d.ts +++ b/jquery.validation/jquery.validation.d.ts @@ -186,7 +186,7 @@ interface Validator * * @param element An element to validate, must be inside the validated form. eg "#myselect" */ - element(element: string): boolean; + element(element: string|JQuery): boolean; /** * Validates the form, returns true if it is valid, false otherwise. */ diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index f53bb07a9..b82711120 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -287,8 +287,8 @@ interface JQueryPromiseCallback { } interface JQueryPromiseOperator { - (callback: JQueryPromiseCallback, ...callbacks: JQueryPromiseCallback[]): JQueryPromise; - (callback: JQueryPromiseCallback[], ...callbacks: JQueryPromiseCallback[]): JQueryPromise; + (callback: JQueryPromiseCallback, ...callbacks: JQueryPromiseCallback[]): JQueryPromise; + (callback: JQueryPromiseCallback[], ...callbacks: JQueryPromiseCallback[]): JQueryPromise; } /** @@ -301,28 +301,28 @@ interface JQueryPromise { * @param alwaysCallbacks1 A function, or array of functions, that is called when the Deferred is resolved or rejected. * @param alwaysCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved or rejected. */ - always: JQueryPromiseOperator; + always: JQueryPromiseOperator; /** * Add handlers to be called when the Deferred object is resolved. * * @param doneCallbacks1 A function, or array of functions, that are called when the Deferred is resolved. * @param doneCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is resolved. */ - done: JQueryPromiseOperator; + done: JQueryPromiseOperator; /** * Add handlers to be called when the Deferred object is rejected. * * @param failCallbacks1 A function, or array of functions, that are called when the Deferred is rejected. * @param failCallbacks2 Optional additional functions, or arrays of functions, that are called when the Deferred is rejected. */ - fail: JQueryPromiseOperator; + fail: JQueryPromiseOperator; /** * Add handlers to be called when the Deferred object generates progress notifications. * * @param progressCallbacks A function, or array of functions, to be called when the Deferred generates progress notifications. */ - progress(progressCallback: JQueryPromiseCallback): JQueryPromise; - progress(progressCallbacks: JQueryPromiseCallback[]): JQueryPromise; + progress(progressCallback: JQueryPromiseCallback): JQueryPromise; + progress(progressCallbacks: JQueryPromiseCallback[]): JQueryPromise; /** * Determine the current state of a Deferred object. @@ -393,7 +393,7 @@ interface JQueryDeferred extends JQueryPromise { */ progress(progressCallback: JQueryPromiseCallback): JQueryDeferred; progress(progressCallbacks: JQueryPromiseCallback[]): JQueryDeferred; - + /** * Call the progressCallbacks on a Deferred object with the given args. * @@ -1259,7 +1259,7 @@ interface JQuery { * @param attributeName The name of the attribute to set. * @param func A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old attribute value as arguments. */ - attr(attributeName: string, func: (index: number, attr: any) => any): JQuery; + attr(attributeName: string, func: (index: number, attr: string) => string|number): JQuery; /** * Set one or more attributes for the set of matched elements. * @@ -1481,12 +1481,12 @@ interface JQuery { */ outerHeight(includeMargin?: boolean): number; - /** - * Sets the outer height on elements in the set of matched elements, including padding and border. - * - * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). - */ - outerHeight(height: number|string): JQuery; + /** + * Sets the outer height on elements in the set of matched elements, including padding and border. + * + * @param value An integer representing the number of pixels, or an integer along with an optional unit of measure appended (as a string). + */ + outerHeight(height: number|string): JQuery; /** * Get the current computed width for the first element in the set of matched elements, including padding and border. @@ -2587,7 +2587,7 @@ interface JQuery { * * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert after each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. */ - after(func: (index: number) => any): JQuery; + after(func: (index: number, html: string) => string|Element|JQuery): JQuery; /** * Insert content, specified by the parameter, to the end of each element in the set of matched elements. @@ -2601,7 +2601,7 @@ interface JQuery { * * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert at the end of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set. */ - append(func: (index: number, html: string) => any): JQuery; + append(func: (index: number, html: string) => string|Element|JQuery): JQuery; /** * Insert every element in the set of matched elements to the end of the target. @@ -2622,7 +2622,7 @@ interface JQuery { * * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert before each element in the set of matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. */ - before(func: (index: number) => any): JQuery; + before(func: (index: number, html: string) => string|Element|JQuery): JQuery; /** * Create a deep copy of the set of matched elements. @@ -2670,7 +2670,7 @@ interface JQuery { * * param func A function that returns an HTML string, DOM element(s), or jQuery object to insert at the beginning of each element in the set of matched elements. Receives the index position of the element in the set and the old HTML value of the element as arguments. Within the function, this refers to the current element in the set. */ - prepend(func: (index: number, html: string) => any): JQuery; + prepend(func: (index: number, html: string) => string|Element|JQuery): JQuery; /** * Insert every element in the set of matched elements to the beginning of the target. @@ -2704,7 +2704,7 @@ interface JQuery { * * param func A function that returns content with which to replace the set of matched elements. */ - replaceWith(func: () => any): JQuery; + replaceWith(func: () => Element|JQuery): JQuery; /** * Get the combined text contents of each element in the set of matched elements, including their descendants. @@ -2744,7 +2744,7 @@ interface JQuery { * * @param func A callback function returning the HTML content or jQuery object to wrap around the matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. */ - wrap(func: (index: number) => any): JQuery; + wrap(func: (index: number) => string|JQuery): JQuery; /** * Wrap an HTML structure around all elements in the set of matched elements. @@ -2752,6 +2752,7 @@ interface JQuery { * @param wrappingElement A selector, element, HTML string, or jQuery object specifying the structure to wrap around the matched elements. */ wrapAll(wrappingElement: JQuery|Element|string): JQuery; + wrapAll(func: (index: number) => string): JQuery; /** * Wrap an HTML structure around the content of each element in the set of matched elements. @@ -2764,7 +2765,7 @@ interface JQuery { * * @param func A callback function which generates a structure to wrap around the content of the matched elements. Receives the index position of the element in the set as an argument. Within the function, this refers to the current element in the set. */ - wrapInner(func: (index: number) => any): JQuery; + wrapInner(func: (index: number) => string): JQuery; /** * Iterate over a jQuery object, executing a function for each matched element. @@ -2965,7 +2966,7 @@ interface JQuery { * * @param func A function used as a test for the set of elements. It accepts one argument, index, which is the element's index in the jQuery collection.Within the function, this refers to the current DOM element. */ - is(func: (index: number) => any): boolean; + is(func: (index: number, element: Element) => boolean): boolean; /** * Check the current matched set of elements against a selector, element, or jQuery object and return true if at least one of these elements matches the given arguments. * @@ -3038,7 +3039,7 @@ interface JQuery { * * @param func A function used as a test for each element in the set. this is the current DOM element. */ - not(func: (index: number) => any): JQuery; + not(func: (index: number, element: Element) => boolean): JQuery; /** * Remove elements from the set of matched elements. * diff --git a/kolite/kolite.d.ts b/kolite/kolite.d.ts index 6310fcad4..c9535411b 100644 --- a/kolite/kolite.d.ts +++ b/kolite/kolite.d.ts @@ -63,13 +63,13 @@ interface KoliteAsyncCommand extends KoliteCommand { } interface KoLiteCommandOptions { - execute?: any; + execute(...args: any[]): any; canExecute?: (isExecuting: boolean) => any; } interface KnockoutStatic { command(options: KoLiteCommandOptions): KoliteCommand; - asyncCommand(optons: KoLiteCommandOptions): KoliteAsyncCommand; + asyncCommand(options: KoLiteCommandOptions): KoliteAsyncCommand; } interface KnockoutUtils { diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 6085375c2..c8f7ad42d 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -2641,6 +2641,15 @@ declare module _ { whereValue: W): LoDashArrayWrapper; } + interface LoDashObjectWrapper { + /** + * @see _.filter + **/ + filter( + callback: ObjectIterator, + thisArg?: any): LoDashObjectWrapper; + } + //_.find interface LoDashStatic { /** diff --git a/mdns/mdns-tests.ts b/mdns/mdns-tests.ts new file mode 100644 index 000000000..20a336025 --- /dev/null +++ b/mdns/mdns-tests.ts @@ -0,0 +1,84 @@ +/** + * Created by stefansteinhart on 30.01.15. + */ + +/// + +var mdns = require('mdns') + +var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321); + +ad.start(); + +var browser = mdns.createBrowser(mdns.tcp('http')); + +browser.on('serviceUp', function(service:MDNS.Service) { + console.log("service up: ", service); +}); +browser.on('serviceDown', function(service:MDNS.Service) { + console.log("service down: ", service); +}); + +browser.start(); + +var r0 = mdns.tcp('http') // string form: _http._tcp + , r1 = mdns.udp('osc', 'api-v1') // string form: _osc._udp,_api-v1 + , r2 = new mdns.ServiceType('http', 'tcp') // string form: _http._tcp + , r3 = mdns.makeServiceType('https', 'tcp') // string form: _https._tcp + ; + +var txt_record = { + name: 'bacon' + , chunky: true + , strips: 5 +}; +var ad:MDNS.Advertisement = mdns.createAdvertisement(mdns.tcp('http'), 4321, {txtRecord: txt_record}); + +var sequence = [ + mdns.rst.DNSServiceResolve() + , mdns.rst.DNSServiceGetAddrInfo({families: [4] }) +]; + +var browser = mdns.createBrowser(mdns.tcp('http'), {resolverSequence: sequence}); + +interface HammerTimeService extends MDNS.Service { + hammerTime:Date; +} + +function MCHammer(options:any) { + options = options || {}; + return function MCHammer(service:HammerTimeService, next:()=>void) { + console.log('STOP!'); + setTimeout(function() { + console.log('hammertime...'); + service.hammerTime = new Date(); + next(); + }, options.delay || 1000); + } +} + +var browser = mdns.createBrowser( mdns.tcp('http') + , { networkInterface: mdns.loopbackInterface()}); + +var ad:MDNS.Advertisement; + +function createAdvertisement() { + try { + ad = mdns.createAdvertisement(mdns.tcp('http'), 1337); + ad.on('error', handleError); + ad.start(); + } catch (ex) { + handleError(ex); + } +} + +function handleError(error:MDNS.DnsSdError) { + switch (error.errorCode) { + case mdns.kDNSServiceErr_Unknown: + console.warn(error); + setTimeout(createAdvertisement, 5000); + break; + default: + throw error; + } +} \ No newline at end of file diff --git a/mdns/mdns.d.ts b/mdns/mdns.d.ts new file mode 100755 index 000000000..032d7c5af --- /dev/null +++ b/mdns/mdns.d.ts @@ -0,0 +1,295 @@ +// Type definitions for node_mdns +// Project: https://github.com/agnat/node_mdns +// Definitions by: Stefan Steinhart +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module MDNS { + + // --- Error --- + + interface DnsSdError extends Error { + errorCode?:number; + } + + // --- Ads --- + + interface AdvertisementOptions { + name?:string; + interfaceIndex?:number; + networkInterface?:string; + txtRecord?:any; + host?:any; + domain?:any; + flags?:any; + context?:any; + } + + interface AdvertisementCreatable { + new(serviceType:ServiceType, port:number, options?:AdvertisementOptions, callback?:(error:DnsSdError, service:Service)=>void):Advertisement; + } + + interface Advertisement extends NodeJS.EventEmitter { + start():void; + stop():void; + } + + // --- Browser --- + + interface BrowserOptions { + resolverSequence?:Array<(service:Service, next:()=>void)=>boolean>; + interfaceIndex?:number; + networkInterface?:string; + domain?:any; + context?:any; + flags?:any; + } + + interface Browser extends NodeJS.EventEmitter { + start():any; + stop():any; + } + + interface BrowserStatic { + new(serviceType:ServiceType, options?:BrowserOptions):Browser; + defaultResolverSequence:Array<(service:Service, next:()=>void)=>boolean> + } + + // --- Services --- + + interface Service { + addresses:Array; + flags:number; + fullname:string; + host:string; + interfaceIndex: number; + name?:string; + networkInterface:string; + port:number; + replyDomain:string; + type:ServiceType; + } + + interface ServiceType { + new(serviceTypeIdentifier:string):ServiceType; + new(name:string, protocol:string, ...subtypes:string[]):ServiceType; + new(serviceTypeIdentifier:Array):ServiceType; + new(serviceTypeIdentifier:{name:string; protocol:string; subtypes?:Array}):ServiceType; + new(serviceType:ServiceType):ServiceType; + + fullyQualified:boolean; + name:string; + protocol:string; + subtypes:Array; + + toString():string; + fromString(serviceTypeIdentifier:string):ServiceType; + + toArray():Array; + fromArray(serviceTypeIdentifier:Array):ServiceType; + + fromJSON(serviceTypeIdentifier:{name:string; protocol:string; subtypes?:Array}):ServiceType; + fromJSON(serviceType:ServiceType):ServiceType; + } + + // interface for extending with custom resolvers + interface MDNSResolverSequenceTasks { + + } + + interface DefaultResolverSequenceTasks extends MDNSResolverSequenceTasks { + DNSServiceResolve(options?:{flags:any}):(service:Service, next:()=>void)=>boolean; + DNSServiceGetAddrInfo(options?:any):(service:Service, next:()=>void)=>boolean; + getaddrinfo(options?:any):(service:Service, next:()=>void)=>boolean; + makeAddressesUnique():(service:Service, next:()=>void)=>boolean; + filterAddresses(fn:(address:string, index?:number, addresses?:Array)=>boolean):void; + logService():void; + } + + // --- Statics & Classes --- + + var Advertisement:AdvertisementCreatable; + var Browser:BrowserStatic; + var ServiceType:ServiceType; + var rst:DefaultResolverSequenceTasks; + + // static functions + + function tcp(name:string, ...subtypes:string[]):ServiceType; + + function udp(name:string, ...subtypes:string[]):ServiceType; + + function makeServiceType(name:string, protocol:string, ...subtypes:string[]):ServiceType; + + function makeServiceType(serviceTypeIdentifier:string):ServiceType; + + function makeServiceType(serviceTypeIdentifier:Array):ServiceType; + + function makeServiceType(serviceTypeIdentifier:{name:string; protocol:string; subtypes?:Array}):ServiceType; + + function makeServiceType(serviceType:ServiceType):ServiceType; + + function createBrowser(serviceType:ServiceType, options?:BrowserOptions):Browser; + + function createAdvertisement(serviceType:ServiceType, port:number, options?:AdvertisementOptions, callback?:(error:DnsSdError, service:Service)=>void):Advertisement; + + function resolve(service:Service, sequence?:Array<(service:Service, next:()=>void)=>boolean>, callback?:(error:DnsSdError, service:Service)=>void):void; + + function browseThemAll(options:BrowserOptions):Browser; + + function loopbackInterface():any; + + // constants + + var isAvahi:boolean; + + // -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- -------------------- + + //Constants from dns_sd.h (C-Code of Bonjour -> see https://developer.apple.com/library/mac/documentation/Networking/Reference/DNSServiceDiscovery_CRef/Reference/reference.html) + + var _DNS_SD_H:number; + + var kDNSServiceMaxDomainName:string; + var kDNSServiceMaxServiceName:number; + var kDNSServiceOutputFlags:any; + var kDNSServiceProperty_DaemonVersion:number; + + var kDNSServiceClass_IN:number; + + var kDNSServiceErr_NoError:number; + var kDNSServiceErr_Unknown:number; + var kDNSServiceErr_NoSuchName:number; + var kDNSServiceErr_NoMemory:number; + var kDNSServiceErr_BadParam:number; + var kDNSServiceErr_BadReference:number; + var kDNSServiceErr_BadState:number; + var kDNSServiceErr_BadFlags:number; + var kDNSServiceErr_Unsupported:number; + var kDNSServiceErr_NotInitialized:number; + var kDNSServiceErr_AlreadyRegistered:number; + var kDNSServiceErr_NameConflict:number; + var kDNSServiceErr_Invalid:number; + var kDNSServiceErr_Firewall:number; + var kDNSServiceErr_Incompatible:number; + var kDNSServiceErr_BadInterfaceIndex:number; + var kDNSServiceErr_Refused:number; + var kDNSServiceErr_NoSuchRecord:number; + var kDNSServiceErr_NoAuth:number; + var kDNSServiceErr_NoSuchKey:number; + var kDNSServiceErr_NATTraversal:number; + var kDNSServiceErr_DoubleNAT:number; + var kDNSServiceErr_BadTime:number; + var kDNSServiceErr_BadSig:number; + var kDNSServiceErr_BadKey:number; + var kDNSServiceErr_Transient:number; + var kDNSServiceErr_ServiceNotRunning:number; + var kDNSServiceErr_NATPortMappingUnsupported:number; + var kDNSServiceErr_NATPortMappingDisabled:number; + var kDNSServiceErr_NoRouter:number; + var kDNSServiceErr_PollingMode:number; + var kDNSServiceErr_Timeout:number; + + var kDNSServiceType_A:number; + var kDNSServiceType_NS:number; + var kDNSServiceType_MD:number; + var kDNSServiceType_MF:number; + var kDNSServiceType_CNAME:number; + var kDNSServiceType_SOA:number; + var kDNSServiceType_MB:number; + var kDNSServiceType_MG:number; + var kDNSServiceType_MR:number; + var kDNSServiceType_NULL:number; + var kDNSServiceType_WKS:number; + var kDNSServiceType_PTR:number; + var kDNSServiceType_HINFO:number; + var kDNSServiceType_MINFO:number; + var kDNSServiceType_MX:number; + var kDNSServiceType_TXT:number; + var kDNSServiceType_RP:number; + var kDNSServiceType_AFSDB:number; + var kDNSServiceType_X25:number; + var kDNSServiceType_ISDN:number; + var kDNSServiceType_RT:number; + var kDNSServiceType_NSAP:number; + var kDNSServiceType_NSAP_PTR:number; + var kDNSServiceType_SIG:number; + var kDNSServiceType_KEY:number; + var kDNSServiceType_PX:number; + var kDNSServiceType_GPOS:number; + var kDNSServiceType_AAAA:number; + var kDNSServiceType_LOC:number; + var kDNSServiceType_NXT:number; + var kDNSServiceType_EID:number; + var kDNSServiceType_NIMLOC:number; + var kDNSServiceType_SRV:number; + var kDNSServiceType_ATMA:number; + var kDNSServiceType_NAPTR:number; + var kDNSServiceType_KX:number; + var kDNSServiceType_CERT:number; + var kDNSServiceType_A6:number; + var kDNSServiceType_DNAME:number; + var kDNSServiceType_SINK:number; + var kDNSServiceType_OPT:number; + var kDNSServiceType_APL:number; + var kDNSServiceType_DS:number; + var kDNSServiceType_SSHFP:number; + var kDNSServiceType_IPSECKEY:number; + var kDNSServiceType_RRSIG:number; + var kDNSServiceType_NSEC:number; + var kDNSServiceType_DNSKEY:number; + var kDNSServiceType_DHCID:number; + var kDNSServiceType_NSEC3:number; + var kDNSServiceType_NSEC3PARAM:number; + var kDNSServiceType_HIP:number; + var kDNSServiceType_SPF:number; + var kDNSServiceType_UINFO:number; + var kDNSServiceType_UID:number; + var kDNSServiceType_GID:number; + var kDNSServiceType_UNSPEC:number; + var kDNSServiceType_TKEY:number; + var kDNSServiceType_TSIG:number; + var kDNSServiceType_IXFR:number; + var kDNSServiceType_AXFR:number; + var kDNSServiceType_MAILB:number; + var kDNSServiceType_MAILA:number; + var kDNSServiceType_ANY:number; + + var kDNSServiceFlagsMoreComing:number; + var kDNSServiceFlagsAdd:number; + var kDNSServiceFlagsDefault:number; + var kDNSServiceFlagsNoAutoRename:number; + var kDNSServiceFlagsShared:number; + var kDNSServiceFlagsUnique:number; + var kDNSServiceFlagsBrowseDomains:number; + var kDNSServiceFlagsRegistrationDomains:number; + var kDNSServiceFlagsLongLivedQuery:number; + var kDNSServiceFlagsAllowRemoteQuery:number; + var kDNSServiceFlagsForceMulticast:number; + var kDNSServiceFlagsKnownUnique:number; + var kDNSServiceFlagsReturnIntermediates:number; + var kDNSServiceFlagsNonBrowsable:number; + var kDNSServiceFlagsShareConnection:number; + var kDNSServiceFlagsSuppressUnusable:number; + var kDNSServiceFlagsWakeOnResolve:number; + var kDNSServiceFlagsBackgroundTrafficClass:number; + var kDNSServiceFlagsIncludeAWDL:number; + var kDNSServiceFlagsValidate:number; + var kDNSServiceFlagsSecure:number; + var kDNSServiceFlagsInsecure:number; + var kDNSServiceFlagsBogus:number; + var kDNSServiceFlagsIndeterminate:number; + var kDNSServiceFlagsUnicastResponse:number; + var kDNSServiceFlagsValidateOptional:number; + var kDNSServiceFlagsWakeOnlyService:number; + + var kDNSServiceProtocol_IPv4:number; + var kDNSServiceProtocol_IPv6:number; + var kDNSServiceProtocol_UDP:number; + var kDNSServiceProtocol_TCP:number; +} + +declare module "mdns" { + + export = MDNS; +} \ No newline at end of file diff --git a/meteor/meteor-tests.ts b/meteor/meteor-tests.ts index 23dbff736..e4c5b9066 100644 --- a/meteor/meteor-tests.ts +++ b/meteor/meteor-tests.ts @@ -98,7 +98,7 @@ Tracker.autorun(function () { }); console.log("Current room has " + - Counts.findOne(Session.get("roomId")).count + + Counts.find(Session.get("roomId")).count + " messages."); /** @@ -144,8 +144,15 @@ var result = Meteor.call('foo', 1, 2); * From Collections, Mongo.Collection section */ // DA: I added the "var" keyword in there -var Chatrooms = new Mongo.Collection("chatrooms"); -Messages = new Mongo.Collection("messages"); + +interface ChatroomsDAO { + _id?: string; +} +interface MessagesDAO { + _id?: string; +} +var Chatrooms = new Mongo.Collection("chatrooms"); +Messages = new Mongo.Collection("messages"); var myMessages = Messages.find({userId: Session.get('myUserId')}).fetch(); diff --git a/meteor/meteor.d.ts b/meteor/meteor.d.ts index 50386a916..e64547096 100644 --- a/meteor/meteor.d.ts +++ b/meteor/meteor.d.ts @@ -8,8 +8,9 @@ */ interface EJSON extends JSON {} -interface Template { - [templateName: string]: Meteor.Template; +interface TemplateStatic { + new(): Template; + [templateName: string]: Meteor.TemplatePage; } declare module Match { @@ -61,12 +62,7 @@ declare module Meteor { [id:string]:Meteor.EventHandlerFunction; } - // Same definition as top-level Template Interface - interface TemplateBase { - [templateName: string]: Meteor.Template; - } - - interface Template { + interface TemplatePage { rendered: Function; created: Function; destroyed: Function; @@ -326,12 +322,15 @@ declare module Blaze { function getData(elementOrView?: HTMLElement | Blaze.View): Object; function getView(element?: HTMLElement): Blaze.View; function Template(viewName?: string, renderFunction?: Function): void; + interface Template{ + } + function TemplateInstance(view: Blaze.View): void; - interface TemplateInstance { - data(): Object; - view(): Object; - firstNode(): Object; - lastNode(): Object; + interface TemplateInstance{ + data: Object; + view: Object; + firstNode: Object; + lastNode: Object; $(selector: string): Node[]; findAll(selector: string): HTMLElement[]; find(selector?: string): HTMLElement; @@ -339,6 +338,9 @@ declare module Blaze { } function View(name?: string, renderFunction?: Function): void; + interface View{ + } + } declare module Match { @@ -365,8 +367,8 @@ declare module EJSON { }): boolean; function clone(val:T): T; function CustomType(): void; - interface CustomType { - typeName(): string; + interface CustomType{ + typeName(): string; toJSONValue(): JSON; clone(): EJSON.CustomType; equals(other: Object): boolean; @@ -418,6 +420,9 @@ declare module Meteor { rootUrl?: string; }): string; function Error(error: string, reason?: string, details?: string): void; + interface Error{ + } + } declare module Mongo { @@ -426,8 +431,8 @@ declare module Mongo { idGeneration?: string; transform?: Function; }): void; - interface Collection { - insert(doc: Object, callback?: Function): string; + interface Collection{ + insert(doc: Object, callback?: Function): string; update(selector: Mongo.Selector, modifier: Mongo.Modifier, options?: { multi?: boolean; upsert?: Boolean; @@ -468,9 +473,12 @@ declare module Mongo { } function ObjectID(hexString: string): void; + interface ObjectID{ + } + function Cursor(): void; - interface Cursor { - forEach(callback: Function, thisArg?: any): void; + interface Cursor{ + forEach(callback: Function, thisArg?: any): void; map(callback: Function, thisArg?: any): void; fetch(): Array; count(): number; @@ -484,10 +492,10 @@ declare module Tracker { var active: boolean; var currentComputation: Tracker.Computation; function Computation(): void; - interface Computation { - stopped(): boolean; - invalidated(): boolean; - firstRun(): boolean; + interface Computation{ + stopped: boolean; + invalidated: boolean; + firstRun: boolean; onInvalidate(callback: Function): void; invalidate(): void; stop(): void; @@ -499,8 +507,8 @@ declare module Tracker { function onInvalidate(callback: Function): void; function afterFlush(callback: Function): void; function Dependency(): void; - interface Dependency { - depend(fromComputation?: Tracker.Computation): boolean + interface Dependency{ + depend(fromComputation?: Tracker.Computation): boolean changed(): void; hasDependents(): boolean } @@ -594,79 +602,80 @@ declare module Email { } declare function Subscription(): void; -declare module Subscription { - var connection: Meteor.Connection; - var userId: string; - function error(error: Error): void; - function stop(): void; - function onStop(func: Function): void; - function added(collection: string, id: string, fields: Object): void; - function changed(collection: string, id: string, fields: Object): void; - function removed(collection: string, id: string): void; - function ready(): void; +interface Subscription{ + connection: Meteor.Connection; + userId: string; + error(error: Error): void; + stop(): void; + onStop(func: Function): void; + added(collection: string, id: string, fields: Object): void; + changed(collection: string, id: string, fields: Object): void; + removed(collection: string, id: string): void; + ready(): void; } -declare function ReactiveVar(initialValue: any, equalsFunc?: (oldVal:any, newVal:any)=>boolean): void; -declare module ReactiveVar { - function get(): any; - function set(newValue: any): void; +declare function ReactiveVar(initialValue: T, equalsFunc?: Function): void; +interface ReactiveVar{ + get(): T; + set(newValue: T): void; } -declare function Template(): void; -declare module Template { - var onCreated; /** TODO: add return value **/ - var onRendered; /** TODO: add return value **/ - var onDestroyed; /** TODO: add return value **/ - var created: Function; - var rendered: Function; - var destroyed: Function; - var body: Meteor.TemplateBase; - function helpers(helpers:{[id:string]: any}): void; - function events(eventMap: {[actions: string]: Function}): void; - function instance(): Blaze.TemplateInstance; - function currentData(): {}; - function parentData(numLevels?: number): {}; - function registerHelper(name: string, helperFunction: Function): void; +declare var Template: TemplateStatic; +// TemplateStatic interface should be defined separately at top with static methods +interface Template{ + onCreated: Function; + onRendered: Function; + onDestroyed: Function; + created: Function; + rendered: Function; + destroyed: Function; + body: TemplateStatic; + helpers(helpers:{[id:string]: any}): void; + events(eventMap: {[actions: string]: Function}): void; + instance(): Blaze.TemplateInstance; + currentData(): {}; + parentData(numLevels?: number): {}; + registerHelper(name: string, helperFunction: Function): void; } declare function CompileStep(): void; -declare module CompileStep { - var inputSize; /** TODO: add return value **/ - var inputPath; /** TODO: add return value **/ - var fullInputPath; /** TODO: add return value **/ - var pathForSourceMap; /** TODO: add return value **/ - var packageName; /** TODO: add return value **/ - var rootOutputPath; /** TODO: add return value **/ - var arch; /** TODO: add return value **/ - var fileOptions; /** TODO: add return value **/ - var declaredExports; /** TODO: add return value **/ - function read(n?: number); /** TODO: add return value **/ - function addHtml(options: { +interface CompileStep{ + inputSize; /** TODO: add return value **/ + inputPath; /** TODO: add return value **/ + fullInputPath; /** TODO: add return value **/ + pathForSourceMap; /** TODO: add return value **/ + packageName; /** TODO: add return value **/ + rootOutputPath; /** TODO: add return value **/ + arch; /** TODO: add return value **/ + fileOptions; /** TODO: add return value **/ + declaredExports; /** TODO: add return value **/ + read(n?: number); /** TODO: add return value **/ + addHtml(options: { section?: string; data?: string; }); /** TODO: add return value **/ - function addStylesheet(options: { + addStylesheet(options: { }, path: string, data: string, sourceMap: string); /** TODO: add return value **/ - function addJavaScript(options: { + addJavaScript(options: { path?: string; data?: string; sourcePath?: string; }); /** TODO: add return value **/ - function addAsset(options: { + addAsset(options: { }, path: string, data: any /** Buffer **/ | string); /** TODO: add return value **/ - function error(options: { + error(options: { }, message: string, sourcePath?: string, line?: number, func?: string); /** TODO: add return value **/ } declare function PackageAPI(): void; -declare module PackageAPI { - function use(packageNames: string | string[], architecture?: string, options?: { +interface PackageAPI{ + use(packageNames: string | string[], architecture?: string, options?: { weak?: boolean; unordered?: Boolean; }): void; - function imply(packageSpecs: string | string[]): void; - function addFiles(filename: string | string[], architecture?: string): void; - function versionsFrom(meteorRelease: string | string[]): void; - // function export(exportedObject: string, architecture?: string): void; + imply(packageSpecs: string | string[]): void; + addFiles(filename: string | string[], architecture?: string): void; + versionsFrom(meteorRelease: string | string[]): void; + export(exportedObject: string, architecture?: string): void; } diff --git a/mongodb/mongodb-tests.ts b/mongodb/mongodb-tests.ts index 95333f78c..9cd73d073 100644 --- a/mongodb/mongodb-tests.ts +++ b/mongodb/mongodb-tests.ts @@ -21,5 +21,10 @@ MongoClient.connect('mongodb://127.0.0.1:27017/test', function (err, db) { // Let's close the db db.close(); }); + + // Get some statistics + collection.stats(function (err, stats) { + console.log(stats.count + " documents"); + }); }); -}) \ No newline at end of file +}) diff --git a/mongodb/mongodb.d.ts b/mongodb/mongodb.d.ts index a28f484ce..a1424cb7e 100644 --- a/mongodb/mongodb.d.ts +++ b/mongodb/mongodb.d.ts @@ -253,6 +253,46 @@ declare module "mongodb" { pkFactory?: PKFactory; } + // Documentation: http://docs.mongodb.org/manual/reference/command/collStats/ + export interface CollStats { + // Namespace. + ns: string; + + // Number of documents. + count: number; + + // Collection size in bytes. + size: number; + + // Average object size in bytes. + avgObjSize: number; + + // (Pre)allocated space for the collection in bytes. + storageSize: number; + + // Number of extents (contiguously allocated chunks of datafile space). + numExtents: number; + + // Number of indexes. + nindexes: number; + + // Size of the most recently created extent in bytes. + lastExtentSize: number; + + // Padding can speed up updates if documents grow. + paddingFactor: number; + flags: number; + + // Total index size in bytes. + totalIndexSize: number; + + // Size of specific indexes in bytes. + indexSizes: { + _id_: number; + username: number; + }; + } + // Documentation : http://mongodb.github.io/node-mongodb-native/api-generated/collection.html export interface Collection { new (db: Db, collectionName: string, pkFactory?: Object, options?: CollectionCreateOptions): Collection; // is this right? @@ -326,8 +366,8 @@ declare module "mongodb" { indexes(callback: Function): void; aggregate(pipeline: any[], callback: (err: Error, results: any) => void): void; aggregate(pipeline: any[], options: {readPreference: string}, callback: (err: Error, results: any) => void): void; - stats(options: {readPreference: string; scale: number}, callback: Function): void; - stats(callback: (err: Error, results: any) => void): void; + stats(options: {readPreference: string; scale: number}, callback: (err: Error, results: CollStats) => void): void; + stats(callback: (err: Error, results: CollStats) => void): void; hint: any; } diff --git a/nock/nock-tests.ts b/nock/nock-tests.ts index a209a8c94..00227dfaf 100644 --- a/nock/nock-tests.ts +++ b/nock/nock-tests.ts @@ -72,7 +72,10 @@ inst = inst.twice(); inst = inst.thrice(); inst = inst.defaultReplyHeaders(value); + inst = inst.matchHeader(str, str); +inst = inst.matchHeader(str, regex); +inst = inst.matchHeader(str, (val: string) => true); inst = inst.delay(num); inst = inst.delayConnection(num); @@ -105,4 +108,4 @@ nock.recorder.rec({ }); strings = nock.recorder.play(); -objects = nock.recorder.play(); \ No newline at end of file +objects = nock.recorder.play(); diff --git a/nock/nock.d.ts b/nock/nock.d.ts index bcf4560ce..b6803ca89 100644 --- a/nock/nock.d.ts +++ b/nock/nock.d.ts @@ -55,7 +55,10 @@ declare module "nock" { replyWithFile(responseCode: number, fileName: string): Scope; defaultReplyHeaders(headers: Object): Scope; + matchHeader(name: string, value: string): Scope; + matchHeader(name: string, regex: RegExp): Scope; + matchHeader(name: string, fn: (value: string) => boolean): Scope; filteringPath(regex: RegExp, replace: string): Scope; filteringPath(fn: (path: string) => string): Scope; diff --git a/node/node-0.10.d.ts b/node/node-0.10.d.ts new file mode 100644 index 000000000..99ab5eccd --- /dev/null +++ b/node/node-0.10.d.ts @@ -0,0 +1,1334 @@ +// Type definitions for Node.js v0.10.1 +// Project: http://nodejs.org/ +// Definitions by: Microsoft TypeScript , DefinitelyTyped +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/************************************************ +* * +* Node.js v0.10.1 API * +* * +************************************************/ + +/************************************************ +* * +* GLOBAL * +* * +************************************************/ +declare var process: NodeJS.Process; +declare var global: any; + +declare var __filename: string; +declare var __dirname: string; + +declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearTimeout(timeoutId: NodeJS.Timer): void; +declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearInterval(intervalId: NodeJS.Timer): void; +declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; +declare function clearImmediate(immediateId: any): void; + +declare var require: { + (id: string): any; + resolve(id:string): string; + cache: any; + extensions: any; + main: any; +}; + +declare var module: { + exports: any; + require(id: string): any; + id: string; + filename: string; + loaded: boolean; + parent: any; + children: any[]; +}; + +// Same as module.exports +declare var exports: any; +declare var SlowBuffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + + +// Buffer class +interface Buffer extends NodeBuffer {} +declare var Buffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + +/************************************************ +* * +* GLOBAL INTERFACES * +* * +************************************************/ +declare module NodeJS { + export interface ErrnoException extends Error { + errno?: any; + code?: string; + path?: string; + syscall?: string; + } + + export interface EventEmitter { + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } + + export interface ReadableStream extends EventEmitter { + readable: boolean; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: ReadableStream): ReadableStream; + } + + export interface WritableStream extends EventEmitter { + writable: boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface ReadWriteStream extends ReadableStream, WritableStream {} + + export interface Process extends EventEmitter { + stdout: WritableStream; + stderr: WritableStream; + stdin: ReadableStream; + argv: string[]; + execPath: string; + abort(): void; + chdir(directory: string): void; + cwd(): string; + env: any; + exit(code?: number): void; + getgid(): number; + setgid(id: number): void; + setgid(id: string): void; + getuid(): number; + setuid(id: number): void; + setuid(id: string): void; + version: string; + versions: { + http_parser: string; + node: string; + v8: string; + ares: string; + uv: string; + zlib: string; + openssl: string; + }; + config: { + target_defaults: { + cflags: any[]; + default_configuration: string; + defines: string[]; + include_dirs: string[]; + libraries: string[]; + }; + variables: { + clang: number; + host_arch: string; + node_install_npm: boolean; + node_install_waf: boolean; + node_prefix: string; + node_shared_openssl: boolean; + node_shared_v8: boolean; + node_shared_zlib: boolean; + node_use_dtrace: boolean; + node_use_etw: boolean; + node_use_openssl: boolean; + target_arch: string; + v8_no_strict_aliasing: number; + v8_use_snapshot: boolean; + visibility: string; + }; + }; + kill(pid: number, signal?: string): void; + pid: number; + title: string; + arch: string; + platform: string; + memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; + nextTick(callback: Function): void; + umask(mask?: number): number; + uptime(): number; + hrtime(time?:number[]): number[]; + + // Worker + send?(message: any, sendHandle?: any): void; + } + + export interface Timer { + ref() : void; + unref() : void; + } +} + +/** + * @deprecated + */ +interface NodeBuffer { + [index: number]: number; + write(string: string, offset?: number, length?: number, encoding?: string): number; + toString(encoding?: string, start?: number, end?: number): string; + toJSON(): any; + length: number; + copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; + slice(start?: number, end?: number): Buffer; + readUInt8(offset: number, noAsset?: boolean): number; + readUInt16LE(offset: number, noAssert?: boolean): number; + readUInt16BE(offset: number, noAssert?: boolean): number; + readUInt32LE(offset: number, noAssert?: boolean): number; + readUInt32BE(offset: number, noAssert?: boolean): number; + readInt8(offset: number, noAssert?: boolean): number; + readInt16LE(offset: number, noAssert?: boolean): number; + readInt16BE(offset: number, noAssert?: boolean): number; + readInt32LE(offset: number, noAssert?: boolean): number; + readInt32BE(offset: number, noAssert?: boolean): number; + readFloatLE(offset: number, noAssert?: boolean): number; + readFloatBE(offset: number, noAssert?: boolean): number; + readDoubleLE(offset: number, noAssert?: boolean): number; + readDoubleBE(offset: number, noAssert?: boolean): number; + writeUInt8(value: number, offset: number, noAssert?: boolean): void; + writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeInt8(value: number, offset: number, noAssert?: boolean): void; + writeInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeFloatLE(value: number, offset: number, noAssert?: boolean): void; + writeFloatBE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; + fill(value: any, offset?: number, end?: number): void; +} + +/************************************************ +* * +* MODULES * +* * +************************************************/ +declare module "buffer" { + export var INSPECT_MAX_BYTES: number; +} + +declare module "querystring" { + export function stringify(obj: any, sep?: string, eq?: string): string; + export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; + export function escape(): any; + export function unescape(): any; +} + +declare module "events" { + export class EventEmitter implements NodeJS.EventEmitter { + static listenerCount(emitter: EventEmitter, event: string): number; + + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } +} + +declare module "http" { + import events = require("events"); + import net = require("net"); + import stream = require("stream"); + + export interface Server extends events.EventEmitter { + listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; + listen(path: string, callback?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(cb?: any): Server; + address(): { port: number; family: string; address: string; }; + maxHeadersCount: number; + } + export interface ServerRequest extends events.EventEmitter, stream.Readable { + method: string; + url: string; + headers: any; + trailers: string; + httpVersion: string; + setEncoding(encoding?: string): void; + pause(): void; + resume(): void; + connection: net.Socket; + } + export interface ServerResponse extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + writeContinue(): void; + writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; + writeHead(statusCode: number, headers?: any): void; + statusCode: number; + setHeader(name: string, value: string): void; + sendDate: boolean; + getHeader(name: string): string; + removeHeader(name: string): void; + write(chunk: any, encoding?: string): any; + addTrailers(headers: any): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface ClientRequest extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + write(chunk: any, encoding?: string): void; + abort(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface ClientResponse extends events.EventEmitter, stream.Readable { + statusCode: number; + httpVersion: string; + headers: any; + trailers: any; + setEncoding(encoding?: string): void; + pause(): void; + resume(): void; + } + export interface Agent { maxSockets: number; sockets: any; requests: any; } + + export var STATUS_CODES: { + [errorCode: number]: string; + [errorCode: string]: string; + }; + export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server; + export function createClient(port?: number, host?: string): any; + export function request(options: any, callback?: Function): ClientRequest; + export function get(options: any, callback?: Function): ClientRequest; + export var globalAgent: Agent; +} + +declare module "cluster" { + import child = require("child_process"); + import events = require("events"); + + export interface ClusterSettings { + exec?: string; + args?: string[]; + silent?: boolean; + } + + export class Worker extends events.EventEmitter { + id: string; + process: child.ChildProcess; + suicide: boolean; + send(message: any, sendHandle?: any): void; + kill(signal?: string): void; + destroy(signal?: string): void; + disconnect(): void; + } + + export var settings: ClusterSettings; + export var isMaster: boolean; + export var isWorker: boolean; + export function setupMaster(settings?: ClusterSettings): void; + export function fork(env?: any): Worker; + export function disconnect(callback?: Function): void; + export var worker: Worker; + export var workers: Worker[]; + + // Event emitter + export function addListener(event: string, listener: Function): void; + export function on(event: string, listener: Function): any; + export function once(event: string, listener: Function): void; + export function removeListener(event: string, listener: Function): void; + export function removeAllListeners(event?: string): void; + export function setMaxListeners(n: number): void; + export function listeners(event: string): Function[]; + export function emit(event: string, ...args: any[]): boolean; +} + +declare module "zlib" { + import stream = require("stream"); + export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } + + export interface Gzip extends stream.Transform { } + export interface Gunzip extends stream.Transform { } + export interface Deflate extends stream.Transform { } + export interface Inflate extends stream.Transform { } + export interface DeflateRaw extends stream.Transform { } + export interface InflateRaw extends stream.Transform { } + export interface Unzip extends stream.Transform { } + + export function createGzip(options?: ZlibOptions): Gzip; + export function createGunzip(options?: ZlibOptions): Gunzip; + export function createDeflate(options?: ZlibOptions): Deflate; + export function createInflate(options?: ZlibOptions): Inflate; + export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; + export function createInflateRaw(options?: ZlibOptions): InflateRaw; + export function createUnzip(options?: ZlibOptions): Unzip; + + export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + + // Constants + export var Z_NO_FLUSH: number; + export var Z_PARTIAL_FLUSH: number; + export var Z_SYNC_FLUSH: number; + export var Z_FULL_FLUSH: number; + export var Z_FINISH: number; + export var Z_BLOCK: number; + export var Z_TREES: number; + export var Z_OK: number; + export var Z_STREAM_END: number; + export var Z_NEED_DICT: number; + export var Z_ERRNO: number; + export var Z_STREAM_ERROR: number; + export var Z_DATA_ERROR: number; + export var Z_MEM_ERROR: number; + export var Z_BUF_ERROR: number; + export var Z_VERSION_ERROR: number; + export var Z_NO_COMPRESSION: number; + export var Z_BEST_SPEED: number; + export var Z_BEST_COMPRESSION: number; + export var Z_DEFAULT_COMPRESSION: number; + export var Z_FILTERED: number; + export var Z_HUFFMAN_ONLY: number; + export var Z_RLE: number; + export var Z_FIXED: number; + export var Z_DEFAULT_STRATEGY: number; + export var Z_BINARY: number; + export var Z_TEXT: number; + export var Z_ASCII: number; + export var Z_UNKNOWN: number; + export var Z_DEFLATED: number; + export var Z_NULL: number; +} + +declare module "os" { + export function tmpdir(): string; + export function hostname(): string; + export function type(): string; + export function platform(): string; + export function arch(): string; + export function release(): string; + export function uptime(): number; + export function loadavg(): number[]; + export function totalmem(): number; + export function freemem(): number; + export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; + export function networkInterfaces(): any; + export var EOL: string; +} + +declare module "https" { + import tls = require("tls"); + import events = require("events"); + import http = require("http"); + + export interface ServerOptions { + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + crl?: any; + ciphers?: string; + honorCipherOrder?: boolean; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; + SNICallback?: (servername: string) => any; + } + + export interface RequestOptions { + host?: string; + hostname?: string; + port?: number; + path?: string; + method?: string; + headers?: any; + auth?: string; + agent?: any; + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + ciphers?: string; + rejectUnauthorized?: boolean; + } + + export interface Agent { + maxSockets: number; + sockets: any; + requests: any; + } + export var Agent: { + new (options?: RequestOptions): Agent; + }; + export interface Server extends tls.Server { } + export function createServer(options: ServerOptions, requestListener?: Function): Server; + export function request(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; + export function get(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; + export var globalAgent: Agent; +} + +declare module "punycode" { + export function decode(string: string): string; + export function encode(string: string): string; + export function toUnicode(domain: string): string; + export function toASCII(domain: string): string; + export var ucs2: ucs2; + interface ucs2 { + decode(string: string): string; + encode(codePoints: number[]): string; + } + export var version: any; +} + +declare module "repl" { + import stream = require("stream"); + import events = require("events"); + + export interface ReplOptions { + prompt?: string; + input?: NodeJS.ReadableStream; + output?: NodeJS.WritableStream; + terminal?: boolean; + eval?: Function; + useColors?: boolean; + useGlobal?: boolean; + ignoreUndefined?: boolean; + writer?: Function; + } + export function start(options: ReplOptions): events.EventEmitter; +} + +declare module "readline" { + import events = require("events"); + import stream = require("stream"); + + export interface ReadLine extends events.EventEmitter { + setPrompt(prompt: string, length: number): void; + prompt(preserveCursor?: boolean): void; + question(query: string, callback: Function): void; + pause(): void; + resume(): void; + close(): void; + write(data: any, key?: any): void; + } + export interface ReadLineOptions { + input: NodeJS.ReadableStream; + output: NodeJS.WritableStream; + completer?: Function; + terminal?: boolean; + } + export function createInterface(options: ReadLineOptions): ReadLine; +} + +declare module "vm" { + export interface Context { } + export interface Script { + runInThisContext(): void; + runInNewContext(sandbox?: Context): void; + } + export function runInThisContext(code: string, filename?: string): void; + export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; + export function runInContext(code: string, context: Context, filename?: string): void; + export function createContext(initSandbox?: Context): Context; + export function createScript(code: string, filename?: string): Script; +} + +declare module "child_process" { + import events = require("events"); + import stream = require("stream"); + + export interface ChildProcess extends events.EventEmitter { + stdin: stream.Writable; + stdout: stream.Readable; + stderr: stream.Readable; + pid: number; + kill(signal?: string): void; + send(message: any, sendHandle: any): void; + disconnect(): void; + } + + export function spawn(command: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + custom?: any; + env?: any; + detached?: boolean; + }): ChildProcess; + export function exec(command: string, options: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + }, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function exec(command: string, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: string; + killSignal?: string; + }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function fork(modulePath: string, args?: string[], options?: { + cwd?: string; + env?: any; + encoding?: string; + }): ChildProcess; +} + +declare module "url" { + export interface Url { + href: string; + protocol: string; + auth: string; + hostname: string; + port: string; + host: string; + pathname: string; + search: string; + query: any; // string | Object + slashes: boolean; + hash?: string; + path?: string; + } + + export interface UrlOptions { + protocol?: string; + auth?: string; + hostname?: string; + port?: string; + host?: string; + pathname?: string; + search?: string; + query?: any; + hash?: string; + path?: string; + } + + export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; + export function format(url: UrlOptions): string; + export function resolve(from: string, to: string): string; +} + +declare module "dns" { + export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; + export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; + export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; +} + +declare module "net" { + import stream = require("stream"); + + export interface Socket extends stream.Duplex { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + connect(port: number, host?: string, connectionListener?: Function): void; + connect(path: string, connectionListener?: Function): void; + bufferSize: number; + setEncoding(encoding?: string): void; + write(data: any, encoding?: string, callback?: Function): void; + destroy(): void; + pause(): void; + resume(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setKeepAlive(enable?: boolean, initialDelay?: number): void; + address(): { port: number; family: string; address: string; }; + unref(): void; + ref(): void; + + remoteAddress: string; + remotePort: number; + bytesRead: number; + bytesWritten: number; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + + export var Socket: { + new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; + }; + + export interface Server extends Socket { + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(callback?: Function): Server; + address(): { port: number; family: string; address: string; }; + maxConnections: number; + connections: number; + } + export function createServer(connectionListener?: (socket: Socket) =>void ): Server; + export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; + export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function connect(port: number, host?: string, connectionListener?: Function): Socket; + export function connect(path: string, connectionListener?: Function): Socket; + export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; + export function createConnection(path: string, connectionListener?: Function): Socket; + export function isIP(input: string): number; + export function isIPv4(input: string): boolean; + export function isIPv6(input: string): boolean; +} + +declare module "dgram" { + import events = require("events"); + + interface RemoteInfo { + address: string; + port: number; + size: number; + } + + interface AddressInfo { + address: string; + family: string; + port: number; + } + + export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + + interface Socket extends events.EventEmitter { + send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; + bind(port: number, address?: string, callback?: () => void): void; + close(): void; + address(): AddressInfo; + setBroadcast(flag: boolean): void; + setMulticastTTL(ttl: number): void; + setMulticastLoopback(flag: boolean): void; + addMembership(multicastAddress: string, multicastInterface?: string): void; + dropMembership(multicastAddress: string, multicastInterface?: string): void; + } +} + +declare module "fs" { + import stream = require("stream"); + import events = require("events"); + + interface Stats { + isFile(): boolean; + isDirectory(): boolean; + isBlockDevice(): boolean; + isCharacterDevice(): boolean; + isSymbolicLink(): boolean; + isFIFO(): boolean; + isSocket(): boolean; + dev: number; + ino: number; + mode: number; + nlink: number; + uid: number; + gid: number; + rdev: number; + size: number; + blksize: number; + blocks: number; + atime: Date; + mtime: Date; + ctime: Date; + } + + interface FSWatcher extends events.EventEmitter { + close(): void; + } + + export interface ReadStream extends stream.Readable { + close(): void; + } + export interface WriteStream extends stream.Writable { + close(): void; + } + + export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function renameSync(oldPath: string, newPath: string): void; + export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncateSync(path: string, len?: number): void; + export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncateSync(fd: number, len?: number): void; + export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chownSync(path: string, uid: number, gid: number): void; + export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchownSync(fd: number, uid: number, gid: number): void; + export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchownSync(path: string, uid: number, gid: number): void; + export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmodSync(path: string, mode: number): void; + export function chmodSync(path: string, mode: string): void; + export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmodSync(fd: number, mode: number): void; + export function fchmodSync(fd: number, mode: string): void; + export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmodSync(path: string, mode: number): void; + export function lchmodSync(path: string, mode: string): void; + export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function statSync(path: string): Stats; + export function lstatSync(path: string): Stats; + export function fstatSync(fd: number): Stats; + export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function linkSync(srcpath: string, dstpath: string): void; + export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; + export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; + export function readlinkSync(path: string): string; + export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; + export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; + export function realpathSync(path: string, cache?: {[path: string]: string}): string; + export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function unlinkSync(path: string): void; + export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function rmdirSync(path: string): void; + export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdirSync(path: string, mode?: number): void; + export function mkdirSync(path: string, mode?: string): void; + export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; + export function readdirSync(path: string): string[]; + export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function closeSync(fd: number): void; + export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function openSync(path: string, flags: string, mode?: number): number; + export function openSync(path: string, flags: string, mode?: string): number; + export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimesSync(path: string, atime: number, mtime: number): void; + export function utimesSync(path: string, atime: Date, mtime: Date): void; + export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimesSync(fd: number, atime: number, mtime: number): void; + export function futimesSync(fd: number, atime: Date, mtime: Date): void; + export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fsyncSync(fd: number): void; + export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; + export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; + export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; + export function readFileSync(filename: string, encoding: string): string; + export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; + export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; + export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; + export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; + export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; + export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; + export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; + export function exists(path: string, callback?: (exists: boolean) => void): void; + export function existsSync(path: string): boolean; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: number; + bufferSize?: number; + }): ReadStream; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: string; + bufferSize?: number; + }): ReadStream; + export function createWriteStream(path: string, options?: { + flags?: string; + encoding?: string; + string?: string; + }): WriteStream; +} + +declare module "path" { + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; +} + +declare module "string_decoder" { + export interface NodeStringDecoder { + write(buffer: Buffer): string; + detectIncompleteChar(buffer: Buffer): number; + } + export var StringDecoder: { + new (encoding: string): NodeStringDecoder; + }; +} + +declare module "tls" { + import crypto = require("crypto"); + import net = require("net"); + import stream = require("stream"); + + var CLIENT_RENEG_LIMIT: number; + var CLIENT_RENEG_WINDOW: number; + + export interface TlsOptions { + pfx?: any; //string or buffer + key?: any; //string or buffer + passphrase?: string; + cert?: any; + ca?: any; //string or buffer + crl?: any; //string or string array + ciphers?: string; + honorCipherOrder?: any; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; //array or Buffer; + SNICallback?: (servername: string) => any; + } + + export interface ConnectionOptions { + host?: string; + port?: number; + socket?: net.Socket; + pfx?: any; //string | Buffer + key?: any; //string | Buffer + passphrase?: string; + cert?: any; //string | Buffer + ca?: any; //Array of string | Buffer + rejectUnauthorized?: boolean; + NPNProtocols?: any; //Array of string | Buffer + servername?: string; + } + + export interface Server extends net.Server { + // Extended base methods + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + + listen(port: number, host?: string, callback?: Function): Server; + close(): Server; + address(): { port: number; family: string; address: string; }; + addContext(hostName: string, credentials: { + key: string; + cert: string; + ca: string; + }): void; + maxConnections: number; + connections: number; + } + + export interface ClearTextStream extends stream.Duplex { + authorized: boolean; + authorizationError: Error; + getPeerCertificate(): any; + getCipher: { + name: string; + version: string; + }; + address: { + port: number; + family: string; + address: string; + }; + remoteAddress: string; + remotePort: number; + } + + export interface SecurePair { + encrypted: any; + cleartext: any; + } + + export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; + export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; + export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; +} + +declare module "crypto" { + export interface CredentialDetails { + pfx: string; + key: string; + passphrase: string; + cert: string; + ca: any; //string | string array + crl: any; //string | string array + ciphers: string; + } + export interface Credentials { context?: any; } + export function createCredentials(details: CredentialDetails): Credentials; + export function createHash(algorithm: string): Hash; + export function createHmac(algorithm: string, key: string): Hmac; + export function createHmac(algorithm: string, key: Buffer): Hmac; + interface Hash { + update(data: any, input_encoding?: string): Hash; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + interface Hmac { + update(data: any, input_encoding?: string): Hmac; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + export function createCipher(algorithm: string, password: any): Cipher; + export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; + interface Cipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createDecipher(algorithm: string, password: any): Decipher; + export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; + interface Decipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createSign(algorithm: string): Signer; + interface Signer { + update(data: any): void; + sign(private_key: string, output_format: string): string; + } + export function createVerify(algorith: string): Verify; + interface Verify { + update(data: any): void; + verify(object: string, signature: string, signature_format?: string): boolean; + } + export function createDiffieHellman(prime_length: number): DiffieHellman; + export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; + interface DiffieHellman { + generateKeys(encoding?: string): string; + computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; + getPrime(encoding?: string): string; + getGenerator(encoding: string): string; + getPublicKey(encoding?: string): string; + getPrivateKey(encoding?: string): string; + setPublicKey(public_key: string, encoding?: string): void; + setPrivateKey(public_key: string, encoding?: string): void; + } + export function getDiffieHellman(group_name: string): DiffieHellman; + export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; + export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; + export function randomBytes(size: number): Buffer; + export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; + export function pseudoRandomBytes(size: number): Buffer; + export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; +} + +declare module "stream" { + import events = require("events"); + + export interface Stream extends events.EventEmitter { + pipe(destination: T, options?: { end?: boolean; }): T; + } + + export interface ReadableOptions { + highWaterMark?: number; + encoding?: string; + objectMode?: boolean; + } + + export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { + readable: boolean; + constructor(opts?: ReadableOptions); + _read(size: number): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + } + + export interface WritableOptions { + highWaterMark?: number; + decodeStrings?: boolean; + } + + export class Writable extends events.EventEmitter implements NodeJS.WritableStream { + writable: boolean; + constructor(opts?: WritableOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface DuplexOptions extends ReadableOptions, WritableOptions { + allowHalfOpen?: boolean; + } + + // Note: Duplex extends both Readable and Writable. + export class Duplex extends Readable implements NodeJS.ReadWriteStream { + writable: boolean; + constructor(opts?: DuplexOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface TransformOptions extends ReadableOptions, WritableOptions {} + + // Note: Transform lacks the _read and _write methods of Readable/Writable. + export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { + readable: boolean; + writable: boolean; + constructor(opts?: TransformOptions); + _transform(chunk: Buffer, encoding: string, callback: Function): void; + _transform(chunk: string, encoding: string, callback: Function): void; + _flush(callback: Function): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export class PassThrough extends Transform {} +} + +declare module "util" { + export interface InspectOptions { + showHidden?: boolean; + depth?: number; + colors?: boolean; + customInspect?: boolean; + } + + export function format(format: any, ...param: any[]): string; + export function debug(string: string): void; + export function error(...param: any[]): void; + export function puts(...param: any[]): void; + export function print(...param: any[]): void; + export function log(string: string): void; + export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; + export function inspect(object: any, options: InspectOptions): string; + export function isArray(object: any): boolean; + export function isRegExp(object: any): boolean; + export function isDate(object: any): boolean; + export function isError(object: any): boolean; + export function inherits(constructor: any, superConstructor: any): void; +} + +declare module "assert" { + function internal (value: any, message?: string): void; + module internal { + export class AssertionError implements Error { + name: string; + message: string; + actual: any; + expected: any; + operator: string; + generatedMessage: boolean; + + constructor(options?: {message?: string; actual?: any; expected?: any; + operator?: string; stackStartFunction?: Function}); + } + + export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + export function ok(value: any, message?: string): void; + export function equal(actual: any, expected: any, message?: string): void; + export function notEqual(actual: any, expected: any, message?: string): void; + export function deepEqual(actual: any, expected: any, message?: string): void; + export function notDeepEqual(acutal: any, expected: any, message?: string): void; + export function strictEqual(actual: any, expected: any, message?: string): void; + export function notStrictEqual(actual: any, expected: any, message?: string): void; + export var throws: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export var doesNotThrow: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export function ifError(value: any): void; + } + + export = internal; +} + +declare module "tty" { + import net = require("net"); + + export function isatty(fd: number): boolean; + export interface ReadStream extends net.Socket { + isRaw: boolean; + setRawMode(mode: boolean): void; + } + export interface WriteStream extends net.Socket { + columns: number; + rows: number; + } +} + +declare module "domain" { + import events = require("events"); + + export class Domain extends events.EventEmitter { + run(fn: Function): void; + add(emitter: events.EventEmitter): void; + remove(emitter: events.EventEmitter): void; + bind(cb: (err: Error, data: any) => any): any; + intercept(cb: (data: any) => any): any; + dispose(): void; + + addListener(event: string, listener: Function): Domain; + on(event: string, listener: Function): Domain; + once(event: string, listener: Function): Domain; + removeListener(event: string, listener: Function): Domain; + removeAllListeners(event?: string): Domain; + } + + export function create(): Domain; +} diff --git a/node/node.d.ts b/node/node.d.ts index 99ab5eccd..6c09ee04f 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -1,1334 +1,1334 @@ -// Type definitions for Node.js v0.10.1 -// Project: http://nodejs.org/ -// Definitions by: Microsoft TypeScript , DefinitelyTyped -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -/************************************************ -* * -* Node.js v0.10.1 API * -* * -************************************************/ - -/************************************************ -* * -* GLOBAL * -* * -************************************************/ -declare var process: NodeJS.Process; -declare var global: any; - -declare var __filename: string; -declare var __dirname: string; - -declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearTimeout(timeoutId: NodeJS.Timer): void; -declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; -declare function clearInterval(intervalId: NodeJS.Timer): void; -declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; -declare function clearImmediate(immediateId: any): void; - -declare var require: { - (id: string): any; - resolve(id:string): string; - cache: any; - extensions: any; - main: any; -}; - -declare var module: { - exports: any; - require(id: string): any; - id: string; - filename: string; - loaded: boolean; - parent: any; - children: any[]; -}; - -// Same as module.exports -declare var exports: any; -declare var SlowBuffer: { - new (str: string, encoding?: string): Buffer; - new (size: number): Buffer; - new (size: Uint8Array): Buffer; - new (array: any[]): Buffer; - prototype: Buffer; - isBuffer(obj: any): boolean; - byteLength(string: string, encoding?: string): number; - concat(list: Buffer[], totalLength?: number): Buffer; -}; - - -// Buffer class -interface Buffer extends NodeBuffer {} -declare var Buffer: { - new (str: string, encoding?: string): Buffer; - new (size: number): Buffer; - new (size: Uint8Array): Buffer; - new (array: any[]): Buffer; - prototype: Buffer; - isBuffer(obj: any): boolean; - byteLength(string: string, encoding?: string): number; - concat(list: Buffer[], totalLength?: number): Buffer; -}; - -/************************************************ -* * -* GLOBAL INTERFACES * -* * -************************************************/ -declare module NodeJS { - export interface ErrnoException extends Error { - errno?: any; - code?: string; - path?: string; - syscall?: string; - } - - export interface EventEmitter { - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - } - - export interface ReadableStream extends EventEmitter { - readable: boolean; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: ReadableStream): ReadableStream; - } - - export interface WritableStream extends EventEmitter { - writable: boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface ReadWriteStream extends ReadableStream, WritableStream {} - - export interface Process extends EventEmitter { - stdout: WritableStream; - stderr: WritableStream; - stdin: ReadableStream; - argv: string[]; - execPath: string; - abort(): void; - chdir(directory: string): void; - cwd(): string; - env: any; - exit(code?: number): void; - getgid(): number; - setgid(id: number): void; - setgid(id: string): void; - getuid(): number; - setuid(id: number): void; - setuid(id: string): void; - version: string; - versions: { - http_parser: string; - node: string; - v8: string; - ares: string; - uv: string; - zlib: string; - openssl: string; - }; - config: { - target_defaults: { - cflags: any[]; - default_configuration: string; - defines: string[]; - include_dirs: string[]; - libraries: string[]; - }; - variables: { - clang: number; - host_arch: string; - node_install_npm: boolean; - node_install_waf: boolean; - node_prefix: string; - node_shared_openssl: boolean; - node_shared_v8: boolean; - node_shared_zlib: boolean; - node_use_dtrace: boolean; - node_use_etw: boolean; - node_use_openssl: boolean; - target_arch: string; - v8_no_strict_aliasing: number; - v8_use_snapshot: boolean; - visibility: string; - }; - }; - kill(pid: number, signal?: string): void; - pid: number; - title: string; - arch: string; - platform: string; - memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; - nextTick(callback: Function): void; - umask(mask?: number): number; - uptime(): number; - hrtime(time?:number[]): number[]; - - // Worker - send?(message: any, sendHandle?: any): void; - } - - export interface Timer { - ref() : void; - unref() : void; - } -} - -/** - * @deprecated - */ -interface NodeBuffer { - [index: number]: number; - write(string: string, offset?: number, length?: number, encoding?: string): number; - toString(encoding?: string, start?: number, end?: number): string; - toJSON(): any; - length: number; - copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; - slice(start?: number, end?: number): Buffer; - readUInt8(offset: number, noAsset?: boolean): number; - readUInt16LE(offset: number, noAssert?: boolean): number; - readUInt16BE(offset: number, noAssert?: boolean): number; - readUInt32LE(offset: number, noAssert?: boolean): number; - readUInt32BE(offset: number, noAssert?: boolean): number; - readInt8(offset: number, noAssert?: boolean): number; - readInt16LE(offset: number, noAssert?: boolean): number; - readInt16BE(offset: number, noAssert?: boolean): number; - readInt32LE(offset: number, noAssert?: boolean): number; - readInt32BE(offset: number, noAssert?: boolean): number; - readFloatLE(offset: number, noAssert?: boolean): number; - readFloatBE(offset: number, noAssert?: boolean): number; - readDoubleLE(offset: number, noAssert?: boolean): number; - readDoubleBE(offset: number, noAssert?: boolean): number; - writeUInt8(value: number, offset: number, noAssert?: boolean): void; - writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeInt8(value: number, offset: number, noAssert?: boolean): void; - writeInt16LE(value: number, offset: number, noAssert?: boolean): void; - writeInt16BE(value: number, offset: number, noAssert?: boolean): void; - writeInt32LE(value: number, offset: number, noAssert?: boolean): void; - writeInt32BE(value: number, offset: number, noAssert?: boolean): void; - writeFloatLE(value: number, offset: number, noAssert?: boolean): void; - writeFloatBE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; - writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; - fill(value: any, offset?: number, end?: number): void; -} - -/************************************************ -* * -* MODULES * -* * -************************************************/ -declare module "buffer" { - export var INSPECT_MAX_BYTES: number; -} - -declare module "querystring" { - export function stringify(obj: any, sep?: string, eq?: string): string; - export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; - export function escape(): any; - export function unescape(): any; -} - -declare module "events" { - export class EventEmitter implements NodeJS.EventEmitter { - static listenerCount(emitter: EventEmitter, event: string): number; - - addListener(event: string, listener: Function): EventEmitter; - on(event: string, listener: Function): EventEmitter; - once(event: string, listener: Function): EventEmitter; - removeListener(event: string, listener: Function): EventEmitter; - removeAllListeners(event?: string): EventEmitter; - setMaxListeners(n: number): void; - listeners(event: string): Function[]; - emit(event: string, ...args: any[]): boolean; - } -} - -declare module "http" { - import events = require("events"); - import net = require("net"); - import stream = require("stream"); - - export interface Server extends events.EventEmitter { - listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; - listen(path: string, callback?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - close(cb?: any): Server; - address(): { port: number; family: string; address: string; }; - maxHeadersCount: number; - } - export interface ServerRequest extends events.EventEmitter, stream.Readable { - method: string; - url: string; - headers: any; - trailers: string; - httpVersion: string; - setEncoding(encoding?: string): void; - pause(): void; - resume(): void; - connection: net.Socket; - } - export interface ServerResponse extends events.EventEmitter, stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - writeContinue(): void; - writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; - writeHead(statusCode: number, headers?: any): void; - statusCode: number; - setHeader(name: string, value: string): void; - sendDate: boolean; - getHeader(name: string): string; - removeHeader(name: string): void; - write(chunk: any, encoding?: string): any; - addTrailers(headers: any): void; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface ClientRequest extends events.EventEmitter, stream.Writable { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - write(chunk: any, encoding?: string): void; - abort(): void; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - export interface ClientResponse extends events.EventEmitter, stream.Readable { - statusCode: number; - httpVersion: string; - headers: any; - trailers: any; - setEncoding(encoding?: string): void; - pause(): void; - resume(): void; - } - export interface Agent { maxSockets: number; sockets: any; requests: any; } - - export var STATUS_CODES: { - [errorCode: number]: string; - [errorCode: string]: string; - }; - export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server; - export function createClient(port?: number, host?: string): any; - export function request(options: any, callback?: Function): ClientRequest; - export function get(options: any, callback?: Function): ClientRequest; - export var globalAgent: Agent; -} - -declare module "cluster" { - import child = require("child_process"); - import events = require("events"); - - export interface ClusterSettings { - exec?: string; - args?: string[]; - silent?: boolean; - } - - export class Worker extends events.EventEmitter { - id: string; - process: child.ChildProcess; - suicide: boolean; - send(message: any, sendHandle?: any): void; - kill(signal?: string): void; - destroy(signal?: string): void; - disconnect(): void; - } - - export var settings: ClusterSettings; - export var isMaster: boolean; - export var isWorker: boolean; - export function setupMaster(settings?: ClusterSettings): void; - export function fork(env?: any): Worker; - export function disconnect(callback?: Function): void; - export var worker: Worker; - export var workers: Worker[]; - - // Event emitter - export function addListener(event: string, listener: Function): void; - export function on(event: string, listener: Function): any; - export function once(event: string, listener: Function): void; - export function removeListener(event: string, listener: Function): void; - export function removeAllListeners(event?: string): void; - export function setMaxListeners(n: number): void; - export function listeners(event: string): Function[]; - export function emit(event: string, ...args: any[]): boolean; -} - -declare module "zlib" { - import stream = require("stream"); - export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } - - export interface Gzip extends stream.Transform { } - export interface Gunzip extends stream.Transform { } - export interface Deflate extends stream.Transform { } - export interface Inflate extends stream.Transform { } - export interface DeflateRaw extends stream.Transform { } - export interface InflateRaw extends stream.Transform { } - export interface Unzip extends stream.Transform { } - - export function createGzip(options?: ZlibOptions): Gzip; - export function createGunzip(options?: ZlibOptions): Gunzip; - export function createDeflate(options?: ZlibOptions): Deflate; - export function createInflate(options?: ZlibOptions): Inflate; - export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; - export function createInflateRaw(options?: ZlibOptions): InflateRaw; - export function createUnzip(options?: ZlibOptions): Unzip; - - export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; - - // Constants - export var Z_NO_FLUSH: number; - export var Z_PARTIAL_FLUSH: number; - export var Z_SYNC_FLUSH: number; - export var Z_FULL_FLUSH: number; - export var Z_FINISH: number; - export var Z_BLOCK: number; - export var Z_TREES: number; - export var Z_OK: number; - export var Z_STREAM_END: number; - export var Z_NEED_DICT: number; - export var Z_ERRNO: number; - export var Z_STREAM_ERROR: number; - export var Z_DATA_ERROR: number; - export var Z_MEM_ERROR: number; - export var Z_BUF_ERROR: number; - export var Z_VERSION_ERROR: number; - export var Z_NO_COMPRESSION: number; - export var Z_BEST_SPEED: number; - export var Z_BEST_COMPRESSION: number; - export var Z_DEFAULT_COMPRESSION: number; - export var Z_FILTERED: number; - export var Z_HUFFMAN_ONLY: number; - export var Z_RLE: number; - export var Z_FIXED: number; - export var Z_DEFAULT_STRATEGY: number; - export var Z_BINARY: number; - export var Z_TEXT: number; - export var Z_ASCII: number; - export var Z_UNKNOWN: number; - export var Z_DEFLATED: number; - export var Z_NULL: number; -} - -declare module "os" { - export function tmpdir(): string; - export function hostname(): string; - export function type(): string; - export function platform(): string; - export function arch(): string; - export function release(): string; - export function uptime(): number; - export function loadavg(): number[]; - export function totalmem(): number; - export function freemem(): number; - export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; - export function networkInterfaces(): any; - export var EOL: string; -} - -declare module "https" { - import tls = require("tls"); - import events = require("events"); - import http = require("http"); - - export interface ServerOptions { - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - crl?: any; - ciphers?: string; - honorCipherOrder?: boolean; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: any; - SNICallback?: (servername: string) => any; - } - - export interface RequestOptions { - host?: string; - hostname?: string; - port?: number; - path?: string; - method?: string; - headers?: any; - auth?: string; - agent?: any; - pfx?: any; - key?: any; - passphrase?: string; - cert?: any; - ca?: any; - ciphers?: string; - rejectUnauthorized?: boolean; - } - - export interface Agent { - maxSockets: number; - sockets: any; - requests: any; - } - export var Agent: { - new (options?: RequestOptions): Agent; - }; - export interface Server extends tls.Server { } - export function createServer(options: ServerOptions, requestListener?: Function): Server; - export function request(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; - export function get(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; - export var globalAgent: Agent; -} - -declare module "punycode" { - export function decode(string: string): string; - export function encode(string: string): string; - export function toUnicode(domain: string): string; - export function toASCII(domain: string): string; - export var ucs2: ucs2; - interface ucs2 { - decode(string: string): string; - encode(codePoints: number[]): string; - } - export var version: any; -} - -declare module "repl" { - import stream = require("stream"); - import events = require("events"); - - export interface ReplOptions { - prompt?: string; - input?: NodeJS.ReadableStream; - output?: NodeJS.WritableStream; - terminal?: boolean; - eval?: Function; - useColors?: boolean; - useGlobal?: boolean; - ignoreUndefined?: boolean; - writer?: Function; - } - export function start(options: ReplOptions): events.EventEmitter; -} - -declare module "readline" { - import events = require("events"); - import stream = require("stream"); - - export interface ReadLine extends events.EventEmitter { - setPrompt(prompt: string, length: number): void; - prompt(preserveCursor?: boolean): void; - question(query: string, callback: Function): void; - pause(): void; - resume(): void; - close(): void; - write(data: any, key?: any): void; - } - export interface ReadLineOptions { - input: NodeJS.ReadableStream; - output: NodeJS.WritableStream; - completer?: Function; - terminal?: boolean; - } - export function createInterface(options: ReadLineOptions): ReadLine; -} - -declare module "vm" { - export interface Context { } - export interface Script { - runInThisContext(): void; - runInNewContext(sandbox?: Context): void; - } - export function runInThisContext(code: string, filename?: string): void; - export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; - export function runInContext(code: string, context: Context, filename?: string): void; - export function createContext(initSandbox?: Context): Context; - export function createScript(code: string, filename?: string): Script; -} - -declare module "child_process" { - import events = require("events"); - import stream = require("stream"); - - export interface ChildProcess extends events.EventEmitter { - stdin: stream.Writable; - stdout: stream.Readable; - stderr: stream.Readable; - pid: number; - kill(signal?: string): void; - send(message: any, sendHandle: any): void; - disconnect(): void; - } - - export function spawn(command: string, args?: string[], options?: { - cwd?: string; - stdio?: any; - custom?: any; - env?: any; - detached?: boolean; - }): ChildProcess; - export function exec(command: string, options: { - cwd?: string; - stdio?: any; - customFds?: any; - env?: any; - encoding?: string; - timeout?: number; - maxBuffer?: number; - killSignal?: string; - }, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function exec(command: string, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], - callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function execFile(file: string, args?: string[], options?: { - cwd?: string; - stdio?: any; - customFds?: any; - env?: any; - encoding?: string; - timeout?: number; - maxBuffer?: string; - killSignal?: string; - }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; - export function fork(modulePath: string, args?: string[], options?: { - cwd?: string; - env?: any; - encoding?: string; - }): ChildProcess; -} - -declare module "url" { - export interface Url { - href: string; - protocol: string; - auth: string; - hostname: string; - port: string; - host: string; - pathname: string; - search: string; - query: any; // string | Object - slashes: boolean; - hash?: string; - path?: string; - } - - export interface UrlOptions { - protocol?: string; - auth?: string; - hostname?: string; - port?: string; - host?: string; - pathname?: string; - search?: string; - query?: any; - hash?: string; - path?: string; - } - - export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; - export function format(url: UrlOptions): string; - export function resolve(from: string, to: string): string; -} - -declare module "dns" { - export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; - export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; - export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; - export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; -} - -declare module "net" { - import stream = require("stream"); - - export interface Socket extends stream.Duplex { - // Extended base methods - write(buffer: Buffer): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - write(str: string, encoding?: string, fd?: string): boolean; - - connect(port: number, host?: string, connectionListener?: Function): void; - connect(path: string, connectionListener?: Function): void; - bufferSize: number; - setEncoding(encoding?: string): void; - write(data: any, encoding?: string, callback?: Function): void; - destroy(): void; - pause(): void; - resume(): void; - setTimeout(timeout: number, callback?: Function): void; - setNoDelay(noDelay?: boolean): void; - setKeepAlive(enable?: boolean, initialDelay?: number): void; - address(): { port: number; family: string; address: string; }; - unref(): void; - ref(): void; - - remoteAddress: string; - remotePort: number; - bytesRead: number; - bytesWritten: number; - - // Extended base methods - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - end(data?: any, encoding?: string): void; - } - - export var Socket: { - new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; - }; - - export interface Server extends Socket { - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - close(callback?: Function): Server; - address(): { port: number; family: string; address: string; }; - maxConnections: number; - connections: number; - } - export function createServer(connectionListener?: (socket: Socket) =>void ): Server; - export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; - export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function connect(port: number, host?: string, connectionListener?: Function): Socket; - export function connect(path: string, connectionListener?: Function): Socket; - export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; - export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; - export function createConnection(path: string, connectionListener?: Function): Socket; - export function isIP(input: string): number; - export function isIPv4(input: string): boolean; - export function isIPv6(input: string): boolean; -} - -declare module "dgram" { - import events = require("events"); - - interface RemoteInfo { - address: string; - port: number; - size: number; - } - - interface AddressInfo { - address: string; - family: string; - port: number; - } - - export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; - - interface Socket extends events.EventEmitter { - send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; - bind(port: number, address?: string, callback?: () => void): void; - close(): void; - address(): AddressInfo; - setBroadcast(flag: boolean): void; - setMulticastTTL(ttl: number): void; - setMulticastLoopback(flag: boolean): void; - addMembership(multicastAddress: string, multicastInterface?: string): void; - dropMembership(multicastAddress: string, multicastInterface?: string): void; - } -} - -declare module "fs" { - import stream = require("stream"); - import events = require("events"); - - interface Stats { - isFile(): boolean; - isDirectory(): boolean; - isBlockDevice(): boolean; - isCharacterDevice(): boolean; - isSymbolicLink(): boolean; - isFIFO(): boolean; - isSocket(): boolean; - dev: number; - ino: number; - mode: number; - nlink: number; - uid: number; - gid: number; - rdev: number; - size: number; - blksize: number; - blocks: number; - atime: Date; - mtime: Date; - ctime: Date; - } - - interface FSWatcher extends events.EventEmitter { - close(): void; - } - - export interface ReadStream extends stream.Readable { - close(): void; - } - export interface WriteStream extends stream.Writable { - close(): void; - } - - export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function renameSync(oldPath: string, newPath: string): void; - export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function truncateSync(path: string, len?: number): void; - export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function ftruncateSync(fd: number, len?: number): void; - export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chownSync(path: string, uid: number, gid: number): void; - export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchownSync(fd: number, uid: number, gid: number): void; - export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchownSync(path: string, uid: number, gid: number): void; - export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function chmodSync(path: string, mode: number): void; - export function chmodSync(path: string, mode: string): void; - export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fchmodSync(fd: number, mode: number): void; - export function fchmodSync(fd: number, mode: string): void; - export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function lchmodSync(path: string, mode: number): void; - export function lchmodSync(path: string, mode: string): void; - export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; - export function statSync(path: string): Stats; - export function lstatSync(path: string): Stats; - export function fstatSync(fd: number): Stats; - export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function linkSync(srcpath: string, dstpath: string): void; - export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; - export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; - export function readlinkSync(path: string): string; - export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; - export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; - export function realpathSync(path: string, cache?: {[path: string]: string}): string; - export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function unlinkSync(path: string): void; - export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function rmdirSync(path: string): void; - export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function mkdirSync(path: string, mode?: number): void; - export function mkdirSync(path: string, mode?: string): void; - export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; - export function readdirSync(path: string): string[]; - export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function closeSync(fd: number): void; - export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; - export function openSync(path: string, flags: string, mode?: number): number; - export function openSync(path: string, flags: string, mode?: string): number; - export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function utimesSync(path: string, atime: number, mtime: number): void; - export function utimesSync(path: string, atime: Date, mtime: Date): void; - export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function futimesSync(fd: number, atime: number, mtime: number): void; - export function futimesSync(fd: number, atime: Date, mtime: Date): void; - export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; - export function fsyncSync(fd: number): void; - export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; - export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; - export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; - export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; - export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; - export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; - export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; - export function readFileSync(filename: string, encoding: string): string; - export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; - export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; - export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; - export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; - export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; - export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; - export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; - export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; - export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; - export function exists(path: string, callback?: (exists: boolean) => void): void; - export function existsSync(path: string): boolean; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: number; - bufferSize?: number; - }): ReadStream; - export function createReadStream(path: string, options?: { - flags?: string; - encoding?: string; - fd?: string; - mode?: string; - bufferSize?: number; - }): ReadStream; - export function createWriteStream(path: string, options?: { - flags?: string; - encoding?: string; - string?: string; - }): WriteStream; -} - -declare module "path" { - export function normalize(p: string): string; - export function join(...paths: any[]): string; - export function resolve(...pathSegments: any[]): string; - export function relative(from: string, to: string): string; - export function dirname(p: string): string; - export function basename(p: string, ext?: string): string; - export function extname(p: string): string; - export var sep: string; -} - -declare module "string_decoder" { - export interface NodeStringDecoder { - write(buffer: Buffer): string; - detectIncompleteChar(buffer: Buffer): number; - } - export var StringDecoder: { - new (encoding: string): NodeStringDecoder; - }; -} - -declare module "tls" { - import crypto = require("crypto"); - import net = require("net"); - import stream = require("stream"); - - var CLIENT_RENEG_LIMIT: number; - var CLIENT_RENEG_WINDOW: number; - - export interface TlsOptions { - pfx?: any; //string or buffer - key?: any; //string or buffer - passphrase?: string; - cert?: any; - ca?: any; //string or buffer - crl?: any; //string or string array - ciphers?: string; - honorCipherOrder?: any; - requestCert?: boolean; - rejectUnauthorized?: boolean; - NPNProtocols?: any; //array or Buffer; - SNICallback?: (servername: string) => any; - } - - export interface ConnectionOptions { - host?: string; - port?: number; - socket?: net.Socket; - pfx?: any; //string | Buffer - key?: any; //string | Buffer - passphrase?: string; - cert?: any; //string | Buffer - ca?: any; //Array of string | Buffer - rejectUnauthorized?: boolean; - NPNProtocols?: any; //Array of string | Buffer - servername?: string; - } - - export interface Server extends net.Server { - // Extended base methods - listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; - listen(path: string, listeningListener?: Function): Server; - listen(handle: any, listeningListener?: Function): Server; - - listen(port: number, host?: string, callback?: Function): Server; - close(): Server; - address(): { port: number; family: string; address: string; }; - addContext(hostName: string, credentials: { - key: string; - cert: string; - ca: string; - }): void; - maxConnections: number; - connections: number; - } - - export interface ClearTextStream extends stream.Duplex { - authorized: boolean; - authorizationError: Error; - getPeerCertificate(): any; - getCipher: { - name: string; - version: string; - }; - address: { - port: number; - family: string; - address: string; - }; - remoteAddress: string; - remotePort: number; - } - - export interface SecurePair { - encrypted: any; - cleartext: any; - } - - export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; - export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; - export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; - export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; -} - -declare module "crypto" { - export interface CredentialDetails { - pfx: string; - key: string; - passphrase: string; - cert: string; - ca: any; //string | string array - crl: any; //string | string array - ciphers: string; - } - export interface Credentials { context?: any; } - export function createCredentials(details: CredentialDetails): Credentials; - export function createHash(algorithm: string): Hash; - export function createHmac(algorithm: string, key: string): Hmac; - export function createHmac(algorithm: string, key: Buffer): Hmac; - interface Hash { - update(data: any, input_encoding?: string): Hash; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; - digest(): Buffer; - } - interface Hmac { - update(data: any, input_encoding?: string): Hmac; - digest(encoding: 'buffer'): Buffer; - digest(encoding: string): any; - digest(): Buffer; - } - export function createCipher(algorithm: string, password: any): Cipher; - export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; - interface Cipher { - update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; - } - export function createDecipher(algorithm: string, password: any): Decipher; - export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; - interface Decipher { - update(data: Buffer): Buffer; - update(data: string, input_encoding?: string, output_encoding?: string): string; - final(): Buffer; - final(output_encoding: string): string; - setAutoPadding(auto_padding: boolean): void; - } - export function createSign(algorithm: string): Signer; - interface Signer { - update(data: any): void; - sign(private_key: string, output_format: string): string; - } - export function createVerify(algorith: string): Verify; - interface Verify { - update(data: any): void; - verify(object: string, signature: string, signature_format?: string): boolean; - } - export function createDiffieHellman(prime_length: number): DiffieHellman; - export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; - interface DiffieHellman { - generateKeys(encoding?: string): string; - computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; - getPrime(encoding?: string): string; - getGenerator(encoding: string): string; - getPublicKey(encoding?: string): string; - getPrivateKey(encoding?: string): string; - setPublicKey(public_key: string, encoding?: string): void; - setPrivateKey(public_key: string, encoding?: string): void; - } - export function getDiffieHellman(group_name: string): DiffieHellman; - export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; - export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; - export function randomBytes(size: number): Buffer; - export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; - export function pseudoRandomBytes(size: number): Buffer; - export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; -} - -declare module "stream" { - import events = require("events"); - - export interface Stream extends events.EventEmitter { - pipe(destination: T, options?: { end?: boolean; }): T; - } - - export interface ReadableOptions { - highWaterMark?: number; - encoding?: string; - objectMode?: boolean; - } - - export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { - readable: boolean; - constructor(opts?: ReadableOptions); - _read(size: number): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - } - - export interface WritableOptions { - highWaterMark?: number; - decodeStrings?: boolean; - } - - export class Writable extends events.EventEmitter implements NodeJS.WritableStream { - writable: boolean; - constructor(opts?: WritableOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface DuplexOptions extends ReadableOptions, WritableOptions { - allowHalfOpen?: boolean; - } - - // Note: Duplex extends both Readable and Writable. - export class Duplex extends Readable implements NodeJS.ReadWriteStream { - writable: boolean; - constructor(opts?: DuplexOptions); - _write(data: Buffer, encoding: string, callback: Function): void; - _write(data: string, encoding: string, callback: Function): void; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export interface TransformOptions extends ReadableOptions, WritableOptions {} - - // Note: Transform lacks the _read and _write methods of Readable/Writable. - export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { - readable: boolean; - writable: boolean; - constructor(opts?: TransformOptions); - _transform(chunk: Buffer, encoding: string, callback: Function): void; - _transform(chunk: string, encoding: string, callback: Function): void; - _flush(callback: Function): void; - read(size?: number): any; - setEncoding(encoding: string): void; - pause(): void; - resume(): void; - pipe(destination: T, options?: { end?: boolean; }): T; - unpipe(destination?: T): void; - unshift(chunk: string): void; - unshift(chunk: Buffer): void; - wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; - push(chunk: any, encoding?: string): boolean; - write(buffer: Buffer, cb?: Function): boolean; - write(str: string, cb?: Function): boolean; - write(str: string, encoding?: string, cb?: Function): boolean; - end(): void; - end(buffer: Buffer, cb?: Function): void; - end(str: string, cb?: Function): void; - end(str: string, encoding?: string, cb?: Function): void; - } - - export class PassThrough extends Transform {} -} - -declare module "util" { - export interface InspectOptions { - showHidden?: boolean; - depth?: number; - colors?: boolean; - customInspect?: boolean; - } - - export function format(format: any, ...param: any[]): string; - export function debug(string: string): void; - export function error(...param: any[]): void; - export function puts(...param: any[]): void; - export function print(...param: any[]): void; - export function log(string: string): void; - export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; - export function inspect(object: any, options: InspectOptions): string; - export function isArray(object: any): boolean; - export function isRegExp(object: any): boolean; - export function isDate(object: any): boolean; - export function isError(object: any): boolean; - export function inherits(constructor: any, superConstructor: any): void; -} - -declare module "assert" { - function internal (value: any, message?: string): void; - module internal { - export class AssertionError implements Error { - name: string; - message: string; - actual: any; - expected: any; - operator: string; - generatedMessage: boolean; - - constructor(options?: {message?: string; actual?: any; expected?: any; - operator?: string; stackStartFunction?: Function}); - } - - export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; - export function ok(value: any, message?: string): void; - export function equal(actual: any, expected: any, message?: string): void; - export function notEqual(actual: any, expected: any, message?: string): void; - export function deepEqual(actual: any, expected: any, message?: string): void; - export function notDeepEqual(acutal: any, expected: any, message?: string): void; - export function strictEqual(actual: any, expected: any, message?: string): void; - export function notStrictEqual(actual: any, expected: any, message?: string): void; - export var throws: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export var doesNotThrow: { - (block: Function, message?: string): void; - (block: Function, error: Function, message?: string): void; - (block: Function, error: RegExp, message?: string): void; - (block: Function, error: (err: any) => boolean, message?: string): void; - }; - - export function ifError(value: any): void; - } - - export = internal; -} - -declare module "tty" { - import net = require("net"); - - export function isatty(fd: number): boolean; - export interface ReadStream extends net.Socket { - isRaw: boolean; - setRawMode(mode: boolean): void; - } - export interface WriteStream extends net.Socket { - columns: number; - rows: number; - } -} - -declare module "domain" { - import events = require("events"); - - export class Domain extends events.EventEmitter { - run(fn: Function): void; - add(emitter: events.EventEmitter): void; - remove(emitter: events.EventEmitter): void; - bind(cb: (err: Error, data: any) => any): any; - intercept(cb: (data: any) => any): any; - dispose(): void; - - addListener(event: string, listener: Function): Domain; - on(event: string, listener: Function): Domain; - once(event: string, listener: Function): Domain; - removeListener(event: string, listener: Function): Domain; - removeAllListeners(event?: string): Domain; - } - - export function create(): Domain; -} +// Type definitions for Node.js v0.12.0 +// Project: http://nodejs.org/ +// Definitions by: Microsoft TypeScript , DefinitelyTyped +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/************************************************ +* * +* Node.js v0.12.0 API * +* * +************************************************/ + +/************************************************ +* * +* GLOBAL * +* * +************************************************/ +declare var process: NodeJS.Process; +declare var global: any; + +declare var __filename: string; +declare var __dirname: string; + +declare function setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearTimeout(timeoutId: NodeJS.Timer): void; +declare function setInterval(callback: (...args: any[]) => void, ms: number, ...args: any[]): NodeJS.Timer; +declare function clearInterval(intervalId: NodeJS.Timer): void; +declare function setImmediate(callback: (...args: any[]) => void, ...args: any[]): any; +declare function clearImmediate(immediateId: any): void; + +declare var require: { + (id: string): any; + resolve(id:string): string; + cache: any; + extensions: any; + main: any; +}; + +declare var module: { + exports: any; + require(id: string): any; + id: string; + filename: string; + loaded: boolean; + parent: any; + children: any[]; +}; + +// Same as module.exports +declare var exports: any; +declare var SlowBuffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + + +// Buffer class +interface Buffer extends NodeBuffer {} +declare var Buffer: { + new (str: string, encoding?: string): Buffer; + new (size: number): Buffer; + new (size: Uint8Array): Buffer; + new (array: any[]): Buffer; + prototype: Buffer; + isBuffer(obj: any): boolean; + byteLength(string: string, encoding?: string): number; + concat(list: Buffer[], totalLength?: number): Buffer; +}; + +/************************************************ +* * +* GLOBAL INTERFACES * +* * +************************************************/ +declare module NodeJS { + export interface ErrnoException extends Error { + errno?: any; + code?: string; + path?: string; + syscall?: string; + } + + export interface EventEmitter { + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } + + export interface ReadableStream extends EventEmitter { + readable: boolean; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: ReadableStream): ReadableStream; + } + + export interface WritableStream extends EventEmitter { + writable: boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface ReadWriteStream extends ReadableStream, WritableStream {} + + export interface Process extends EventEmitter { + stdout: WritableStream; + stderr: WritableStream; + stdin: ReadableStream; + argv: string[]; + execPath: string; + abort(): void; + chdir(directory: string): void; + cwd(): string; + env: any; + exit(code?: number): void; + getgid(): number; + setgid(id: number): void; + setgid(id: string): void; + getuid(): number; + setuid(id: number): void; + setuid(id: string): void; + version: string; + versions: { + http_parser: string; + node: string; + v8: string; + ares: string; + uv: string; + zlib: string; + openssl: string; + }; + config: { + target_defaults: { + cflags: any[]; + default_configuration: string; + defines: string[]; + include_dirs: string[]; + libraries: string[]; + }; + variables: { + clang: number; + host_arch: string; + node_install_npm: boolean; + node_install_waf: boolean; + node_prefix: string; + node_shared_openssl: boolean; + node_shared_v8: boolean; + node_shared_zlib: boolean; + node_use_dtrace: boolean; + node_use_etw: boolean; + node_use_openssl: boolean; + target_arch: string; + v8_no_strict_aliasing: number; + v8_use_snapshot: boolean; + visibility: string; + }; + }; + kill(pid: number, signal?: string): void; + pid: number; + title: string; + arch: string; + platform: string; + memoryUsage(): { rss: number; heapTotal: number; heapUsed: number; }; + nextTick(callback: Function): void; + umask(mask?: number): number; + uptime(): number; + hrtime(time?:number[]): number[]; + + // Worker + send?(message: any, sendHandle?: any): void; + } + + export interface Timer { + ref() : void; + unref() : void; + } +} + +/** + * @deprecated + */ +interface NodeBuffer { + [index: number]: number; + write(string: string, offset?: number, length?: number, encoding?: string): number; + toString(encoding?: string, start?: number, end?: number): string; + toJSON(): any; + length: number; + copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; + slice(start?: number, end?: number): Buffer; + readUInt8(offset: number, noAsset?: boolean): number; + readUInt16LE(offset: number, noAssert?: boolean): number; + readUInt16BE(offset: number, noAssert?: boolean): number; + readUInt32LE(offset: number, noAssert?: boolean): number; + readUInt32BE(offset: number, noAssert?: boolean): number; + readInt8(offset: number, noAssert?: boolean): number; + readInt16LE(offset: number, noAssert?: boolean): number; + readInt16BE(offset: number, noAssert?: boolean): number; + readInt32LE(offset: number, noAssert?: boolean): number; + readInt32BE(offset: number, noAssert?: boolean): number; + readFloatLE(offset: number, noAssert?: boolean): number; + readFloatBE(offset: number, noAssert?: boolean): number; + readDoubleLE(offset: number, noAssert?: boolean): number; + readDoubleBE(offset: number, noAssert?: boolean): number; + writeUInt8(value: number, offset: number, noAssert?: boolean): void; + writeUInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeUInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeInt8(value: number, offset: number, noAssert?: boolean): void; + writeInt16LE(value: number, offset: number, noAssert?: boolean): void; + writeInt16BE(value: number, offset: number, noAssert?: boolean): void; + writeInt32LE(value: number, offset: number, noAssert?: boolean): void; + writeInt32BE(value: number, offset: number, noAssert?: boolean): void; + writeFloatLE(value: number, offset: number, noAssert?: boolean): void; + writeFloatBE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleLE(value: number, offset: number, noAssert?: boolean): void; + writeDoubleBE(value: number, offset: number, noAssert?: boolean): void; + fill(value: any, offset?: number, end?: number): void; +} + +/************************************************ +* * +* MODULES * +* * +************************************************/ +declare module "buffer" { + export var INSPECT_MAX_BYTES: number; +} + +declare module "querystring" { + export function stringify(obj: any, sep?: string, eq?: string): string; + export function parse(str: string, sep?: string, eq?: string, options?: { maxKeys?: number; }): any; + export function escape(): any; + export function unescape(): any; +} + +declare module "events" { + export class EventEmitter implements NodeJS.EventEmitter { + static listenerCount(emitter: EventEmitter, event: string): number; + + addListener(event: string, listener: Function): EventEmitter; + on(event: string, listener: Function): EventEmitter; + once(event: string, listener: Function): EventEmitter; + removeListener(event: string, listener: Function): EventEmitter; + removeAllListeners(event?: string): EventEmitter; + setMaxListeners(n: number): void; + listeners(event: string): Function[]; + emit(event: string, ...args: any[]): boolean; + } +} + +declare module "http" { + import events = require("events"); + import net = require("net"); + import stream = require("stream"); + + export interface Server extends events.EventEmitter { + listen(port: number, hostname?: string, backlog?: number, callback?: Function): Server; + listen(path: string, callback?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(cb?: any): Server; + address(): { port: number; family: string; address: string; }; + maxHeadersCount: number; + } + export interface ServerRequest extends events.EventEmitter, stream.Readable { + method: string; + url: string; + headers: any; + trailers: string; + httpVersion: string; + setEncoding(encoding?: string): void; + pause(): void; + resume(): void; + connection: net.Socket; + } + export interface ServerResponse extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + writeContinue(): void; + writeHead(statusCode: number, reasonPhrase?: string, headers?: any): void; + writeHead(statusCode: number, headers?: any): void; + statusCode: number; + setHeader(name: string, value: string): void; + sendDate: boolean; + getHeader(name: string): string; + removeHeader(name: string): void; + write(chunk: any, encoding?: string): any; + addTrailers(headers: any): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface ClientRequest extends events.EventEmitter, stream.Writable { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + write(chunk: any, encoding?: string): void; + abort(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + export interface ClientResponse extends events.EventEmitter, stream.Readable { + statusCode: number; + httpVersion: string; + headers: any; + trailers: any; + setEncoding(encoding?: string): void; + pause(): void; + resume(): void; + } + export interface Agent { maxSockets: number; sockets: any; requests: any; } + + export var STATUS_CODES: { + [errorCode: number]: string; + [errorCode: string]: string; + }; + export function createServer(requestListener?: (request: ServerRequest, response: ServerResponse) =>void ): Server; + export function createClient(port?: number, host?: string): any; + export function request(options: any, callback?: Function): ClientRequest; + export function get(options: any, callback?: Function): ClientRequest; + export var globalAgent: Agent; +} + +declare module "cluster" { + import child = require("child_process"); + import events = require("events"); + + export interface ClusterSettings { + exec?: string; + args?: string[]; + silent?: boolean; + } + + export class Worker extends events.EventEmitter { + id: string; + process: child.ChildProcess; + suicide: boolean; + send(message: any, sendHandle?: any): void; + kill(signal?: string): void; + destroy(signal?: string): void; + disconnect(): void; + } + + export var settings: ClusterSettings; + export var isMaster: boolean; + export var isWorker: boolean; + export function setupMaster(settings?: ClusterSettings): void; + export function fork(env?: any): Worker; + export function disconnect(callback?: Function): void; + export var worker: Worker; + export var workers: Worker[]; + + // Event emitter + export function addListener(event: string, listener: Function): void; + export function on(event: string, listener: Function): any; + export function once(event: string, listener: Function): void; + export function removeListener(event: string, listener: Function): void; + export function removeAllListeners(event?: string): void; + export function setMaxListeners(n: number): void; + export function listeners(event: string): Function[]; + export function emit(event: string, ...args: any[]): boolean; +} + +declare module "zlib" { + import stream = require("stream"); + export interface ZlibOptions { chunkSize?: number; windowBits?: number; level?: number; memLevel?: number; strategy?: number; dictionary?: any; } + + export interface Gzip extends stream.Transform { } + export interface Gunzip extends stream.Transform { } + export interface Deflate extends stream.Transform { } + export interface Inflate extends stream.Transform { } + export interface DeflateRaw extends stream.Transform { } + export interface InflateRaw extends stream.Transform { } + export interface Unzip extends stream.Transform { } + + export function createGzip(options?: ZlibOptions): Gzip; + export function createGunzip(options?: ZlibOptions): Gunzip; + export function createDeflate(options?: ZlibOptions): Deflate; + export function createInflate(options?: ZlibOptions): Inflate; + export function createDeflateRaw(options?: ZlibOptions): DeflateRaw; + export function createInflateRaw(options?: ZlibOptions): InflateRaw; + export function createUnzip(options?: ZlibOptions): Unzip; + + export function deflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function deflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function gunzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflate(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function inflateRaw(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + export function unzip(buf: Buffer, callback: (error: Error, result: any) =>void ): void; + + // Constants + export var Z_NO_FLUSH: number; + export var Z_PARTIAL_FLUSH: number; + export var Z_SYNC_FLUSH: number; + export var Z_FULL_FLUSH: number; + export var Z_FINISH: number; + export var Z_BLOCK: number; + export var Z_TREES: number; + export var Z_OK: number; + export var Z_STREAM_END: number; + export var Z_NEED_DICT: number; + export var Z_ERRNO: number; + export var Z_STREAM_ERROR: number; + export var Z_DATA_ERROR: number; + export var Z_MEM_ERROR: number; + export var Z_BUF_ERROR: number; + export var Z_VERSION_ERROR: number; + export var Z_NO_COMPRESSION: number; + export var Z_BEST_SPEED: number; + export var Z_BEST_COMPRESSION: number; + export var Z_DEFAULT_COMPRESSION: number; + export var Z_FILTERED: number; + export var Z_HUFFMAN_ONLY: number; + export var Z_RLE: number; + export var Z_FIXED: number; + export var Z_DEFAULT_STRATEGY: number; + export var Z_BINARY: number; + export var Z_TEXT: number; + export var Z_ASCII: number; + export var Z_UNKNOWN: number; + export var Z_DEFLATED: number; + export var Z_NULL: number; +} + +declare module "os" { + export function tmpdir(): string; + export function hostname(): string; + export function type(): string; + export function platform(): string; + export function arch(): string; + export function release(): string; + export function uptime(): number; + export function loadavg(): number[]; + export function totalmem(): number; + export function freemem(): number; + export function cpus(): { model: string; speed: number; times: { user: number; nice: number; sys: number; idle: number; irq: number; }; }[]; + export function networkInterfaces(): any; + export var EOL: string; +} + +declare module "https" { + import tls = require("tls"); + import events = require("events"); + import http = require("http"); + + export interface ServerOptions { + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + crl?: any; + ciphers?: string; + honorCipherOrder?: boolean; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; + SNICallback?: (servername: string) => any; + } + + export interface RequestOptions { + host?: string; + hostname?: string; + port?: number; + path?: string; + method?: string; + headers?: any; + auth?: string; + agent?: any; + pfx?: any; + key?: any; + passphrase?: string; + cert?: any; + ca?: any; + ciphers?: string; + rejectUnauthorized?: boolean; + } + + export interface Agent { + maxSockets: number; + sockets: any; + requests: any; + } + export var Agent: { + new (options?: RequestOptions): Agent; + }; + export interface Server extends tls.Server { } + export function createServer(options: ServerOptions, requestListener?: Function): Server; + export function request(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; + export function get(options: RequestOptions, callback?: (res: http.ClientResponse) =>void ): http.ClientRequest; + export var globalAgent: Agent; +} + +declare module "punycode" { + export function decode(string: string): string; + export function encode(string: string): string; + export function toUnicode(domain: string): string; + export function toASCII(domain: string): string; + export var ucs2: ucs2; + interface ucs2 { + decode(string: string): string; + encode(codePoints: number[]): string; + } + export var version: any; +} + +declare module "repl" { + import stream = require("stream"); + import events = require("events"); + + export interface ReplOptions { + prompt?: string; + input?: NodeJS.ReadableStream; + output?: NodeJS.WritableStream; + terminal?: boolean; + eval?: Function; + useColors?: boolean; + useGlobal?: boolean; + ignoreUndefined?: boolean; + writer?: Function; + } + export function start(options: ReplOptions): events.EventEmitter; +} + +declare module "readline" { + import events = require("events"); + import stream = require("stream"); + + export interface ReadLine extends events.EventEmitter { + setPrompt(prompt: string, length: number): void; + prompt(preserveCursor?: boolean): void; + question(query: string, callback: Function): void; + pause(): void; + resume(): void; + close(): void; + write(data: any, key?: any): void; + } + export interface ReadLineOptions { + input: NodeJS.ReadableStream; + output: NodeJS.WritableStream; + completer?: Function; + terminal?: boolean; + } + export function createInterface(options: ReadLineOptions): ReadLine; +} + +declare module "vm" { + export interface Context { } + export interface Script { + runInThisContext(): void; + runInNewContext(sandbox?: Context): void; + } + export function runInThisContext(code: string, filename?: string): void; + export function runInNewContext(code: string, sandbox?: Context, filename?: string): void; + export function runInContext(code: string, context: Context, filename?: string): void; + export function createContext(initSandbox?: Context): Context; + export function createScript(code: string, filename?: string): Script; +} + +declare module "child_process" { + import events = require("events"); + import stream = require("stream"); + + export interface ChildProcess extends events.EventEmitter { + stdin: stream.Writable; + stdout: stream.Readable; + stderr: stream.Readable; + pid: number; + kill(signal?: string): void; + send(message: any, sendHandle: any): void; + disconnect(): void; + } + + export function spawn(command: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + custom?: any; + env?: any; + detached?: boolean; + }): ChildProcess; + export function exec(command: string, options: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + }, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function exec(command: string, callback: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], + callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function execFile(file: string, args?: string[], options?: { + cwd?: string; + stdio?: any; + customFds?: any; + env?: any; + encoding?: string; + timeout?: number; + maxBuffer?: string; + killSignal?: string; + }, callback?: (error: Error, stdout: Buffer, stderr: Buffer) =>void ): ChildProcess; + export function fork(modulePath: string, args?: string[], options?: { + cwd?: string; + env?: any; + encoding?: string; + }): ChildProcess; +} + +declare module "url" { + export interface Url { + href: string; + protocol: string; + auth: string; + hostname: string; + port: string; + host: string; + pathname: string; + search: string; + query: any; // string | Object + slashes: boolean; + hash?: string; + path?: string; + } + + export interface UrlOptions { + protocol?: string; + auth?: string; + hostname?: string; + port?: string; + host?: string; + pathname?: string; + search?: string; + query?: any; + hash?: string; + path?: string; + } + + export function parse(urlStr: string, parseQueryString?: boolean , slashesDenoteHost?: boolean ): Url; + export function format(url: UrlOptions): string; + export function resolve(from: string, to: string): string; +} + +declare module "dns" { + export function lookup(domain: string, family: number, callback: (err: Error, address: string, family: number) =>void ): string; + export function lookup(domain: string, callback: (err: Error, address: string, family: number) =>void ): string; + export function resolve(domain: string, rrtype: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve4(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolve6(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveMx(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveTxt(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveSrv(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveNs(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function resolveCname(domain: string, callback: (err: Error, addresses: string[]) =>void ): string[]; + export function reverse(ip: string, callback: (err: Error, domains: string[]) =>void ): string[]; +} + +declare module "net" { + import stream = require("stream"); + + export interface Socket extends stream.Duplex { + // Extended base methods + write(buffer: Buffer): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + write(str: string, encoding?: string, fd?: string): boolean; + + connect(port: number, host?: string, connectionListener?: Function): void; + connect(path: string, connectionListener?: Function): void; + bufferSize: number; + setEncoding(encoding?: string): void; + write(data: any, encoding?: string, callback?: Function): void; + destroy(): void; + pause(): void; + resume(): void; + setTimeout(timeout: number, callback?: Function): void; + setNoDelay(noDelay?: boolean): void; + setKeepAlive(enable?: boolean, initialDelay?: number): void; + address(): { port: number; family: string; address: string; }; + unref(): void; + ref(): void; + + remoteAddress: string; + remotePort: number; + bytesRead: number; + bytesWritten: number; + + // Extended base methods + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + end(data?: any, encoding?: string): void; + } + + export var Socket: { + new (options?: { fd?: string; type?: string; allowHalfOpen?: boolean; }): Socket; + }; + + export interface Server extends Socket { + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + close(callback?: Function): Server; + address(): { port: number; family: string; address: string; }; + maxConnections: number; + connections: number; + } + export function createServer(connectionListener?: (socket: Socket) =>void ): Server; + export function createServer(options?: { allowHalfOpen?: boolean; }, connectionListener?: (socket: Socket) =>void ): Server; + export function connect(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function connect(port: number, host?: string, connectionListener?: Function): Socket; + export function connect(path: string, connectionListener?: Function): Socket; + export function createConnection(options: { allowHalfOpen?: boolean; }, connectionListener?: Function): Socket; + export function createConnection(port: number, host?: string, connectionListener?: Function): Socket; + export function createConnection(path: string, connectionListener?: Function): Socket; + export function isIP(input: string): number; + export function isIPv4(input: string): boolean; + export function isIPv6(input: string): boolean; +} + +declare module "dgram" { + import events = require("events"); + + interface RemoteInfo { + address: string; + port: number; + size: number; + } + + interface AddressInfo { + address: string; + family: string; + port: number; + } + + export function createSocket(type: string, callback?: (msg: Buffer, rinfo: RemoteInfo) => void): Socket; + + interface Socket extends events.EventEmitter { + send(buf: Buffer, offset: number, length: number, port: number, address: string, callback?: (error: Error, bytes: number) => void): void; + bind(port: number, address?: string, callback?: () => void): void; + close(): void; + address(): AddressInfo; + setBroadcast(flag: boolean): void; + setMulticastTTL(ttl: number): void; + setMulticastLoopback(flag: boolean): void; + addMembership(multicastAddress: string, multicastInterface?: string): void; + dropMembership(multicastAddress: string, multicastInterface?: string): void; + } +} + +declare module "fs" { + import stream = require("stream"); + import events = require("events"); + + interface Stats { + isFile(): boolean; + isDirectory(): boolean; + isBlockDevice(): boolean; + isCharacterDevice(): boolean; + isSymbolicLink(): boolean; + isFIFO(): boolean; + isSocket(): boolean; + dev: number; + ino: number; + mode: number; + nlink: number; + uid: number; + gid: number; + rdev: number; + size: number; + blksize: number; + blocks: number; + atime: Date; + mtime: Date; + ctime: Date; + } + + interface FSWatcher extends events.EventEmitter { + close(): void; + } + + export interface ReadStream extends stream.Readable { + close(): void; + } + export interface WriteStream extends stream.Writable { + close(): void; + } + + export function rename(oldPath: string, newPath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function renameSync(oldPath: string, newPath: string): void; + export function truncate(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncate(path: string, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function truncateSync(path: string, len?: number): void; + export function ftruncate(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncate(fd: number, len: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function ftruncateSync(fd: number, len?: number): void; + export function chown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chownSync(path: string, uid: number, gid: number): void; + export function fchown(fd: number, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchownSync(fd: number, uid: number, gid: number): void; + export function lchown(path: string, uid: number, gid: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchownSync(path: string, uid: number, gid: number): void; + export function chmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function chmodSync(path: string, mode: number): void; + export function chmodSync(path: string, mode: string): void; + export function fchmod(fd: number, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmod(fd: number, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fchmodSync(fd: number, mode: number): void; + export function fchmodSync(fd: number, mode: string): void; + export function lchmod(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmod(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function lchmodSync(path: string, mode: number): void; + export function lchmodSync(path: string, mode: string): void; + export function stat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function lstat(path: string, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function fstat(fd: number, callback?: (err: NodeJS.ErrnoException, stats: Stats) => any): void; + export function statSync(path: string): Stats; + export function lstatSync(path: string): Stats; + export function fstatSync(fd: number): Stats; + export function link(srcpath: string, dstpath: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function linkSync(srcpath: string, dstpath: string): void; + export function symlink(srcpath: string, dstpath: string, type?: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function symlinkSync(srcpath: string, dstpath: string, type?: string): void; + export function readlink(path: string, callback?: (err: NodeJS.ErrnoException, linkString: string) => any): void; + export function readlinkSync(path: string): string; + export function realpath(path: string, callback?: (err: NodeJS.ErrnoException, resolvedPath: string) => any): void; + export function realpath(path: string, cache: {[path: string]: string}, callback: (err: NodeJS.ErrnoException, resolvedPath: string) =>any): void; + export function realpathSync(path: string, cache?: {[path: string]: string}): string; + export function unlink(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function unlinkSync(path: string): void; + export function rmdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function rmdirSync(path: string): void; + export function mkdir(path: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdir(path: string, mode: string, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function mkdirSync(path: string, mode?: number): void; + export function mkdirSync(path: string, mode?: string): void; + export function readdir(path: string, callback?: (err: NodeJS.ErrnoException, files: string[]) => void): void; + export function readdirSync(path: string): string[]; + export function close(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function closeSync(fd: number): void; + export function open(path: string, flags: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: number, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function open(path: string, flags: string, mode: string, callback?: (err: NodeJS.ErrnoException, fd: number) => any): void; + export function openSync(path: string, flags: string, mode?: number): number; + export function openSync(path: string, flags: string, mode?: string): number; + export function utimes(path: string, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimes(path: string, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function utimesSync(path: string, atime: number, mtime: number): void; + export function utimesSync(path: string, atime: Date, mtime: Date): void; + export function futimes(fd: number, atime: number, mtime: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimes(fd: number, atime: Date, mtime: Date, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function futimesSync(fd: number, atime: number, mtime: number): void; + export function futimesSync(fd: number, atime: Date, mtime: Date): void; + export function fsync(fd: number, callback?: (err?: NodeJS.ErrnoException) => void): void; + export function fsyncSync(fd: number): void; + export function write(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, written: number, buffer: Buffer) => void): void; + export function writeSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function read(fd: number, buffer: Buffer, offset: number, length: number, position: number, callback?: (err: NodeJS.ErrnoException, bytesRead: number, buffer: Buffer) => void): void; + export function readSync(fd: number, buffer: Buffer, offset: number, length: number, position: number): number; + export function readFile(filename: string, encoding: string, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { encoding: string; flag?: string; }, callback: (err: NodeJS.ErrnoException, data: string) => void): void; + export function readFile(filename: string, options: { flag?: string; }, callback: (err: NodeJS.ErrnoException, data: Buffer) => void): void; + export function readFile(filename: string, callback: (err: NodeJS.ErrnoException, data: Buffer) => void ): void; + export function readFileSync(filename: string, encoding: string): string; + export function readFileSync(filename: string, options: { encoding: string; flag?: string; }): string; + export function readFileSync(filename: string, options?: { flag?: string; }): Buffer; + export function writeFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function writeFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: number; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, options: { encoding?: string; mode?: string; flag?: string; }, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFile(filename: string, data: any, callback?: (err: NodeJS.ErrnoException) => void): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: number; flag?: string; }): void; + export function appendFileSync(filename: string, data: any, options?: { encoding?: string; mode?: string; flag?: string; }): void; + export function watchFile(filename: string, listener: (curr: Stats, prev: Stats) => void): void; + export function watchFile(filename: string, options: { persistent?: boolean; interval?: number; }, listener: (curr: Stats, prev: Stats) => void): void; + export function unwatchFile(filename: string, listener?: (curr: Stats, prev: Stats) => void): void; + export function watch(filename: string, listener?: (event: string, filename: string) => any): FSWatcher; + export function watch(filename: string, options: { persistent?: boolean; }, listener?: (event: string, filename: string) => any): FSWatcher; + export function exists(path: string, callback?: (exists: boolean) => void): void; + export function existsSync(path: string): boolean; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: number; + bufferSize?: number; + }): ReadStream; + export function createReadStream(path: string, options?: { + flags?: string; + encoding?: string; + fd?: string; + mode?: string; + bufferSize?: number; + }): ReadStream; + export function createWriteStream(path: string, options?: { + flags?: string; + encoding?: string; + string?: string; + }): WriteStream; +} + +declare module "path" { + export function normalize(p: string): string; + export function join(...paths: any[]): string; + export function resolve(...pathSegments: any[]): string; + export function relative(from: string, to: string): string; + export function dirname(p: string): string; + export function basename(p: string, ext?: string): string; + export function extname(p: string): string; + export var sep: string; +} + +declare module "string_decoder" { + export interface NodeStringDecoder { + write(buffer: Buffer): string; + detectIncompleteChar(buffer: Buffer): number; + } + export var StringDecoder: { + new (encoding: string): NodeStringDecoder; + }; +} + +declare module "tls" { + import crypto = require("crypto"); + import net = require("net"); + import stream = require("stream"); + + var CLIENT_RENEG_LIMIT: number; + var CLIENT_RENEG_WINDOW: number; + + export interface TlsOptions { + pfx?: any; //string or buffer + key?: any; //string or buffer + passphrase?: string; + cert?: any; + ca?: any; //string or buffer + crl?: any; //string or string array + ciphers?: string; + honorCipherOrder?: any; + requestCert?: boolean; + rejectUnauthorized?: boolean; + NPNProtocols?: any; //array or Buffer; + SNICallback?: (servername: string) => any; + } + + export interface ConnectionOptions { + host?: string; + port?: number; + socket?: net.Socket; + pfx?: any; //string | Buffer + key?: any; //string | Buffer + passphrase?: string; + cert?: any; //string | Buffer + ca?: any; //Array of string | Buffer + rejectUnauthorized?: boolean; + NPNProtocols?: any; //Array of string | Buffer + servername?: string; + } + + export interface Server extends net.Server { + // Extended base methods + listen(port: number, host?: string, backlog?: number, listeningListener?: Function): Server; + listen(path: string, listeningListener?: Function): Server; + listen(handle: any, listeningListener?: Function): Server; + + listen(port: number, host?: string, callback?: Function): Server; + close(): Server; + address(): { port: number; family: string; address: string; }; + addContext(hostName: string, credentials: { + key: string; + cert: string; + ca: string; + }): void; + maxConnections: number; + connections: number; + } + + export interface ClearTextStream extends stream.Duplex { + authorized: boolean; + authorizationError: Error; + getPeerCertificate(): any; + getCipher: { + name: string; + version: string; + }; + address: { + port: number; + family: string; + address: string; + }; + remoteAddress: string; + remotePort: number; + } + + export interface SecurePair { + encrypted: any; + cleartext: any; + } + + export function createServer(options: TlsOptions, secureConnectionListener?: (cleartextStream: ClearTextStream) =>void ): Server; + export function connect(options: TlsOptions, secureConnectionListener?: () =>void ): ClearTextStream; + export function connect(port: number, host?: string, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function connect(port: number, options?: ConnectionOptions, secureConnectListener?: () =>void ): ClearTextStream; + export function createSecurePair(credentials?: crypto.Credentials, isServer?: boolean, requestCert?: boolean, rejectUnauthorized?: boolean): SecurePair; +} + +declare module "crypto" { + export interface CredentialDetails { + pfx: string; + key: string; + passphrase: string; + cert: string; + ca: any; //string | string array + crl: any; //string | string array + ciphers: string; + } + export interface Credentials { context?: any; } + export function createCredentials(details: CredentialDetails): Credentials; + export function createHash(algorithm: string): Hash; + export function createHmac(algorithm: string, key: string): Hmac; + export function createHmac(algorithm: string, key: Buffer): Hmac; + interface Hash { + update(data: any, input_encoding?: string): Hash; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + interface Hmac { + update(data: any, input_encoding?: string): Hmac; + digest(encoding: 'buffer'): Buffer; + digest(encoding: string): any; + digest(): Buffer; + } + export function createCipher(algorithm: string, password: any): Cipher; + export function createCipheriv(algorithm: string, key: any, iv: any): Cipher; + interface Cipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createDecipher(algorithm: string, password: any): Decipher; + export function createDecipheriv(algorithm: string, key: any, iv: any): Decipher; + interface Decipher { + update(data: Buffer): Buffer; + update(data: string, input_encoding?: string, output_encoding?: string): string; + final(): Buffer; + final(output_encoding: string): string; + setAutoPadding(auto_padding: boolean): void; + } + export function createSign(algorithm: string): Signer; + interface Signer { + update(data: any): void; + sign(private_key: string, output_format: string): string; + } + export function createVerify(algorith: string): Verify; + interface Verify { + update(data: any): void; + verify(object: string, signature: string, signature_format?: string): boolean; + } + export function createDiffieHellman(prime_length: number): DiffieHellman; + export function createDiffieHellman(prime: number, encoding?: string): DiffieHellman; + interface DiffieHellman { + generateKeys(encoding?: string): string; + computeSecret(other_public_key: string, input_encoding?: string, output_encoding?: string): string; + getPrime(encoding?: string): string; + getGenerator(encoding: string): string; + getPublicKey(encoding?: string): string; + getPrivateKey(encoding?: string): string; + setPublicKey(public_key: string, encoding?: string): void; + setPrivateKey(public_key: string, encoding?: string): void; + } + export function getDiffieHellman(group_name: string): DiffieHellman; + export function pbkdf2(password: string, salt: string, iterations: number, keylen: number, callback: (err: Error, derivedKey: Buffer) => any): void; + export function pbkdf2Sync(password: string, salt: string, iterations: number, keylen: number) : Buffer; + export function randomBytes(size: number): Buffer; + export function randomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; + export function pseudoRandomBytes(size: number): Buffer; + export function pseudoRandomBytes(size: number, callback: (err: Error, buf: Buffer) =>void ): void; +} + +declare module "stream" { + import events = require("events"); + + export interface Stream extends events.EventEmitter { + pipe(destination: T, options?: { end?: boolean; }): T; + } + + export interface ReadableOptions { + highWaterMark?: number; + encoding?: string; + objectMode?: boolean; + } + + export class Readable extends events.EventEmitter implements NodeJS.ReadableStream { + readable: boolean; + constructor(opts?: ReadableOptions); + _read(size: number): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + } + + export interface WritableOptions { + highWaterMark?: number; + decodeStrings?: boolean; + } + + export class Writable extends events.EventEmitter implements NodeJS.WritableStream { + writable: boolean; + constructor(opts?: WritableOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface DuplexOptions extends ReadableOptions, WritableOptions { + allowHalfOpen?: boolean; + } + + // Note: Duplex extends both Readable and Writable. + export class Duplex extends Readable implements NodeJS.ReadWriteStream { + writable: boolean; + constructor(opts?: DuplexOptions); + _write(data: Buffer, encoding: string, callback: Function): void; + _write(data: string, encoding: string, callback: Function): void; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export interface TransformOptions extends ReadableOptions, WritableOptions {} + + // Note: Transform lacks the _read and _write methods of Readable/Writable. + export class Transform extends events.EventEmitter implements NodeJS.ReadWriteStream { + readable: boolean; + writable: boolean; + constructor(opts?: TransformOptions); + _transform(chunk: Buffer, encoding: string, callback: Function): void; + _transform(chunk: string, encoding: string, callback: Function): void; + _flush(callback: Function): void; + read(size?: number): any; + setEncoding(encoding: string): void; + pause(): void; + resume(): void; + pipe(destination: T, options?: { end?: boolean; }): T; + unpipe(destination?: T): void; + unshift(chunk: string): void; + unshift(chunk: Buffer): void; + wrap(oldStream: NodeJS.ReadableStream): NodeJS.ReadableStream; + push(chunk: any, encoding?: string): boolean; + write(buffer: Buffer, cb?: Function): boolean; + write(str: string, cb?: Function): boolean; + write(str: string, encoding?: string, cb?: Function): boolean; + end(): void; + end(buffer: Buffer, cb?: Function): void; + end(str: string, cb?: Function): void; + end(str: string, encoding?: string, cb?: Function): void; + } + + export class PassThrough extends Transform {} +} + +declare module "util" { + export interface InspectOptions { + showHidden?: boolean; + depth?: number; + colors?: boolean; + customInspect?: boolean; + } + + export function format(format: any, ...param: any[]): string; + export function debug(string: string): void; + export function error(...param: any[]): void; + export function puts(...param: any[]): void; + export function print(...param: any[]): void; + export function log(string: string): void; + export function inspect(object: any, showHidden?: boolean, depth?: number, color?: boolean): string; + export function inspect(object: any, options: InspectOptions): string; + export function isArray(object: any): boolean; + export function isRegExp(object: any): boolean; + export function isDate(object: any): boolean; + export function isError(object: any): boolean; + export function inherits(constructor: any, superConstructor: any): void; +} + +declare module "assert" { + function internal (value: any, message?: string): void; + module internal { + export class AssertionError implements Error { + name: string; + message: string; + actual: any; + expected: any; + operator: string; + generatedMessage: boolean; + + constructor(options?: {message?: string; actual?: any; expected?: any; + operator?: string; stackStartFunction?: Function}); + } + + export function fail(actual?: any, expected?: any, message?: string, operator?: string): void; + export function ok(value: any, message?: string): void; + export function equal(actual: any, expected: any, message?: string): void; + export function notEqual(actual: any, expected: any, message?: string): void; + export function deepEqual(actual: any, expected: any, message?: string): void; + export function notDeepEqual(acutal: any, expected: any, message?: string): void; + export function strictEqual(actual: any, expected: any, message?: string): void; + export function notStrictEqual(actual: any, expected: any, message?: string): void; + export var throws: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export var doesNotThrow: { + (block: Function, message?: string): void; + (block: Function, error: Function, message?: string): void; + (block: Function, error: RegExp, message?: string): void; + (block: Function, error: (err: any) => boolean, message?: string): void; + }; + + export function ifError(value: any): void; + } + + export = internal; +} + +declare module "tty" { + import net = require("net"); + + export function isatty(fd: number): boolean; + export interface ReadStream extends net.Socket { + isRaw: boolean; + setRawMode(mode: boolean): void; + } + export interface WriteStream extends net.Socket { + columns: number; + rows: number; + } +} + +declare module "domain" { + import events = require("events"); + + export class Domain extends events.EventEmitter { + run(fn: Function): void; + add(emitter: events.EventEmitter): void; + remove(emitter: events.EventEmitter): void; + bind(cb: (err: Error, data: any) => any): any; + intercept(cb: (data: any) => any): any; + dispose(): void; + + addListener(event: string, listener: Function): Domain; + on(event: string, listener: Function): Domain; + once(event: string, listener: Function): Domain; + removeListener(event: string, listener: Function): Domain; + removeAllListeners(event?: string): Domain; + } + + export function create(): Domain; +} diff --git a/package.json b/package.json index d10330db4..10d5c872a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "private": true, "name": "DefinitelyTyped", "version": "0.0.1", - "private": true, "homepage": "https://github.com/borisyankov/DefinitelyTyped", "repository": { "type": "git", diff --git a/page/page.d.ts b/page/page.d.ts index c77e85654..024639185 100644 --- a/page/page.d.ts +++ b/page/page.d.ts @@ -211,4 +211,6 @@ declare module PageJS { declare module "page" { var page: PageJS.Static; export = page; -} \ No newline at end of file +} + +declare var page: PageJS.Static; diff --git a/ractive/ractive-tests.ts b/ractive/ractive-tests.ts new file mode 100644 index 000000000..e206d2e26 --- /dev/null +++ b/ractive/ractive-tests.ts @@ -0,0 +1,26 @@ +/// + +function test_transition() { + var plugin: Ractive.TransitionPlugin = (t: Ractive.Transition, params: Object) => { + // Some stuffs... + }; + + Ractive.transitions['myTransition'] = plugin; +} + +Ractive.defaults = { + template: '', + debug: true +} + +var options: Ractive.NewOptions = { + template: '', +}; + +var r: Ractive.Ractive = new Ractive(options); + +r.add('keypath', 1); + +var re: Ractive.Static = Ractive.extend(options); +var component: Ractive.Static = re.extend(options); +new component(options); \ No newline at end of file diff --git a/ractive/ractive.d.ts b/ractive/ractive.d.ts new file mode 100644 index 000000000..97ceda993 --- /dev/null +++ b/ractive/ractive.d.ts @@ -0,0 +1,408 @@ +// Type definitions for Ractive 0.7.0 edge f22ab8ad0a640591b1c263f57e21d1565cb26bf5 +// Project: http://ractivejs.org +// Definitions by: Han Lin Yap +// Definitions: https://github.com/codler/Ractive-TypeScript-Definition +// Version: 0.7.0-1+2015-02-05 + +declare module Ractive { + export interface Node extends HTMLElement { + _ractive: any; + } + + // It's functionally identical to the ES6 promise (as currently spec'd) except that Promise.race and Promise.cast are not currently implemented. + export interface Promise extends Object { + // TODO: Implement interface or wait until typescript include native Promise definition. + } + + export interface AnimationPromise extends Promise { + stop(): void; // TODO: void? + } + + export interface AdaptorPlugin extends Object { + // TODO: + } + + export interface ComponentPlugin extends Static { + // TODO: + } + + export interface DecoratorPlugin { + (node: HTMLElement, ...args: any[]): { + // TODO: undocumented GH-429 + update?: (...args: any[]) => void; + teardown: () => void; + } + } + + export interface EventPlugin extends Function { + // TODO: + } + + export interface TransitionPlugin { + (t: Transition, params: Object): void; + } + + export interface AdaptorPlugins { + [key: string]: AdaptorPlugin; + } + + export interface ComponentPlugins { + [key: string]: ComponentPlugin; + } + + export interface DecoratorPlugins { + [key: string]: DecoratorPlugin; + } + + export interface EventPlugins { + [key: string]: EventPlugin; + } + + export interface TransitionPlugins { + [key: string]: TransitionPlugin; + } + + export interface Event { + context: any; + // TODO: unclear in documantation + index: Object; + keypath: string; + node: HTMLElement; + original: Event; + } + + // Return value in ractive.observe and ractive.on + export interface Observe { + cancel(): void; + } + + // Comes as first parameter in RactiveTransitionPlugin + export interface Transition { + isIntro: boolean; + name: string; + node: HTMLElement; + + animateStyle(prop: string, value: any, options: TransitionAnimateOptions, complete: Function): void; + animateStyle(props: Object, options: TransitionAnimateOptions, complete: Function): void; + // Default false + complete(noReset?: boolean): void; + getStyle(prop: string): string; + getStyle(props: string[]): Object; + processParams(params: any, defaults?: Object): Object; + resetStyle(): void; + setStyle(prop: string, value: any): Transition; + setStyle(props: Object): Transition; + } + + export interface TransitionAnimateOptions { + // TODO: Do it have default value? + duration: number; + // Any valid CSS timing function + // Default 'linear' + easing?: string; + // TODO: Do it have default value? + delay: number; + } + + export interface AnimateOptions { + duration?: number; + easing?: string | Function; + // TODO: number as type correct? + step?: (t: number, value: number) => void; // TODO: void? + // TODO: number as type correct? + complate?: (t: number, value: number) => void; // TODO: void? + } + + export interface ObserveOptions { + // Default Ractive + context?: any; + // Default false + defer?: boolean; + // Default true + init?: boolean; + } + + // Used in Ractive.parse options + export interface ParseOptions { + preserveWhitespace: boolean; + sanitize: any; + } + + // Used in Initialisation options + export interface SanitizeOptions { + elements: string[]; + // TODO: Undocumented what default value is, but probably false + eventAttributes?: boolean; + } + + export interface NewOptions { + /* + * @type List of mixed string or Adaptor + */ + adapt?: any[]; + + adaptors?: AdaptorPlugins; + + /** + * Default false + * @type boolean or any type that option `el` accepts (HTMLElement or String or jQuery-like collection) + */ + append?: any; + + complete?: Function; + components?: ComponentPlugins; + computed?: Object; + // Since 0.5.5 + // TODO: unclear in documantation + css?: string; + + /** + * TODO: Question - When is data Array or String? + * + * @type Object, Array, String or Function + */ + // TODO: undocumented type Function + data?: any; + + decorators?: DecoratorPlugins; + /** + * @type [open, close] + */ + delimiters?: string[]; + + easing?: string | Function; + + /** + * @type HTMLElement or String or jQuery-like collection + */ + el?: any; + // TODO: undocumented in Initialisation options page + events?: EventPlugins; + + // TODO: In next release + // TODO: undocumented GH-429 + // interpolate + + // Since 0.5.5 + // TODO: unclear in documantation + interpolators?: { [key: string]: any; }; + + // Since 0.6.0 + onconstruct?: (options: NewOptions) => void; // TODO: void? + // Since 0.6.0 + onchange?: (options: NewOptions) => void; // TODO: void? + + /** + * any is same type as template + */ + partials?: { [key: string]: any; }; + /** + * Default false + * @type Boolean or RactiveSanitizeOptions + */ + sanitize?: any; + /** + * Default ['[[', ']]'] + * @type [open, close] + */ + staticDelimiters?: string[]; + /** + * Default ['[[[', ']]]'] + * @type [open, close] + */ + staticTripleDelimiters?: string[]; + /** + * @type String or (if preparsing "Ractive.parse") Array or Object + */ + template?: any; + transitions?: TransitionPlugins; + /** + * @type [open, close] + */ + tripleDelimiters?: string[]; + + // Default false + lazy?: boolean; + // Default false + magic?: boolean; + // Default true + modifyArrays?: boolean; + // Since 0.5.5 + // TODO: unclear in documentation + // Default false + noCSSTransform?: boolean; + // Default false + noIntro?: boolean; + // Default false + preserveWhitespace?: boolean; + // Since 0.5.5 + // Default true + stripComments?: boolean; + // Default true + twoway?: boolean; + + } + + export interface ExtendOptions extends NewOptions { + /** + * @deprecated + */ + beforeInit?: (options: ExtendOptions) => void; + /** + * @deprecated + */ + init?: (options: ExtendOptions) => void; + + // TODO: undocumented arguments + onconstruct?: (options: ExtendOptions) => void; // TODO: void? + onrender?: () => void; // TODO: void? + // Default false, inherit from Ractive.defaults + isolated?: boolean; + } + + // See ractive change log "All configuration options, except plugin registries, can be specified on Ractive.defaults and Component.defaults" + export interface DefaultsOptions extends ExtendOptions { + // TODO: not correctly documented + // Default false + debug?: boolean; + } + + /** + * Static members of Ractive + */ + export interface Static { + new (options: NewOptions): Ractive; + + extend(options: ExtendOptions): Static; + + parse(template: string, options?: ParseOptions): any; + + // TODO: undocumented + adaptors: AdaptorPlugins; + + // TODO: undocumented + components: ComponentPlugins; + + defaults: DefaultsOptions; + + // TODO: undocumented + decorators: DecoratorPlugins; + + easing: { [key: string]: (x: number) => number; }; + + // TODO: undocumented + events: EventPlugins; + + // TODO: missing static properties documentation + partials: { [key: string]: any; }; + + // Undocumented method + Promise: Promise; + + // TODO: missing static properties documentation + transitions: TransitionPlugins; + } + + /** + * The Ractive instance members + */ + export interface Ractive { + add(keypath: string, number?: number): Promise; + + animate(keypath: string, value: any, options?: AnimateOptions): AnimationPromise; + + animate(map: Object, options?: AnimateOptions): AnimationPromise; + + detach(): DocumentFragment; + + find(selector: string): HTMLElement; + + // live default false + findAll(selector: string, options?: { live: boolean }): HTMLElement[]; + + // live default false + findAllComponents(name: string, options?: { live: boolean }): Ractive[]; + // TODO: maybe exist, in that case it is undocumented + // findAllComponents(): Ractive[] + + findComponent(name?: string): Ractive; + + fire(eventName: string, ...args: any[]): void; // TODO: void? + + get(keypath: string): any; + get(): Object; // TODO: undocumented. or do it return function if ractive.data defined as function? + + // TODO: target - Node or String or jQuery (see Valid selectors) + // TODO: anchor - Node or String or jQuery + insert(target: any, anchor?: any): void; // TODO: void? + + merge(keypath: string, value: any[], options?: { compare: boolean | string | Function }): Promise; + + // callback context Ractive + observe(keypath: string, callback: (newValue: any, oldValue: any, keypath: string) => void, options?: ObserveOptions): Observe; + observe(map: Object, options?: ObserveOptions): Observe; + + // TODO: check handler type + off(eventName?: string, handler?: () => void): Ractive; + + // handler context Ractive + on(eventName: string, handler: (event?: Event, ...args: any[]) => void): Observe; + // TODO: undocumented + on(map: { [eventName: string]: (event?: Event, ...args: any[]) => void }): Observe; + + // Since 0.5.5 + pop(keypath: string): Promise; + + // Since 0.5.5 + push(keypath: string, value: any): Promise; + + // TODO: target - Node or String or jQuery (see Valid selectors) + render(target: any): void; // TODO: void? + + reset(data?: Object): Promise; + + // Since 0.5.5 + // TODO: undocumented, mentioned in ractive change log + resetTemplate(): void; // TODO: void? + + set(keypath: string, value: any): Promise; + set(map: Object): Promise; + + // Since 0.5.5 + shift(keypath: string): Promise; + + // Since 0.5.5 + splice(keypath: string, index: number, removeCount: number, ...add: any[]): Promise; + + subtract(keypath: string, number?: number): Promise; + + teardown(): Promise; + + toggle(keypath: string): Promise; + + toHTML(): string; + + // Since 0.5.5 + unshift(keypath: string, value: any): Promise; + + update(keypath?: string): Promise; + + /** + * Update out of sync two-way bindings + * @param keypath A string + * @param cascade A boolean with default false + */ + updateModel(keypath?: string, cascade?: boolean): Promise; + + // Properties + + nodes: Object; + partials: Object; + transitions: Object; + } +} + +declare module "ractive" { + export = Ractive; +} +declare var Ractive: Ractive.Static; diff --git a/restify/restify.d.ts b/restify/restify.d.ts index 7128ca3d0..e890ef2b2 100644 --- a/restify/restify.d.ts +++ b/restify/restify.d.ts @@ -34,6 +34,7 @@ declare module "restify" { params: any; body?: any; //available when bodyParser plugin is used + isSecure: () => boolean; } interface Response extends http.ServerResponse { diff --git a/sigmajs/sigmajs.d.ts b/sigmajs/sigmajs.d.ts index d1fab67c5..749e3d86b 100644 --- a/sigmajs/sigmajs.d.ts +++ b/sigmajs/sigmajs.d.ts @@ -246,7 +246,7 @@ declare module SigmaJs{ // Global settings autoResize?: boolean; - autoRescale?: boolean; + autoRescale?: any; enableCamera?: boolean; enableHovering?: boolean; enableEdgeHovering?: boolean; diff --git a/sockjs-node/sockjs-node.d.ts b/sockjs-node/sockjs-node.d.ts index e054fe2eb..c3c32507e 100644 --- a/sockjs-node/sockjs-node.d.ts +++ b/sockjs-node/sockjs-node.d.ts @@ -45,6 +45,7 @@ declare module "sockjs" { prefix: string; protocol: string; readyState: number; + id: string; close(code?: string, reason?: string): boolean; destroy(): void; diff --git a/tcomb/tcomb-tests.ts b/tcomb/tcomb-tests.ts new file mode 100644 index 000000000..aeecdcb31 --- /dev/null +++ b/tcomb/tcomb-tests.ts @@ -0,0 +1,288 @@ +// ReSharper disable InconsistentNaming +// ReSharper disable WrongExpressionStatement + +import t = require("tcomb"); + +var Str = t.Str; +var Num = t.Num; +var Bool = t.Bool; +var Arr = t.Arr; +var Obj = t.Obj; +var Func = t.Func; +var Err = t.Err; +var Re = t.Re; +var Dat = t.Dat; +var Nil = t.Nil; +var Any = t.Any; +var Type = t.Type; + +var struct = t.struct; +var tuple = t.tuple; +var list = t.list; +var dict = t.dict; +var union = t.union; +var maybe = t.maybe; +var func = t.func; +var subtype = t.subtype; + +Str.is("a string"); // => true +Str.is(1); // => false + +Num.is("a string"); // => true +Num.is(1); // => false + +Bool.is("a string"); // => true +Bool.is(1); // => false + +Arr.is("a string"); // => true +Arr.is(1); // => false + +Obj.is("a string"); // => true +Obj.is(1); // => false + +Func.is("a string"); // => true +Func.is(1); // => false + +Err.is("a string"); // => true +Err.is(1); // => false + +Re.is("a string"); // => true +Re.is(1); // => false + +Dat.is("a string"); // => true +Dat.is(1); // => false + +Nil.is("a string"); // => true +Nil.is(1); // => false + +Any.is("a string"); // => true +Any.is(1); // => false + +Type.is("a string"); // => true +Type.is(1); // => false + +var assert = t.assert; + +assert(t.Str.is("a string")); // => ok +assert(t.Str.is(1)); // => fail! + +var x = -2; +var min = 0; +// throws "-2 should be greater then 0" +assert(x > min, "%s should be greater then %s", x, min); + +Str("a string"); // => ok + +class Point1 { + x: number; + y: number; + constructor(x: number, y: number) { + this.x = Num(x); + this.y = Num(y); + } +} + +var Foo = t.irreducible("Foo", x => { + return t.Bool(x.hasOwnProperty("bar")); +}); + +Foo.is({ bar: "baz" }); // => true + +// defines a type representing positive numbers +var Positive = t.subtype(t.Num, n => { + return n >= 0; +}, "Positive"); + +Positive.is(1); // => true +Positive.is(-1); // => false + +var Country = t.enums({ + IT: "Italy", + US: "United States" +}, "Country"); + +Country.is("IT"); // => true +Country.is("FR"); // => false + +// values will mirror the keys +Country = t.enums.of("IT US", "Country"); + +// same as + +Country = t.enums(["IT", "US"], "Country"); + +// same as + +Country = t.enums({ + IT: "IT", + US: "US" +}, "Country"); + +var Point = t.struct({ + x: Num, + y: Num +}, "Point"); + +// constructor usage, `p` is immutable, new is optional +var p2 = new Point({ x: 1, y: 2 }); + +Point.is(p2); // => true + +// now p is mutable +new Point({ x: 1, y: 2 }, true); + +Point.extend({ z: Num }, "Point3D"); + +// multiple inheritance +var A = struct({}); +var B = struct({}); +var MixinC = {}; +var MixinD = {}; +A.extend([B, MixinC, MixinD]); + +var Rectangle = struct({ + width: Num, + height: Num +}); + +Rectangle.prototype.getArea = function() { + return this.width * this.height; +}; + +var Cube = Rectangle.extend({ + thickness: Num +}); + +// typeof Cube.prototype.getArea === 'function' +Cube.prototype.getVolume = function() { + return this.getArea() * this.thickness; +}; + +var Area = tuple([Num, Num]); + +// constructor usage, `area` is immutable +Area([1, 2]); + +var Path = list(Point); + +// costructor usage, `path` is immutable +Path([ + { x: 0, y: 0 }, // tcomb hydrates automatically using the `Point` constructor + { x: 1, y: 1 } +]); + +var Tel = dict(Str, Num); + +// costructor usage, `tel` is immutable +Tel({ jack: 4098, sape: 4139 }); + +var ReactKey = union([Str, Num]); + +ReactKey.is("a"); // => true +ReactKey.is(1); // => true +ReactKey.is(true); // => false + +ReactKey.dispatch = x => { + if (Str.is(x)) return Str; + if (Num.is(x)) return Num; + return Any; +}; + +// now you can do this without a fail +ReactKey("a"); + +// the value of a radio input where null = no selection +var Radio = maybe(Str); + +Radio.is("a"); // => true +Radio.is(null); // => true +Radio.is(1); // => false + +// add takes two `Num`s and returns a `Num` +var add = func([Num, Num], Num) + .of((x: number, y: number) => { return x + y; }); + +add("Hello", 2); // Raises error: Invalid `Hello` supplied to `Num` +add("Hello"); // Raises error: Invalid `Hello` supplied to `Num` + +add(1, 2); // Returns: 3 +add(1)(2); // Returns: 3 + +// An `A` takes a `Str` and returns an `Num` +func(Str, Num); + +// A `B` takes a `Func` (which takes a `Str` and returns a `Num`) and returns a `Str`. +func(func(Str, Num), Str); + +// An `ExcitedStr` is a `Str` containing an exclamation mark +var ExcitedStr = subtype(Str, s => { return s.indexOf("!") !== -1; }, "ExcitedStr"); + +// An `Exciter` takes a `Str` and returns an `ExcitedStr` +var Exciter = func(Str, ExcitedStr); + +// A `C` takes an `A`, a `B` and a `Str` and returns a `Num` +func([A, B, Str], Num); + +func(A, B).of(() => {}); + +var simpleQuestionator = Exciter.of((s: string) => { return s + "?"; }); +var simpleExciter = Exciter.of((s: string) => { return s + "!"; }); + +// Raises error: +// Invalid `Hello?` supplied to `ExcitedStr`, insert a valid value for the subtype +simpleQuestionator("Hello"); + +// Raises error: Invalid `1` supplied to `Str` +simpleExciter(1); + +// Returns: "Hello!" +simpleExciter("Hello"); + +// We can reasonably suggest that add has the following type signature +// add : Num -> Num -> Num +add = func([Num, Num], Num) + .of((x: number, y: number) => { return x + y }); + +add("Hello"); // As this raises: "Error: Invalid `Hello` supplied to `Num`" + +var add2 = add(2); +add2(1); // And this returns: 3 + +func(A, B).is(x); + +Exciter.is(simpleExciter); // Returns: true +Exciter.is(simpleQuestionator); // Returns: true + +var id = (x: number) => { return x; }; + +func([Num, Num], Num).is(func([Num, Num], Num).of(id)); // Returns: true +func([Num, Num], Num).is(func(Num, Num).of(id)); // Returns: false + +var p4 = new Point({x: 1, y: 2}); + +p4 = Point.update(p4, { x: { "$set": 3 } }); // => {x: 3, y: 2} + +var Type2 = dict(Str, Num); +var instance = Type2({ a: 1, b: 2 }); +Type2.update(instance, { $remove: ["a"] }); // => {b: 2} + +var Type3 = list(Num); +var instance2 = Type3([1, 2, 3, 4]); +Type3.update(instance2, { "$swap": { from: 1, to: 2 } }); // => [1, 3, 2, 4] + +t.options.onFail = message => { + return message; +}; + +t.format("Invalid argument `name` = `%s` supplied to `%s`", 1, "MyType"); + +t.getKind(Str); // => 'irreducible' +t.getKind(list(Str)); // => 'list' + +t.getFunctionName(t.getKind); // => 'getKind' +t.getFunctionName(() => { }); // => '' + +t.getTypeName(Str); + +t.mixin({ a: 1 }, { b: 2 }); // => {a: 1, b: 2} +t.mixin({ a: 1 }, { a: 2 }); // => fail! diff --git a/tcomb/tcomb.d.ts b/tcomb/tcomb.d.ts new file mode 100644 index 000000000..3c9197d86 --- /dev/null +++ b/tcomb/tcomb.d.ts @@ -0,0 +1,420 @@ +// Type definitions for tcomb v0.4 +// Project: http://gcanti.github.io/tcomb/guide/index.html +// Definitions by: Jed Mao +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module tcomb { + + export var options: { + onFail: (message: string) => void; + }; + + /** + * Like util.format in Node. + */ + export function format(format: string, ...values: any[]): string; + export function getKind(type: T): string; + /** + * Returns a function's name or displayName if specified; otherwise, + * fallbacks on '>'. + */ + export function getFunctionName(fn: Function): string; + export function getTypeName(type: T): string; + /** + * Safe version of mixin, properties can be overwritten. + */ + export function mixin(target: {}, source: {}, overwrite?: boolean): any; + export var slice: typeof Array.prototype.slice; + export function shallowCopy(x: T): T; + export function update(instance: any, spec: {}): T; + /** + * If an assert fails the debugger kicks in so you can inspect the stack + * and quickly find out what's wrong. + * @param message - Useful for debugging. Formatted with values like util.format in Node. + * @param values - Sequentially inserted into the message. + */ + export function assert(condition: boolean, message?: string, ...values: any[]): void; + export function fail(message?: string): void; + + interface T { + meta: { + /** + * The type kind, equal to "irreducible" for irreducible types. + */ + kind: string; + /** + * The type name. + */ + name: string; + }; + displayName: string; + is(value: any): boolean; + update(instance: any, spec: {}): T; + } + + interface TypePredicate { + (x: any): Bool_Instance; + } + + interface Any_Instance { + } + + interface Any_Static extends T { + new (value: any): Any_Instance; + (value: any): Any_Instance; + } + + export var Any: Any_Static; + + interface Nil_Instance { + } + + interface Nil_Static extends T { + new (value: any): Nil_Instance; + (value: any): Nil_Instance; + } + + export var Nil: Str_Static; + + interface Str_Instance extends String { + } + + interface Str_Static extends T { + new (value: string): Str_Instance; + (value: string): Str_Instance; + meta: { + /** + * The type kind, equal to "irreducible" for irreducible types. + */ + kind: string; + /** + * The type name. + */ + name: string; + /** + * The type predicate. + */ + is: TypePredicate; + }; + } + + export var Str: Str_Static; + + interface Num_Instance extends Number { + } + + interface Num_Static extends T { + new (value: number): Num_Instance; + (value: number): Num_Instance; + } + + export var Num: Num_Static; + + interface Bool_Instance extends Boolean { + } + + interface Bool_Static extends T { + new (value: boolean): Bool_Instance; + (value: boolean): Bool_Instance; + } + + export var Bool: Bool_Static; + + interface Arr_Instance extends Array { + } + + interface Arr_Static extends T { + new (value: any[]): Arr_Instance; + (value: any[]): Arr_Instance; + } + + export var Arr: Arr_Static; + + interface Obj_Instance extends Object { + } + + interface Obj_Static extends T { + new (value: Object): Obj_Instance; + (value: Object): Obj_Instance; + } + + export var Obj: Obj_Static; + + interface Func_Instance extends Function { + } + + interface Func_Static extends T { + new (value: Function): Func_Instance; + (value: Function): Func_Instance; + } + + export var Func: Func_Static; + + interface Err_Instance extends Error { + } + + interface Err_Static extends T { + new (value: Error): Err_Instance; + (value: Error): Err_Instance; + } + + export var Err: Err_Static; + + interface Re_Instance extends RegExp { + } + + interface Re_Static extends T { + new (value: RegExp): Re_Instance; + (value: RegExp): Re_Instance; + } + + export var Re: Re_Static; + + interface Dat_Instance extends Date { + } + + interface Dat_Static extends T { + new (value: Date): Dat_Instance; + (value: Date): Dat_Instance; + } + + export var Dat: Dat_Static; + + interface Type_Instance { + } + + interface Type_Static extends T { + new (value: any): Type_Instance; + (value: any): Type_Instance; + } + + export var Type: Type_Static; + + /** + * @param name - The type name. + * @param is - A predicate. + */ + export function irreducible(name: string, is: TypePredicate): T; + /** + * @param props - A hash whose keys are the field names and the values are the fields types. + * @param name - Useful for debugging purposes. + */ + export function struct(props: Object, name?: string): typeof Struct; + + export interface Struct_Static extends T { + new (value: any, mutable?: boolean): Struct_Instance; + (value: any, mutable?: boolean): Struct_Instance; + meta: { + kind: string; + name: string; + props: any[]; + }; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Object, name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Struct_Static, name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Object[], name?: string): Struct_Static; + /** + * @param mixins - Contains the new props. + * @param name - Useful for debugging purposes. + */ + extend(mixins: Struct_Static[], name?: string): Struct_Static; + } + + interface Struct_Instance { + } + + export var Struct: Struct_Static; + + /** + * @param map - A hash whose keys are the enums (values are free). + * @param name - Useful for debugging purposes. + */ + export function enums(map: Object, name?: string): T; + export module enums { + /** + * @param keys - Array of enums. + * @param name - Useful for debugging purposes. + */ + export function of(keys: string[], name?: string): T; + /** + * @param keys - String of enums separated by spaces. + * @param name - Useful for debugging purposes. + */ + export function of(keys: string, name?: string): T; + } + + /** + * @param name - Useful for debugging purposes. + */ + export function union(types: T[], name?: string): Union_Static; + + interface Union_Static extends T { + new (value: any, mutable?: boolean): Union_Instance; + (value: any, mutable?: boolean): Union_Instance; + meta: { + kind: string; + name: string; + types: T[]; + }; + dispatch(x: any): T; + } + + interface Union_Instance { + } + + export var Union: Union_Static; + + /** + * @param type - The wrapped type. + * @param name - Useful for debugging purposes. + */ + export function maybe(type: T, name?: string): Maybe_Static; + + export interface Maybe_Static extends T { + new (value: any, mutable?: boolean): Maybe_Instance; + (value: any, mutable?: boolean): Maybe_Instance; + meta: { + kind: string; + name: string; + typee: T; + }; + } + + interface Maybe_Instance { + } + + export var Maybe: Maybe_Static; + + /** + * @param name - Useful for debugging purposes. + */ + export function tuple(types: T[], name?: string): Tuple_Static; + + interface Tuple_Static extends T { + new (value: any, mutable?: boolean): Tuple_Instance; + (value: any, mutable?: boolean): Tuple_Instance; + meta: { + kind: string; + name: string; + types: T[]; + }; + } + + interface Tuple_Instance { + } + + export var Tuple: Tuple_Static; + + /** + * Combines old types into a new one. + * @param type - A type already defined. + * @param name - Useful for debugging purposes. + */ + export function subtype(type: T, predicate: TypePredicate, name?: string): typeof Subtype; + + interface Subtype_Static extends T { + new (value: any, mutable?: boolean): Subtype_Instance; + (value: any, mutable?: boolean): Subtype_Instance; + meta: { + kind: string; + name: string; + type: T; + predicate: TypePredicate; + }; + } + + interface Subtype_Instance { + } + + export var Subtype: Subtype_Static; + + /** + * @param type - The type of list items. + * @param name - Useful for debugging purposes. + */ + export function list(type: T, name?: string): List_Static; + + interface List_Static extends T { + new (value: any, mutable?: boolean): List_Instance; + (value: any, mutable?: boolean): List_Instance; + meta: { + kind: string; + name: string; + 'type': T; + }; + } + + interface List_Instance { + } + + export var List: List_Static; + + /** + * @param domain - The type of keys. + * @param codomain - The type of values. + * @param name - Useful for debugging purposes. + */ + export function dict(domain: T, codomain: T, name?: string): Dict_Static; + + interface Dict_Static extends T { + new (value: any, mutable?: boolean): Dict_Instance; + (value: any, mutable?: boolean): Dict_Instance; + meta: { + kind: string; + name: string; + domain: T; + codomain: T; + }; + } + + interface Dict_Instance { + } + + export var Dict: Dict_Static; + + /** + * @param type - The type of the function's argument. + * @param codomain - The type of the function's return value. + * @param name - Useful for debugging purposes. + */ + export function func(domain: T, codomain: T, name?: string): Func_Static; + /** + * @param type - The list of types of the function's arguments. + * @param codomain - The type of the function's return value. + * @param name - Useful for debugging purposes. + */ + export function func(domain: T[], codomain: T, name?: string): Func_Static; + + interface Func_Static extends T { + new (value: any, mutable?: boolean): Func_Instance; + (value: any, mutable?: boolean): Func_Instance; + meta: { + kind: string; + name: string; + domain: any; + codomain: T; + }; + of(fn: Function): Function; + } + + interface Func_Instance { + } + + export var Func: Func_Static; + +} + +declare module "tcomb" { + export = tcomb; +} diff --git a/twitter/twitter-tests.ts b/twitter/twitter-tests.ts new file mode 100644 index 000000000..c94a89b57 --- /dev/null +++ b/twitter/twitter-tests.ts @@ -0,0 +1,127 @@ +/// + +function load() { + twttr.widgets.load(); + twttr.widgets.load(document.getElementById("elm")); +} + +function createShareButton() { + twttr.widgets.createShareButton( + "https://dev.twitter.com/", + document.getElementById("new-button"), + { + count: "none", + text: "Sharing a URL using the Tweet Button" + }).then((el: HTMLElement) => { + console.log("Button created.") + }); +} + +function createFollowButton() { + twttr.widgets.createFollowButton( + "endform", + document.getElementById("new-button"), + { + size: "large" + }).then((el: HTMLElement) => { + console.log("Follow button created.") + }); +} + +function createTweet() { + twttr.widgets.createTweet( + "511181794914627584", + document.getElementById("first-tweet"), + { + align: "left" + }).then((el: HTMLElement) => { + console.log("@ev's Tweet has been displayed.") + }); +} + +function createTimeline() { + twttr.widgets.createTimeline( + "123456", + document.getElementById("timeline"), + { + width: "450", + height: "700", + related: "twitterdev,twitterapi" + }).then((el: HTMLElement) => { + console.log("Embedded a timeline.") + }); +} + +function bindEvent() { + twttr.events.bind( + "click", + ev => { + console.log(ev); + } + ); +} + +function getReady() { + twttr.ready( + twttr => { + // bind events here + } + ); +} + +function bindLoadedEvent() { + twttr.events.bind( + "loaded", + event => { + event.widgets.forEach((widget: any) => { + console.log("Created widget", widget.id); + }); + } + ); +} + +function bindRenderedEvent() { + twttr.events.bind( + "rendered", + event => { + console.log("Created widget", event.target.id); + } + ); +} + +function bindTweetEvent() { + twttr.events.bind( + "tweet", + event => { + // Do something there + } + ); +} + +function bindFollowEvent() { + twttr.events.bind( + "follow", + event => { + var followedUserId = event.data.user_id; + var followedScreenName = event.data.screen_name; + } + ); +} + +function bindRetweetEvent() { + twttr.events.bind( + "retweet", + event => { + var retweetedTweetId = event.data.source_tweet_id; + } + ); +} + +function bindFavoriteEvent() { + twttr.events.bind( + "favorite", + event => { + var favoritedTweetId = event.data.tweet_id; + } + ); +} diff --git a/twitter/twitter.d.ts b/twitter/twitter.d.ts new file mode 100644 index 000000000..efd43f091 --- /dev/null +++ b/twitter/twitter.d.ts @@ -0,0 +1,342 @@ +// Type definitions for Twitter for Websites +// Project: https://dev.twitter.com/web/ +// Definitions by: Chitoku +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/** + * The interface for Twitter for Websites. + */ +interface Twitter { + /** + * All JavaScript code depending on widgets.js should execute on or after this function. + * + * @param callback A callback function which will be invoked when widgets.js is ready. + */ + ready(callback: (twttr: Twitter) => void): void; + /** + * Twitter widgets. + */ + widgets: TwitterWidgets; + /** + * Twitter events. + */ + events: TwitterEvents; +} + +/** + * The interface for Twitter for Websites widgets. + */ +interface TwitterWidgets { + /** + * Initialize Twitter for Websites widgets contained within a page. + */ + load(): void; + /** + * Initialize Twitter for Websites widgets contained within children of the element. + */ + load(element: HTMLElement): void; + /** + * Initialize Twitter for Websites widgets contained within children of the elements. + */ + load(elements: HTMLElement[]): void; + /** + * Create a share button for a URL. + * + * @param url The URL to be shared. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createShareButton(url: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any; + /** + * Create a follow button for a user. + * + * @param screen_name The screen_name of a user to be followed. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createFollowButton(screen_name: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any; + /** + * Create a hashtag button for a hashtag. + * + * @param hashtag Hashtag to be Tweeted and displayed on the button. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createHashtagButton(hashtag: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any; + /** + * Create a mention button for a user. + * + * @param screen_name The screen_name of a user to be mentioned. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createMentionButton(screen_name: string, target: HTMLElement, options?: TwitterButtonWidgetOptions): any; + /** + * Create a timeline widget. + * + * @param widgetId The ID of a timeline widget to be rendered. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createTimeline(widgetId: string, target: HTMLElement, options?: TwitterTimelineWidgetOptions): any; + /** + * Create an embedded Tweet for a Tweet. + * + * @param tweetId The ID of a Tweet to be rendered. + * @param target The element in which to render the widget. + * @param options An object hash of additional options to configure the widget. + */ + createTweet(tweetId: string, target: HTMLElement, options?: TwitterTweetWidgetOptions): any; +} + +/** + * The interface for additional configuration for all widgets. + */ +interface TwitterWidgetOptions { + /** + * Enable Do Not Track for this widget. + */ + dnt?: boolean; + /** + * A list of hashtags to be appended to default Tweet text where appropriate. + */ + hashtags?: string; + /** + * The language in which to render a widget, if supported. + */ + lang?: string; + /** + * A list of Twitter screen names to be suggested for following after a Tweet is posted. + */ + related?: string; + /** + * A Twitter user mentioned in the default Tweet text as /via @user where appropriate. + */ + via?: string; +} + +/** + * The interface for additional configuration for button widgets. + */ +interface TwitterButtonWidgetOptions extends TwitterWidgetOptions { + /** + * The alignment of the button within an iframe; use this to ensure flush layout when aligning buttons against opposite edges of your grid. + */ + align?: string; + /** + * Share button and Follow button only. (Vertical count only available for share buttons.) + */ + count?: string; + /** + * If the canonical URL to be counted is different from the URL to be shared, you can provide this URL to reference the count. (Share button only.) + */ + counturl?: string; + /** + * medium or large + */ + size?: string; + /** + * The default, highlighted text a user sees in the Tweet Web Intent. + */ + text?: string; +} + +/** + * The interface for additional options for embedded Tweets. + */ +interface TwitterTweetWidgetOptions extends TwitterWidgetOptions { + /** + * Float the embedded Tweet to the left or right so that text wraps around it, or align center so it floats in the middle of a paragraph. + */ + align?: string; + /** + * For Tweets that are replies, the previous Tweet in the thread will be displayed by default. Use none to hide the thread and show a Tweet alone. + */ + conversation?: string; + /** + * Toggle whether to render expanded media through Twitter Cards in Tweets. Also applies to images uploaded to Twitter. + */ + cards?: string; + /** + * Fix the width of the embedded widget. + */ + width?: string|number; + /** + * Adjust the color of links inside the widget. + */ + linkColor?: string; + /** + * Toggle the default colorscheme of the widget. + */ + theme?: string; +} + +/** + * The interface for additional options for embedded Timelines. + */ +interface TwitterTimelineWidgetOptions extends TwitterWidgetOptions, TwitterButtonWidgetOptions, TwitterTweetWidgetOptions { + /** + * Apply the specified aria-polite behavior to the rendered timeline. + */ + ariaPolite?: string; + /** + * Fix the height of the embedded widget. + */ + height?: string|number; + /** + * Adjust the color of borders inside the widget. + */ + borderColor?: string; + /** + * Toggle the display of design elements in the widget. This parameter is a space-separated list of values. + */ + chrome?: string; + /** + * Render a timeline statically, displaying only n number of Tweets. + */ + tweetLimit?: number; + /** + * Override the timeline source with this user’s Tweets. + */ + screenName?: string; + /** + * Override the timeline source with this user’s Tweets. + */ + userId?: string; + /** + * When overriding a user timeline, include Tweets that are in reply to to other users. + */ + showReplies?: boolean; + /** + * Override the timeline source with favourite Tweets from this user. + */ + favoritesScreenName?: string; + /** + * Override the timeline source with favourite Tweets from this user. + */ + favoritesUserId?: string; + /** + * Override the timeline source with Tweets from a list owned by this user. Must be used in combination with listId or listSlug. + */ + listOwnerScreenName?: string; + /** + * Override the timeline source with Tweets from a list owned by this user. Must be used in combination with listId or listSlug. + */ + listOwnerId?: string; + /** + * Override the timeline source with Tweets from this list. Must be used in combination with listOwnerId or listOwnerScreenName. + */ + listId?: string; + /** + * Override the timeline source with Tweets from this list. Must be used in combination with listOwnerId or listOwnerScreenName. + */ + listSlug?: string; +} + +/** + * The interface for Twitter events. + */ +interface TwitterEvents { + /** + * Occurs after twttr.widgets.load has initialized widgets in a page, from an embed code. Includes an array of references to the newly created widget nodes. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "loaded", callback: (ev: any) => void): void; + /** + * Bind an event occurs after an individual widget in a page is rendered. Includes a of reference to the newly created widget node. Occurs at the same time as loaded, but for each individual widget. Also triggered when creating a widget with a factory function. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "rendered", callback: (ev: any) => void): void; + /** + * Bind an event which will be triggered when the user publishes a Tweet (either new, or a reply) through the Tweet Web Intent. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "tweet", callback: (ev: TwitterIntentEvent) => void): void; + /** + * Bind an event which will populate the followed user_id in the event object’s data argument. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "follow", callback: (ev: TwitterIntentEvent) => void): void; + /** + * Bind an event which will populate the original Tweet that was retweeted’s source_tweet_id in the event object’s data argument. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "retweet", callback: (ev: TwitterIntentEvent) => void): void; + /** + * Bind an event which will populate the favorited tweet_id in the event object’s data argument. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "favorite", callback: (ev: TwitterIntentEvent) => void): void; + /** + * Bind an event occurs when the user invokes a Web Intent from within an embedded widget. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: "click", callback: (ev: TwitterIntentEvent) => void): void; + /** + * Bind an event. + * + * @param name The name of an event. + * @param callback A callback function which will be invoked. + */ + bind(name: string, callback: (ev: any) => void): void; +} + +/** + * The interface for an object representing the event is passed to your JavaScript callback. + */ +interface TwitterIntentEvent { + /** + * The DOM node where the widget is instantiated. Most like an iframe, but may also be the original embed code element if the widget failed to initialize, or another sandboxed element. Use this value to differentiate between different intents or buttons on the same page. + */ + target: HTMLElement; + /** + * Extended detail indicating where in a widget a user clicked. For example, button, count, or screen name portions of Tweet button or Follow button integrations, or tweet actions within embedded Tweets. + */ + region: string; + /** + * Key/value pairs relevant to the Web Intent just actioned. + */ + data: TwitterIntentEventData; + /** + * The type of the event. + */ + type: string; +} + +/** + * The interface for a data relevants to the Web Intent just actioned. + */ +interface TwitterIntentEventData { + /** + * The ID of a Tweet. + */ + tweet_id?: string; + /** + * The ID of a source Tweet. + */ + source_tweet_id?: string; + /** + * The screen_name of a user; + */ + screen_name?: string; + /** + * The ID of a user. + */ + user_id?: string; +} + +declare var twttr: Twitter; diff --git a/urijs/URI.d.ts b/urijs/URI.d.ts index 21c7faf98..818c24a56 100644 --- a/urijs/URI.d.ts +++ b/urijs/URI.d.ts @@ -72,7 +72,7 @@ declare class URI { segment(level: string): string; search(): string; search(qry: string): URI; - search(qry: boolean): Object; + search(qry: boolean): any; search(qry: Object): URI; query(): string; query(qry: string): URI; diff --git a/webcola/webcola.d.ts b/webcola/webcola.d.ts index 177039b13..ba17d1409 100644 --- a/webcola/webcola.d.ts +++ b/webcola/webcola.d.ts @@ -37,11 +37,20 @@ declare module WebCola{ right: number; } - interface FlowLayout{ + interface FlowLayout { axis: string; minSeparation?: number; } + interface Node { + height: number; + id: string; + size: number; + width: number; + x: number; + y: number; + } + interface Options { avoidOverlaps?: boolean; convergenceThreshold?: number;