From 6591aeb9a8f6b8b1e831fe337d4f11b5a165a298 Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 09:52:48 -0800 Subject: [PATCH 001/104] TypeScript definitions for di-lite 0.3.3 TypeScript definitions for di-lite 0.3.3 (https://github.com/NickQiZhu/di.js) --- di-lite/di-lite.d.ts | 58 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 di-lite/di-lite.d.ts diff --git a/di-lite/di-lite.d.ts b/di-lite/di-lite.d.ts new file mode 100644 index 0000000000..fe279b60ab --- /dev/null +++ b/di-lite/di-lite.d.ts @@ -0,0 +1,58 @@ +// Type definitions for di-lite 0.3.3 +// Project: https://github.com/NickQiZhu/di.js +// Definitions by: Timothy Morris +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +interface di { + version: string; + createContext(): CreateContext; + dependencyExpression(depExp: string): string; + entry(name: string, ctx: CreateContext); + strategy: Strategy; + factory: Factory; + utils: Utils; +} + +interface CreateContext { + map: Object; + entry(name: string): Object; + register(name: string, service: any): CreateContext; + has(name: string): boolean; + "get"(name: string): any; + create(name: string, args: any) + initialize(): void; + clear(): void; + inject(name: string, o: Object, dependencies: string): Object; + ready(o: Function): Object; + ready(o: Object): Object; +} + +interface Entry { + create(newArgs: any): Entry; + object(): Object; + object(o: Object): Entry; + strategy(s: Function): Entry; + type(t: any): Entry; + dependencies(d: string): Entry; + args(a: any): Entry; + factory(f: Function): Entry; +} + +interface Strategy { + proto(name: string, object: Object, type: any, args: any, ctx: CreateContext, dependencies: string): Object; + singleton(name: string, object: Object, type: any, args: any, ctx?: CreateContext, dependencies?: string): Object; +} + +interface Factory { + "constructor"(type: any, args: any): Object; + func(type: any, args: any): any; +} + +interface Utils { + invokeStmt(args: any, op: string): string; +} + +declare var di: di; +declare module "di" { + export = di; +} From 302b3afa2ec9ebeae59bde791677e89fad6dbc3a Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 11:35:11 -0800 Subject: [PATCH 002/104] Prefix interfaces with Di Prefixed interfaces with Di to help organize intellisense --- di-lite/di-lite.d.ts | 46 ++++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/di-lite/di-lite.d.ts b/di-lite/di-lite.d.ts index fe279b60ab..062434dea5 100644 --- a/di-lite/di-lite.d.ts +++ b/di-lite/di-lite.d.ts @@ -3,20 +3,20 @@ // Definitions by: Timothy Morris // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface di { +interface DiLite { version: string; - createContext(): CreateContext; + createContext(): DiCreateContext; dependencyExpression(depExp: string): string; - entry(name: string, ctx: CreateContext); - strategy: Strategy; - factory: Factory; - utils: Utils; + entry(name: string, ctx: DiCreateContext); + strategy: DiStrategy; + factory: DiFactory; + utils: DiUtils; } -interface CreateContext { +interface DiCreateContext { map: Object; entry(name: string): Object; - register(name: string, service: any): CreateContext; + register(name: string, service: any): DiEntry; has(name: string): boolean; "get"(name: string): any; create(name: string, args: any) @@ -27,32 +27,32 @@ interface CreateContext { ready(o: Object): Object; } -interface Entry { - create(newArgs: any): Entry; +interface DiEntry { + create(newArgs: any): DiEntry; object(): Object; - object(o: Object): Entry; - strategy(s: Function): Entry; - type(t: any): Entry; - dependencies(d: string): Entry; - args(a: any): Entry; - factory(f: Function): Entry; + object(o: Object): DiEntry; + strategy(s: Function): DiEntry; + type(t: any): DiEntry; + dependencies(d: string): DiEntry; + args(a: any): DiEntry; + factory(f: Function): DiEntry; } -interface Strategy { - proto(name: string, object: Object, type: any, args: any, ctx: CreateContext, dependencies: string): Object; - singleton(name: string, object: Object, type: any, args: any, ctx?: CreateContext, dependencies?: string): Object; +interface DiStrategy { + proto(name: string, object: Object, type: any, args: any, ctx: DiCreateContext, dependencies: string): Object; + singleton(name: string, object: Object, type: any, args: any, ctx?: DiCreateContext, dependencies?: string): Object; } -interface Factory { +interface DiFactory { "constructor"(type: any, args: any): Object; func(type: any, args: any): any; } -interface Utils { +interface DiUtils { invokeStmt(args: any, op: string): string; } -declare var di: di; -declare module "di" { +declare module "di-lite" { export = di; } +declare var di: DiLite; From 7eabe68bb77b81cbe4e9ca07da8da90c515ad72a Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 18:55:48 -0800 Subject: [PATCH 003/104] Add di-lite tests --- di-lite/di-lite-test.ts | 137 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 di-lite/di-lite-test.ts diff --git a/di-lite/di-lite-test.ts b/di-lite/di-lite-test.ts new file mode 100644 index 0000000000..fbff668f1e --- /dev/null +++ b/di-lite/di-lite-test.ts @@ -0,0 +1,137 @@ +interface Dependency { + dependencies?: string; +} + +function doTest(test: (ctx: DiCreateContext, ...obj: Dependency[]) => void) { + // create di context + var ctx = di.createContext(), + A: Dependency = () => { + this.dependencies = "b, c"; + }, + B: Dependency = () => { + this.dependencies = "c"; + }, + C: Dependency = () => {}; + + // register a class with an unique name + ctx.register("a", A); + ctx.register("b", B); + ctx.register("c", C); + + test(ctx, A, B, C); +} + +module BasicWiring { + doTest(ctx => { + // initialize di container so all singleton(default) objects will be wired at this stage + ctx.initialize(); + + var instanceOfA = ctx.get("a"); + instanceOfA.b === ctx.get("b"); // true + instanceOfA.c === ctx.get("c"); // true + + var instanceOfB = ctx.get("b"); + instanceOfB.c === ctx.get("c"); // true + }); +} + +module WiringWithAssignment { + doTest((ctx, A) => { + A.dependencies = "bee=b, c"; // mix explicit and implicit assignment + + ctx.initialize(); + + var instanceOfA = ctx.get("a"); + instanceOfA.bee === ctx.get("b"); // true - explicit assignment + instanceOfA.c === ctx.get("c"); // true - implicit assignment + }); +} + +module PassiveDependencyResolution { + doTest((ctx, A) => { + ctx.register("a", A); + ctx.get("a"); // this triggers the dependency resolution for "a" alone + ctx.initialize(); + }); +} + +module PrototypeStrategy { + doTest((ctx, A) => { + ctx.register("prototype", A).strategy(di.strategy.proto); + ctx.get("prototype") === ctx.get("prototype"); // false + ctx.create("prototype", 100); // create can be used if you want to explicitly pass in a new parameter + }); +} + +module PassingConstructorArguments { + class ProfileView { } + + doTest(ctx => { + ctx.register("str", String, "hello world"); // signle simple argument + ctx.register("profileView", ProfileView, { el: "#profile_div" }); // signle object literal argument + ctx.register("array", Array, ["Saab", "Volvo", "BMW"]); // multiple argument is passed in using an array + }); +} + +module CyclicalDependency { + doTest((ctx, A, B) => { + A.dependencies = "b"; + B.dependencies = "a"; + + ctx.register("a", A); + ctx.register("b", B); + + ctx.initialize(); + + ctx.get("a").b === ctx.get("b"); // true + ctx.get("b").a === ctx.get("a"); // true + ctx.get("a").b.a === ctx.get("a"); // true + ctx.get("b").a.b === ctx.get("b"); // true + }); +} + +module FunctionalObject { + doTest(ctx => { + var FuncObject = spec => { + var that = {}; + return that; + }, + spec = []; + + ctx.register("funcObjSingleton", FuncObject, spec).factory(di.factory.func); + + // function chaining can be used to customize your object registration + ctx.register("funcObjProto", FuncObject, spec) + .strategy(di.strategy.proto) + .factory(di.factory.func); + + ctx.initialize(); + + ctx.get("funcObjSingleton"); // will return you a signleton instance of FuncObject + ctx.get("funcObjProto"); // will return you a new instance of FuncObject each time + }); +} + +module RuntimeDependenciesOverride { + doTest((ctx, A) => { + ctx.register("a", A) + .dependencies("bee=b"); // dependencies specified here will take precedence + ctx.get("a").bee === ctx.get("b"); // true + }); +} + +module CreateYourOwn { + class Backbone { + history: History = new History(); + } + + class History { + start() {} + } + + doTest(ctx => { + ctx.register("history").object(new Backbone().history); + ctx.get("history").start(); // you can use it since it is already created and initialized + ctx.initialize(); // initialize the rest of the objects + }); +} From b33ff5f0e08b2d7e22568c1f7a1c7f2caae66bdd Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 18:56:12 -0800 Subject: [PATCH 004/104] Fix error revealed by tests --- di-lite/di-lite.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/di-lite/di-lite.d.ts b/di-lite/di-lite.d.ts index 062434dea5..d679b00de1 100644 --- a/di-lite/di-lite.d.ts +++ b/di-lite/di-lite.d.ts @@ -16,7 +16,7 @@ interface DiLite { interface DiCreateContext { map: Object; entry(name: string): Object; - register(name: string, service: any): DiEntry; + register(name: string, type?: any, args?: any): DiEntry; has(name: string): boolean; "get"(name: string): any; create(name: string, args: any) From ba80717c78458816b55b7e4d2084c9ab5807ee16 Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 19:06:14 -0800 Subject: [PATCH 005/104] Add reference path to test file --- di-lite/di-lite-test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/di-lite/di-lite-test.ts b/di-lite/di-lite-test.ts index fbff668f1e..eed9c2625d 100644 --- a/di-lite/di-lite-test.ts +++ b/di-lite/di-lite-test.ts @@ -1,8 +1,10 @@ +/// + interface Dependency { dependencies?: string; } -function doTest(test: (ctx: DiCreateContext, ...obj: Dependency[]) => void) { +function doTest(test: (ctx, ...obj: Dependency[]) => void) { // create di context var ctx = di.createContext(), A: Dependency = () => { @@ -92,11 +94,11 @@ module CyclicalDependency { module FunctionalObject { doTest(ctx => { - var FuncObject = spec => { + var FuncObject = (spec: any) => { var that = {}; return that; }, - spec = []; + spec: any = []; ctx.register("funcObjSingleton", FuncObject, spec).factory(di.factory.func); From 811ddbf03d9ce3aaaa9c19207c4f19bef35e5493 Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 19:06:37 -0800 Subject: [PATCH 006/104] Fix build errors --- di-lite/di-lite.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/di-lite/di-lite.d.ts b/di-lite/di-lite.d.ts index d679b00de1..946fe9a3f8 100644 --- a/di-lite/di-lite.d.ts +++ b/di-lite/di-lite.d.ts @@ -7,7 +7,7 @@ interface DiLite { version: string; createContext(): DiCreateContext; dependencyExpression(depExp: string): string; - entry(name: string, ctx: DiCreateContext); + entry(name: string, ctx: DiCreateContext): DiEntry; strategy: DiStrategy; factory: DiFactory; utils: DiUtils; @@ -19,7 +19,7 @@ interface DiCreateContext { register(name: string, type?: any, args?: any): DiEntry; has(name: string): boolean; "get"(name: string): any; - create(name: string, args: any) + create(name: string, args: any): any; initialize(): void; clear(): void; inject(name: string, o: Object, dependencies: string): Object; From 3769701771f3273a903bbcd70bb2f7827137e118 Mon Sep 17 00:00:00 2001 From: dcrusader Date: Mon, 5 Jan 2015 19:09:08 -0800 Subject: [PATCH 007/104] Fix build errors harder --- di-lite/di-lite-test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/di-lite/di-lite-test.ts b/di-lite/di-lite-test.ts index eed9c2625d..8d6bfb777b 100644 --- a/di-lite/di-lite-test.ts +++ b/di-lite/di-lite-test.ts @@ -4,7 +4,7 @@ interface Dependency { dependencies?: string; } -function doTest(test: (ctx, ...obj: Dependency[]) => void) { +function doTest(test: (ctx: any, ...obj: Dependency[]) => void) { // create di context var ctx = di.createContext(), A: Dependency = () => { From 7e0d5648631c7f45be7a63c557de1bfa8bd182e6 Mon Sep 17 00:00:00 2001 From: Eugene <12kb@sibmail.com> Date: Wed, 7 Jan 2015 03:43:09 +0600 Subject: [PATCH 008/104] added EventDispatcher mixins --- threejs/three-orbitcontrols.d.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/threejs/three-orbitcontrols.d.ts b/threejs/three-orbitcontrols.d.ts index 4f905caa5d..e2c4a3caee 100644 --- a/threejs/three-orbitcontrols.d.ts +++ b/threejs/three-orbitcontrols.d.ts @@ -38,5 +38,11 @@ declare module THREE { mouseButtons: { ORBIT: MOUSE; ZOOM: MOUSE; PAN: MOUSE; }; update():void; + + // EventDispatcher mixins + addEventListener(type: string, listener: (event: any) => void ): void; + hasEventListener(type: string, listener: (event: any) => void): void; + removeEventListener(type: string, listener: (event: any) => void): void; + dispatchEvent(event: { type: string; target: any; }): void; } -} \ No newline at end of file +} From 65235fb1811e9dda6e068a15e5e56c4f2b35b874 Mon Sep 17 00:00:00 2001 From: David Gardiner Date: Wed, 7 Jan 2015 16:27:21 +1030 Subject: [PATCH 009/104] Add ActionHandlerMixin (send method, actions property) and update related classes --- ember/ember.d.ts | 51 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/ember/ember.d.ts b/ember/ember.d.ts index 307d47caf9..f40af66cc5 100644 --- a/ember/ember.d.ts +++ b/ember/ember.d.ts @@ -253,6 +253,20 @@ declare module Ember { **/ function A(arr?: any[]): NativeArray; /** + The Ember.ActionHandler mixin implements support for moving an actions property to an _actions + property at extend time, and adding _actions to the object's mergedProperties list. + **/ + class ActionHandlerMixin { + /** + Triggers a named action on the ActionHandler + **/ + send(name: string, ...args: any[]): void; + /** + The collection of functions, keyed by name, available on this ActionHandler as action targets. + **/ + actions: ActionsHash; + } + /** An instance of Ember.Application is the starting point for every Ember application. It helps to instantiate, initialize and coordinate the many objects that make up your app. **/ @@ -446,6 +460,11 @@ declare module Ember { controllers: {}; needs: string[]; target: any; + model: any; + queryParams: any; + send(name: string, ...args: any[]): void; + actions: {}; + } /** Array polyfills to support ES5 features in older browsers. @@ -719,15 +738,27 @@ declare module Ember { static isClass: boolean; static isMethod: boolean; } - class Controller extends Object { } - /** - Additional methods for the ControllerMixin. - **/ - class ControllerMixin { + class Controller extends Object implements ControllerMixin { replaceRoute(name: string, ...args: any[]): void; transitionToRoute(name: string, ...args: any[]): void; controllers: {}; + model: any; needs: string[]; + queryParams: any; + target: any; + send(name: string, ...args: any[]): void; + actions: ActionsHash; + } + /** + Additional methods for the ControllerMixin. + **/ + class ControllerMixin extends ActionHandlerMixin { + replaceRoute(name: string, ...args: any[]): void; + transitionToRoute(name: string, ...args: any[]): void; + controllers: {}; + model : any; + needs: string[]; + queryParams: any; target: any; } /** @@ -790,7 +821,7 @@ declare module Ember { and other classes like Ember._SimpleMetamorphView that don't need the fully functionaltiy of Ember.View. Unless you have specific needs for CoreView, you will use Ember.View in your applications. **/ - class CoreView extends Object { + class CoreView extends Object implements ActionHandlerMixin { static detect(obj: any): boolean; static detectInstance(obj: any): boolean; /** @@ -805,6 +836,8 @@ declare module Ember { static metaForProperty(key: string): {}; static isClass: boolean; static isMethod: boolean; + send(name: string, ...args: any[]): void; + actions: ActionsHash; parentView: CoreView; } class DAG { @@ -1449,6 +1482,10 @@ declare module Ember { controllers: Object; needs: string[]; target: any; + model: any; + queryParams: any; + send(name: string, ...args: any[]): void; + actions: {}; } class ObjectProxy extends Object { static detect(obj: any): boolean; @@ -1527,7 +1564,7 @@ declare module Ember { elementTag: string; parentBuffer: RenderBuffer; } - class Route extends Object { + class Route extends Object implements ActionHandlerMixin { static detect(obj: any): boolean; static detectInstance(obj: any): boolean; /** From e26b81b4e3063190c1e1adbb7c0621e82ad20951 Mon Sep 17 00:00:00 2001 From: David Gardiner Date: Wed, 7 Jan 2015 16:37:35 +1030 Subject: [PATCH 010/104] Add ActionHandlerMixin to Em module --- ember/ember.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/ember/ember.d.ts b/ember/ember.d.ts index f40af66cc5..b6cdde9d61 100644 --- a/ember/ember.d.ts +++ b/ember/ember.d.ts @@ -2218,6 +2218,7 @@ declare module Em { **/ var $: typeof Ember.$; var A: typeof Ember.A; + class ActionHandlerMixin extends Ember.ActionHandlerMixin { } class Application extends Ember.Application { } class Array extends Ember.Array { } class ArrayController extends Ember.ArrayController { } From 1a4e77db81896d8116a95305c058ca3376b07539 Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Wed, 7 Jan 2015 12:31:35 -0700 Subject: [PATCH 011/104] Export ViewModel and CollectionObservable CollectionObservable and ViewModel are commonly extended by consumers of Knockback and are part of the public api. --- knockback/knockback.d.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/knockback/knockback.d.ts b/knockback/knockback.d.ts index 71773ab92b..996878ceb6 100644 --- a/knockback/knockback.d.ts +++ b/knockback/knockback.d.ts @@ -3,7 +3,7 @@ // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// +/// a /// declare module Knockback { @@ -163,6 +163,8 @@ declare module Knockback { } interface Static extends Utils { + ViewModel; + CollectionObservable; collectionObservable(model?: Backbone.Collection, options?: CollectionOptions): CollectionObservable; /** Base class for observing model attributes. */ observable( From 55efb070ae349184f0f318d7f52fa33b236e7390 Mon Sep 17 00:00:00 2001 From: Rogier Schouten Date: Thu, 8 Jan 2015 17:06:20 +0100 Subject: [PATCH 012/104] Add typings for element-resize-event. --- CONTRIBUTORS.md | 1 + element-resize-event/element-resize-event-tests.ts | 8 ++++++++ element-resize-event/element-resize-event.d.ts | 9 +++++++++ 3 files changed, 18 insertions(+) create mode 100644 element-resize-event/element-resize-event-tests.ts create mode 100644 element-resize-event/element-resize-event.d.ts diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index d634fc8731..242fdb853c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -151,6 +151,7 @@ This document generated by [dt-contributors-generator](https://github.com/vvakam * [:link:](easystarjs/easystarjs.d.ts) [EasyStar.js](http://easystarjs.com) by [Magnus Gustafsson](https://github.com/borundin) * [:link:](ejs-locals/ejs-locals.d.ts) [ejs-locals](https://github.com/randometc/ejs-locals) by [jt000](https://github.com/jt000) * [:link:](jquery.elang/jquery.elang.d.ts) [eLang](https://github.com/sumegizoltan/ELang) by [Zoltan Sumegi](https://github.com/sumegizoltan) +* [:link:](element-resize-event/element-resize-event.d.ts) [ansicolors](https://github.com/KyleAMathews/element-resize-event) by [rogierschouten](https://github.com/rogierschouten) * [:link:](elm/elm.d.ts) [Elm](http://elm-lang.org) by [Dénes Harmath](https://github.com/thSoft) * [:link:](ember/ember.d.ts) [Ember.js](http://emberjs.com) by [Jed Mao](https://github.com/jedmao) * [:link:](emissary/emissary.d.ts) [emissary](https://github.com/atom/emissary) by [vvakame](https://github.com/vvakame) diff --git a/element-resize-event/element-resize-event-tests.ts b/element-resize-event/element-resize-event-tests.ts new file mode 100644 index 0000000000..6155fb1616 --- /dev/null +++ b/element-resize-event/element-resize-event-tests.ts @@ -0,0 +1,8 @@ +/// + +import ere = require("element-resize-event"); + +var domNode: Element = null; +ere(domNode, (): void => { +}); + diff --git a/element-resize-event/element-resize-event.d.ts b/element-resize-event/element-resize-event.d.ts new file mode 100644 index 0000000000..c1c03338dc --- /dev/null +++ b/element-resize-event/element-resize-event.d.ts @@ -0,0 +1,9 @@ +// Type definitions for element-resize-event 1.0.1 +// Project: https://github.com/KyleAMathews/element-resize-event +// Definitions by: Rogier Schouten +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "element-resize-event" { + function elementResizeEvent(domNode: Element, callback: () => void): void; + export = elementResizeEvent; +} From baf046fe784b43c2b20be34d643982b223aef05d Mon Sep 17 00:00:00 2001 From: Nils Lundquist Date: Thu, 8 Jan 2015 09:51:45 -0700 Subject: [PATCH 013/104] Removing 'a' typo --- knockback/knockback.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/knockback/knockback.d.ts b/knockback/knockback.d.ts index 996878ceb6..08798d47ab 100644 --- a/knockback/knockback.d.ts +++ b/knockback/knockback.d.ts @@ -3,7 +3,7 @@ // Definitions by: Boris Yankov // Definitions: https://github.com/borisyankov/DefinitelyTyped -/// a +/// /// declare module Knockback { From 025c836d3d54c769ba1dc9982beb09239d1b476e Mon Sep 17 00:00:00 2001 From: alphaleonis Date: Thu, 8 Jan 2015 19:33:21 +0100 Subject: [PATCH 014/104] Fixed incorrect definition of attributes property in ViewOptions. --- backbone/backbone.d.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backbone/backbone.d.ts b/backbone/backbone.d.ts index 4176724589..834ebc8318 100644 --- a/backbone/backbone.d.ts +++ b/backbone/backbone.d.ts @@ -311,14 +311,14 @@ declare module Backbone { private _updateHash(location: Location, fragment: string, replace: boolean): void; } - interface ViewOptions { - model?: TModel; - collection?: Backbone.Collection; - el?: any; - id?: string; - className?: string; - tagName?: string; - attributes?: any[]; + interface ViewOptions { + model?: TModel; + collection?: Backbone.Collection; + el?: any; + id?: string; + className?: string; + tagName?: string; + attributes?: {[id: string]: any}; } class View extends Events { From b32b06043b299381d2333f591af792b5ce20ea43 Mon Sep 17 00:00:00 2001 From: dcrusader Date: Thu, 8 Jan 2015 10:40:09 -0800 Subject: [PATCH 015/104] Use ghost module pattern from best practices --- di-lite/di-lite.d.ts | 97 ++++++++++++++++++++++++-------------------- 1 file changed, 54 insertions(+), 43 deletions(-) diff --git a/di-lite/di-lite.d.ts b/di-lite/di-lite.d.ts index 946fe9a3f8..356f70c7bc 100644 --- a/di-lite/di-lite.d.ts +++ b/di-lite/di-lite.d.ts @@ -3,56 +3,67 @@ // Definitions by: Timothy Morris // Definitions: https://github.com/borisyankov/DefinitelyTyped -interface DiLite { - version: string; - createContext(): DiCreateContext; - dependencyExpression(depExp: string): string; - entry(name: string, ctx: DiCreateContext): DiEntry; - strategy: DiStrategy; - factory: DiFactory; - utils: DiUtils; -} +declare module DiLite { + interface DiLiteStatic { + version: string; + createContext(): CreateContext; + dependencyExpression(depExp: string): string; + entry(name: string, ctx: CreateContext): any; + strategy: StrategyEnum; + factory: FactoryEnum; + utils: Utils; + } -interface DiCreateContext { - map: Object; - entry(name: string): Object; - register(name: string, type?: any, args?: any): DiEntry; - has(name: string): boolean; - "get"(name: string): any; - create(name: string, args: any): any; - initialize(): void; - clear(): void; - inject(name: string, o: Object, dependencies: string): Object; - ready(o: Function): Object; - ready(o: Object): Object; -} + interface Dictionary { + [index: string]: T; + } -interface DiEntry { - create(newArgs: any): DiEntry; - object(): Object; - object(o: Object): DiEntry; - strategy(s: Function): DiEntry; - type(t: any): DiEntry; - dependencies(d: string): DiEntry; - args(a: any): DiEntry; - factory(f: Function): DiEntry; -} + interface CreateContext { + map: Dictionary; + entry(name: string): T; + register(name: string, service: T): Entry; + has(name: string): boolean; + get(name: string): any; + create(name: string, args: any): T; + initialize(): void; + clear(): void; + inject(name: string, o: T, dependencies: string): T; + ready(o: Function): T; + ready(o: any): T; + } -interface DiStrategy { - proto(name: string, object: Object, type: any, args: any, ctx: DiCreateContext, dependencies: string): Object; - singleton(name: string, object: Object, type: any, args: any, ctx?: DiCreateContext, dependencies?: string): Object; -} + interface Entry { + create(newArgs: any): Entry; + object(o: T): Entry; + object(): T; + strategy(s: Function): Entry; + strategy(): T; + type(t: T): Entry; + type(): T; + dependencies(d: T): Entry; + dependencies(): T; + args(a: T): Entry; + args(): T; + factory(f: Function): Entry; + factory(): T; + } -interface DiFactory { - "constructor"(type: any, args: any): Object; - func(type: any, args: any): any; -} + interface StrategyEnum { + proto(name: string, object: TObject, type: TType, args: any, ctx: CreateContext, dependencies: any): TObject; + singleton(name: string, object: TObject, type: TType, args: any, ctx?: CreateContext, dependencies?: any): TObject; + } -interface DiUtils { - invokeStmt(args: any, op: string): string; + interface FactoryEnum { + constructor(type: T, args: any): T; + func(type: T, args: any): T; + } + + interface Utils { + invokeStmt(args: any, op: string): string; + } } declare module "di-lite" { export = di; } -declare var di: DiLite; +declare var di: DiLite.DiLiteStatic; From 4f2e203405a9dfa0d914d81b714981a758488628 Mon Sep 17 00:00:00 2001 From: Brian Dukes Date: Fri, 9 Jan 2015 14:32:41 -0600 Subject: [PATCH 016/104] Add jquery.tipsy --- jquery.tipsy/jquery.tipsy-tests.ts | 32 ++++++++++++++++++++++++++ jquery.tipsy/jquery.tipsy.d.ts | 36 ++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 jquery.tipsy/jquery.tipsy-tests.ts create mode 100644 jquery.tipsy/jquery.tipsy.d.ts diff --git a/jquery.tipsy/jquery.tipsy-tests.ts b/jquery.tipsy/jquery.tipsy-tests.ts new file mode 100644 index 0000000000..384e34a217 --- /dev/null +++ b/jquery.tipsy/jquery.tipsy-tests.ts @@ -0,0 +1,32 @@ +/// +/// + +// basic +$('#example-1').tipsy(); + +// code snippets from http://onehackoranother.com/projects/jquery/tipsy/ +$('#foo').tipsy({gravity: 'n'}); // nw | n | ne | w | e | sw | s | se + +$('#foo').tipsy({gravity: $.fn.tipsy.autoNS}); + +$('#example-fade').tipsy({fade: true}); + +$('#example-custom-attribute').tipsy({title: 'id'}); + +$('#example-callback').tipsy({title: function() { return this.getAttribute('original-title').toUpperCase(); } }); + +$('#example-fallback').tipsy({fallback: "Where's my tooltip yo'?" }); + +$('#example-html').tipsy({html: true }); + +$('#example-delay').tipsy({delayIn: 500, delayOut: 1000}); + +$(function() { + $('#focus-example [title]').tipsy({trigger: 'focus', gravity: 'w'}); +}); + +function onclickExample1() { $("#manual-example a[rel=tipsy]").tipsy("show"); return false; } +function onclickExample2() { $("#manual-example a[rel=tipsy]").tipsy("hide"); return false; } +$('#manual-example a[rel=tipsy]').tipsy({trigger: 'manual'}); + +$('a.live-tipsy').tipsy({live: true}); \ No newline at end of file diff --git a/jquery.tipsy/jquery.tipsy.d.ts b/jquery.tipsy/jquery.tipsy.d.ts new file mode 100644 index 0000000000..097f7ece86 --- /dev/null +++ b/jquery.tipsy/jquery.tipsy.d.ts @@ -0,0 +1,36 @@ +// Type definitions for jQuery.tipsy +// Project: http://onehackoranother.com/projects/jquery/tipsy/ +// https://github.com/jaz303/tipsy +// Definitions by: Brian Dukes +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +interface JQuery { + tipsy: JQueryTipsy.Tipsy; +} + + +declare module JQueryTipsy { + interface Tipsy { + (options?: Options): JQuery; + autoNS: () => string; + autoWE: () => string; + autoSWSE: () => string; + autoNWNE: () => string; + } + + interface Options { + delayIn?: number; + delayOut?: number; + fade?: boolean; + fallback?: string; + gravity?: any; // string or () => string + html?: boolean; + live?: boolean; + offset?: number; + opacity?: number; + title?: any; // string or () => string + trigger?: string; + } +} From d5baa434baf3acbaf5bec0a342b038f920a11034 Mon Sep 17 00:00:00 2001 From: Brian Dukes Date: Fri, 9 Jan 2015 14:47:20 -0600 Subject: [PATCH 017/104] Add JSDoc to jquery.tipsy --- jquery.tipsy/jquery.tipsy.d.ts | 95 +++++++++++++++++++++++++++++----- 1 file changed, 83 insertions(+), 12 deletions(-) diff --git a/jquery.tipsy/jquery.tipsy.d.ts b/jquery.tipsy/jquery.tipsy.d.ts index 097f7ece86..d586eefbde 100644 --- a/jquery.tipsy/jquery.tipsy.d.ts +++ b/jquery.tipsy/jquery.tipsy.d.ts @@ -1,36 +1,107 @@ // Type definitions for jQuery.tipsy // Project: http://onehackoranother.com/projects/jquery/tipsy/ -// https://github.com/jaz303/tipsy // Definitions by: Brian Dukes // Definitions: https://github.com/borisyankov/DefinitelyTyped /// interface JQuery { + /** + * initialize tipsy plugin + */ tipsy: JQueryTipsy.Tipsy; } - -declare module JQueryTipsy { - interface Tipsy { - (options?: Options): JQuery; - autoNS: () => string; - autoWE: () => string; - autoSWSE: () => string; - autoNWNE: () => string; - } - +declare module JQueryTipsy { interface Options { + /** + * delay before showing tooltip (ms) + * + * default: 0 + */ delayIn?: number; + /** + * delay before hiding tooltip (ms) + * + * default: 0 + */ delayOut?: number; + /** + * fade tooltips in/out? + * + * default: false + */ fade?: boolean; + /** + * fallback text to use when no tooltip text + * + * default: '' + */ fallback?: string; + /** + * gravity + * + * default: 'n' + */ gravity?: any; // string or () => string + /** + * is tooltip content HTML? + * + * default: false + */ html?: boolean; + /** + * use live event support? + * + * default: false + */ live?: boolean; + /** + * pixel offset of tooltip from element + * + * default: 0 + */ offset?: number; + /** + * opacity of tooltip + * + * default: 0.8 + */ opacity?: number; + /** + * attribute/callback containing tooltip text + * + * default: 'title' + */ title?: any; // string or () => string + /** + * how tooltip is triggered - hover | focus | manual + * + * default: 'hover' + */ trigger?: string; - } + } + + interface Tipsy { + /** + * initialize tipsy plugin + */ + (options?: Options): JQuery; + /** + * determine gravity either to North or South automatically based on the element's location in the viewport + */ + autoNS: () => string; + /** + * determine gravity either to West or East automatically based on the element's location in the viewport + */ + autoWE: () => string; + /** + * determine gravity either to Southwest or Southeast automatically based on the element's location in the viewport + */ + autoSWSE: () => string; + /** + * determine gravity either to Northwest or Northeast automatically based on the element's location in the viewport + */ + autoNWNE: () => string; + } } From 343b20868e8dfcab935e177176d5b88db2d0bdf9 Mon Sep 17 00:00:00 2001 From: Yang Guan Date: Fri, 9 Jan 2015 13:51:38 -0800 Subject: [PATCH 018/104] Update typing files for leaflet --- leaflet/leaflet.d.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/leaflet/leaflet.d.ts b/leaflet/leaflet.d.ts index 0c5f48d0a9..ff90fb479f 100644 --- a/leaflet/leaflet.d.ts +++ b/leaflet/leaflet.d.ts @@ -2335,6 +2335,10 @@ declare module L { */ attributionControl: Control.Attribution; + /** + * Map state options + */ + options: MapOptions; //////////////// //////////////// From d29929c13587b606152783fa18fb053b17404065 Mon Sep 17 00:00:00 2001 From: Phips Peter Date: Fri, 9 Jan 2015 15:06:02 -0800 Subject: [PATCH 019/104] Adding a JsDom type definition JsDom is great for being able to parse and understand HTML --- jsdom/jsdom-tests.ts | 72 ++++++++++++++++++++++++++++++++++++++++++++ jsdom/jsdom.d.ts | 41 +++++++++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 jsdom/jsdom-tests.ts create mode 100644 jsdom/jsdom.d.ts diff --git a/jsdom/jsdom-tests.ts b/jsdom/jsdom-tests.ts new file mode 100644 index 0000000000..87eddbfc5f --- /dev/null +++ b/jsdom/jsdom-tests.ts @@ -0,0 +1,72 @@ +import jsdom = require("jsdom"); + +jsdom.env( + "http://nodejs.org/dist/", + ["http://code.jquery.com/jquery.js"], + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + "http://nodejs.org/dist/", + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + "http://nodejs.org/dist/", + { + scripts: ["http://code.jquery.com/jquery.js"], + }, + function (errors, window) { + console.log("there have been nodejs releases!"); + } +); + +jsdom.env( + '

jsdom!

', + ["http://code.jquery.com/jquery.js"], + function (errors, window) { + console.log("contents of a.the-link:", (window).$("a.the-link").text()); + } +); + +jsdom.env({ + url: "http://news.ycombinator.com/", + scripts: ["http://code.jquery.com/jquery.js"], + done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function() { + console.log(" -", $(this).text()); + }); + } +}); + +var jquery: string; + +jsdom.env({ + url: "http://news.ycombinator.com/", + src: [jquery], + done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function () { + console.log(" -", $(this).text()); + }); + } +}); + +var window = jsdom.jsdom().parentWindow; +var window = jsdom.jsdom("
foobar
").parentWindow; +var window = jsdom.jsdom("
foobar
", { +scripts: ["http://code.jquery.com/jquery.js"], +done: function (errors, window) { + var $ = (window).$; + console.log("HN Links"); + $("td.title:not(:last) a").each(function() { + console.log(" -", $(this).text()); + }); +}}).parentWindow; \ No newline at end of file diff --git a/jsdom/jsdom.d.ts b/jsdom/jsdom.d.ts new file mode 100644 index 0000000000..4dbcb086e9 --- /dev/null +++ b/jsdom/jsdom.d.ts @@ -0,0 +1,41 @@ +// Type definitions for jsdom 2.0.0 +// Project: https://github.com/tmpvar/jsdom +// Definitions by: Asana +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "jsdom" { + export function env(config: Config): void; + export function env(htmlRef: string, callback: Callback): void; + export function env(htmlRef: string, scripts: string[], callback: Callback): void; + export function env(htmlRef: string, config: Config, callback: Callback): void; + export function env(htmlRef: string, scripts: string[], config: Config, callback: Callback): void; + export function jsdom(markup?: string, options?: Config): Document; + + interface Callback { + (errors: Error[], window: Window): any; + } + + interface Config { + html?: string; + file?: string; + url?: string; + scripts?: string[]; + src?: string[]; + jar?: Object; + parsingMode?: string; + document?: { + referrer?: string; + cookie?: string; + cookieDomain?: string; + }; + headers?: Object; + features?: { + FetchExternalResources?: any; // string | string[] | boolean + ProcessExternalResources?: any; // string | string[] | boolean + SkipExternalResources?: any; // RegExp | boolean + }; + created?: Callback; + loaded?: Callback; + done?: Callback; + } +} \ No newline at end of file From ff0c34bc71f17d19cde3a6cedd94bf9ff4729850 Mon Sep 17 00:00:00 2001 From: Eric Lu Date: Fri, 9 Jan 2015 15:47:05 -0800 Subject: [PATCH 020/104] Add typing for bunyan logger associated with Request --- restify/restify.d.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/restify/restify.d.ts b/restify/restify.d.ts index 38a43f0dd4..f1cc9766a0 100644 --- a/restify/restify.d.ts +++ b/restify/restify.d.ts @@ -4,10 +4,11 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// - +/// declare module "restify" { import http = require('http'); + import bunyan = require('bunyan'); interface addressInterface { @@ -24,7 +25,7 @@ declare module "restify" { contentLength: number; contentType: string; href: () => string; - log: Object; + log: bunyan.Logger; id: string; path: () => string; query: any; @@ -210,7 +211,7 @@ declare module "restify" { export function fullResponse(): RequestHandler; export var defaultResponseHeaders : any; export var CORS: CORS; - + export module pre { export function pause(): RequestHandler; export function sanitizePath(options?: any): RequestHandler; From 886497fa30033a9207664ea4b04bc078e35145cb Mon Sep 17 00:00:00 2001 From: Jiawei Li Date: Thu, 8 Jan 2015 22:18:42 -0800 Subject: [PATCH 021/104] moment: expose interfaces enables type annotations for files using moment definitions as an external module --- jquery.livestampjs/jquery.livestampjs.d.ts | 2 +- moment-timezone/moment-timezone.d.ts | 28 +- moment/moment-external-tests.ts | 10 +- moment/moment-tests.ts | 10 +- moment/moment.d.ts | 932 +++++++++++---------- 5 files changed, 494 insertions(+), 488 deletions(-) diff --git a/jquery.livestampjs/jquery.livestampjs.d.ts b/jquery.livestampjs/jquery.livestampjs.d.ts index 35453d4f3f..df96f14287 100644 --- a/jquery.livestampjs/jquery.livestampjs.d.ts +++ b/jquery.livestampjs/jquery.livestampjs.d.ts @@ -22,7 +22,7 @@ interface JQueryStatic { interface JQuery { livestamp(date: Date): JQuery; - livestamp(moment: Moment): JQuery; + livestamp(moment: moment.Moment): JQuery; livestamp(timestamp: number): JQuery; livestamp(timestamp: string): JQuery; } diff --git a/moment-timezone/moment-timezone.d.ts b/moment-timezone/moment-timezone.d.ts index 9553faa3ad..1e908ace10 100644 --- a/moment-timezone/moment-timezone.d.ts +++ b/moment-timezone/moment-timezone.d.ts @@ -5,8 +5,14 @@ /// -interface Moment { - tz(timezone: string): Moment; +declare module moment { + interface Moment { + tz(timezone: string): Moment; + } + + interface MomentStatic { + tz: MomentTimezone; + } } interface MomentZone { @@ -21,12 +27,12 @@ interface MomentZone { } interface MomentTimezone { - (date: number, timezone: string): Moment; - (date: number[], timezone: string): Moment; - (date: string, format: string, timezone: string): Moment; - (date: Date, timezone: string): Moment; - (date: Moment, timezone: string): Moment; - (date: Object, timezone: string): Moment; + (date: number, timezone: string): moment.Moment; + (date: number[], timezone: string): moment.Moment; + (date: string, format: string, timezone: string): moment.Moment; + (date: Date, timezone: string): moment.Moment; + (date: moment.Moment, timezone: string): moment.Moment; + (date: Object, timezone: string): moment.Moment; zone(timezone: string): MomentZone; @@ -45,12 +51,8 @@ interface MomentTimezone { names(): string[]; } -interface MomentStatic { - tz: MomentTimezone; -} - declare module 'moment-timezone' { - var _tmp: MomentStatic; + var _tmp: moment.MomentStatic; export = _tmp; } diff --git a/moment/moment-external-tests.ts b/moment/moment-external-tests.ts index 14376f2b4d..ced06cdbf0 100644 --- a/moment/moment-external-tests.ts +++ b/moment/moment-external-tests.ts @@ -302,7 +302,7 @@ moment.locale('en', { }); moment.locale('en', { - months : function (momentToFormat: Moment, format: string) { + months : function (momentToFormat: moment.Moment, format: string) { // momentToFormat is the moment currently being formatted // format is the formatting string if (/^MMMM/.test(format)) { // if the format starts with 'MMMM' @@ -321,7 +321,7 @@ moment.locale('en', { }); moment.locale('en', { - monthsShort : function (momentToFormat: Moment, format: string) { + monthsShort : function (momentToFormat: moment.Moment, format: string) { if (/^MMMM/.test(format)) { return this.nominative[momentToFormat.month()]; } else { @@ -337,7 +337,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdays : function (momentToFormat: Moment) { + weekdays : function (momentToFormat: moment.Moment) { return this.weekdays[momentToFormat.day()]; } }); @@ -347,7 +347,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdaysShort : function (momentToFormat: Moment) { + weekdaysShort : function (momentToFormat: moment.Moment) { return this.weekdaysShort[momentToFormat.day()]; } }); @@ -357,7 +357,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdaysMin : function (momentToFormat: Moment) { + weekdaysMin : function (momentToFormat: moment.Moment) { return this.weekdaysMin[momentToFormat.day()]; } }); diff --git a/moment/moment-tests.ts b/moment/moment-tests.ts index 962c11294d..d58a27fe35 100644 --- a/moment/moment-tests.ts +++ b/moment/moment-tests.ts @@ -302,7 +302,7 @@ moment.locale('en', { }); moment.locale('en', { - months : function (momentToFormat: Moment, format: string) { + months : function (momentToFormat: moment.Moment, format: string) { // momentToFormat is the moment currently being formatted // format is the formatting string if (/^MMMM/.test(format)) { // if the format starts with 'MMMM' @@ -321,7 +321,7 @@ moment.locale('en', { }); moment.locale('en', { - monthsShort : function (momentToFormat: Moment, format: string) { + monthsShort : function (momentToFormat: moment.Moment, format: string) { if (/^MMMM/.test(format)) { return this.nominative[momentToFormat.month()]; } else { @@ -337,7 +337,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdays : function (momentToFormat: Moment) { + weekdays : function (momentToFormat: moment.Moment) { return this.weekdays[momentToFormat.day()]; } }); @@ -347,7 +347,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdaysShort : function (momentToFormat: Moment) { + weekdaysShort : function (momentToFormat: moment.Moment) { return this.weekdaysShort[momentToFormat.day()]; } }); @@ -357,7 +357,7 @@ moment.locale('en', { }); moment.locale('en', { - weekdaysMin : function (momentToFormat: Moment) { + weekdaysMin : function (momentToFormat: moment.Moment) { return this.weekdaysMin[momentToFormat.day()]; } }); diff --git a/moment/moment.d.ts b/moment/moment.d.ts index 200e46e2b6..4d315946b9 100644 --- a/moment/moment.d.ts +++ b/moment/moment.d.ts @@ -1,464 +1,468 @@ -// Type definitions for Moment.js 2.8.0 -// Project: https://github.com/timrwood/moment -// Definitions by: Michael Lakerveld , Aaron King , Hiroki Horiuchi , Dick van den Brink , Adi Dahiya -// Definitions: https://github.com/borisyankov/DefinitelyTyped - -interface MomentInput { - - years?: number; - y?: number; - - months?: number; - M?: number; - - weeks?: number; - w?: number; - - days?: number; - d?: number; - - hours?: number; - h?: number; - - minutes?: number; - m?: number; - - seconds?: number; - s?: number; - - milliseconds?: number; - ms?: number; - -} - -interface Duration { - - humanize(withSuffix?: boolean): string; - - as(units: string): number; - - milliseconds(): number; - asMilliseconds(): number; - - seconds(): number; - asSeconds(): number; - - minutes(): number; - asMinutes(): number; - - hours(): number; - asHours(): number; - - days(): number; - asDays(): number; - - months(): number; - asMonths(): number; - - years(): number; - asYears(): number; - - add(n: number, p: string): Duration; - add(n: number): Duration; - add(d: Duration): Duration; - - subtract(n: number, p: string): Duration; - subtract(n: number): Duration; - subtract(d: Duration): Duration; - - toISOString(): string; - -} - -interface Moment { - - format(format: string): string; - format(): string; - - fromNow(withoutSuffix?: boolean): string; - - startOf(unitOfTime: string): Moment; - endOf(unitOfTime: string): Moment; - - /** - * Mutates the original moment by adding time. (deprecated in 2.8.0) - * - * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) - * @param amount the amount you want to add - */ - add(unitOfTime: string, amount: number): Moment; - /** - * Mutates the original moment by adding time. - * - * @param amount the amount you want to add - * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) - */ - add(amount: number, unitOfTime: string): Moment; - /** - * Mutates the original moment by adding time. Note that the order of arguments can be flipped. - * - * @param amount the amount you want to add - * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) - */ - add(amount: string, unitOfTime: string): Moment; - /** - * Mutates the original moment by adding time. - * - * @param objectLiteral an object literal that describes multiple time units {days:7,months:1} - */ - add(objectLiteral: MomentInput): Moment; - /** - * Mutates the original moment by adding time. - * - * @param duration a length of time - */ - add(duration: Duration): Moment; - - /** - * Mutates the original moment by subtracting time. (deprecated in 2.8.0) - * - * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) - * @param amount the amount you want to subtract - */ - subtract(unitOfTime: string, amount: number): Moment; - /** - * Mutates the original moment by subtracting time. - * - * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) - * @param amount the amount you want to subtract - */ - subtract(amount: number, unitOfTime: string): Moment; - /** - * Mutates the original moment by subtracting time. Note that the order of arguments can be flipped. - * - * @param amount the amount you want to add - * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) - */ - subtract(amount: string, unitOfTime: string): Moment; - /** - * Mutates the original moment by subtracting time. - * - * @param objectLiteral an object literal that describes multiple time units {days:7,months:1} - */ - subtract(objectLiteral: MomentInput): Moment; - /** - * Mutates the original moment by subtracting time. - * - * @param duration a length of time - */ - subtract(duration: Duration): Moment; - - calendar(): string; - calendar(start: Moment): string; - - clone(): Moment; - - /** - * @return Unix timestamp, or milliseconds since the epoch. - */ - valueOf(): number; - - local(): Moment; // current date/time in local mode - - utc(): Moment; // current date/time in UTC mode - - isValid(): boolean; - - year(y: number): Moment; - year(): number; - quarter(): number; - quarter(q: number): Moment; - month(M: number): Moment; - month(M: string): Moment; - month(): number; - day(d: number): Moment; - day(d: string): Moment; - day(): number; - date(d: number): Moment; - date(): number; - hour(h: number): Moment; - hour(): number; - hours(h: number): Moment; - hours(): number; - minute(m: number): Moment; - minute(): number; - minutes(m: number): Moment; - minutes(): number; - second(s: number): Moment; - second(): number; - seconds(s: number): Moment; - seconds(): number; - millisecond(ms: number): Moment; - millisecond(): number; - milliseconds(ms: number): Moment; - milliseconds(): number; - weekday(): number; - weekday(d: number): Moment; - isoWeekday(): number; - isoWeekday(d: number): Moment; - weekYear(): number; - weekYear(d: number): Moment; - isoWeekYear(): number; - isoWeekYear(d: number): Moment; - week(): number; - week(d: number): Moment; - weeks(): number; - weeks(d: number): Moment; - isoWeek(): number; - isoWeek(d: number): Moment; - isoWeeks(): number; - isoWeeks(d: number): Moment; - weeksInYear(): number; - isoWeeksInYear(): number; - dayOfYear(): number; - dayOfYear(d: number): Moment; - - from(f: Moment): string; - from(f: Moment, suffix: boolean): string; - from(d: Date): string; - from(s: string): string; - from(date: number[]): string; - - diff(b: Moment): number; - diff(b: Moment, unitOfTime: string): number; - diff(b: Moment, unitOfTime: string, round: boolean): number; - - toDate(): Date; - toISOString(): string; - unix(): number; - - isLeapYear(): boolean; - zone(): number; - zone(b: number): Moment; - zone(b: string): Moment; - daysInMonth(): number; - isDST(): boolean; - - isBefore(): boolean; - isBefore(b: Moment): boolean; - isBefore(b: string): boolean; - isBefore(b: Number): boolean; - isBefore(b: Date): boolean; - isBefore(b: number[]): boolean; - isBefore(b: Moment, granularity: string): boolean; - isBefore(b: String, granularity: string): boolean; - isBefore(b: Number, granularity: string): boolean; - isBefore(b: Date, granularity: string): boolean; - isBefore(b: number[], granularity: string): boolean; - - isAfter(): boolean; - isAfter(b: Moment): boolean; - isAfter(b: string): boolean; - isAfter(b: Number): boolean; - isAfter(b: Date): boolean; - isAfter(b: number[]): boolean; - isAfter(b: Moment, granularity: string): boolean; - isAfter(b: String, granularity: string): boolean; - isAfter(b: Number, granularity: string): boolean; - isAfter(b: Date, granularity: string): boolean; - isAfter(b: number[], granularity: string): boolean; - - isSame(b: Moment): boolean; - isSame(b: string): boolean; - isSame(b: Number): boolean; - isSame(b: Date): boolean; - isSame(b: number[]): boolean; - isSame(b: Moment, granularity: string): boolean; - isSame(b: String, granularity: string): boolean; - isSame(b: Number, granularity: string): boolean; - isSame(b: Date, granularity: string): boolean; - isSame(b: number[], granularity: string): boolean; - - // Deprecated as of 2.8.0. - lang(language: string): Moment; - lang(reset: boolean): Moment; - lang(): MomentLanguage; - - locale(language: string): Moment; - locale(reset: boolean): Moment; - locale(): string; - - localeData(language: string): Moment; - localeData(reset: boolean): Moment; - localeData(): MomentLanguage; - - // Deprecated as of 2.7.0. - max(date: Date): Moment; - max(date: number): Moment; - max(date: any[]): Moment; - max(date: string): Moment; - max(date: string, format: string): Moment; - max(clone: Moment): Moment; - - // Deprecated as of 2.7.0. - min(date: Date): Moment; - min(date: number): Moment; - min(date: any[]): Moment; - min(date: string): Moment; - min(date: string, format: string): Moment; - min(clone: Moment): Moment; - - get(unit: string): number; - set(unit: string, value: number): Moment; - -} - -interface MomentCalendar { - - lastDay: any; - sameDay: any; - nextDay: any; - lastWeek: any; - nextWeek: any; - sameElse: any; - -} - -interface MomentLanguage { - - months?: any; - monthsShort?: any; - weekdays?: any; - weekdaysShort?: any; - weekdaysMin?: any; - longDateFormat?: MomentLongDateFormat; - relativeTime?: MomentRelativeTime; - meridiem?: (hour: number, minute: number, isLowercase: boolean) => string; - calendar?: MomentCalendar; - ordinal?: (num: number) => string; - -} - -interface MomentLongDateFormat { - - L: string; - LL: string; - LLL: string; - LLLL: string; - LT: string; - l?: string; - ll?: string; - lll?: string; - llll?: string; - lt?: string; - -} - -interface MomentRelativeTime { - - future: any; - past: any; - s: any; - m: any; - mm: any; - h: any; - hh: any; - d: any; - dd: any; - M: any; - MM: any; - y: any; - yy: any; - -} - -interface MomentStatic { - - version: string; - - (): Moment; - (date: number): Moment; - (date: number[]): Moment; - (date: string, format?: string, strict?: boolean): Moment; - (date: string, format?: string, language?: string, strict?: boolean): Moment; - (date: string, formats: string[], strict?: boolean): Moment; - (date: string, formats: string[], language?: string, strict?: boolean): Moment; - (date: string, specialFormat: () => void, strict?: boolean): Moment; - (date: string, specialFormat: () => void, language?: string, strict?: boolean): Moment; - (date: string, formatsIncludingSpecial: any[], strict?: boolean): Moment; - (date: string, formatsIncludingSpecial: any[], language?: string, strict?: boolean): Moment; - (date: Date): Moment; - (date: Moment): Moment; - (date: Object): Moment; - - utc(): Moment; - utc(date: number): Moment; - utc(date: number[]): Moment; - utc(date: string, format?: string, strict?: boolean): Moment; - utc(date: string, format?: string, language?: string, strict?: boolean): Moment; - utc(date: string, formats: string[], strict?: boolean): Moment; - utc(date: string, formats: string[], language?: string, strict?: boolean): Moment; - utc(date: Date): Moment; - utc(date: Moment): Moment; - utc(date: Object): Moment; - - unix(timestamp: number): Moment; - - invalid(parsingFlags?: Object): Moment; - isMoment(): boolean; - isMoment(m: any): boolean; - - // Deprecated in 2.8.0. - lang(language?: string): string; - lang(language?: string, definition?: MomentLanguage): string; - - locale(language?: string): string; - locale(language?: string[]): string; - locale(language?: string, definition?: MomentLanguage): string; - - localeData(language?: string): MomentLanguage; - - longDateFormat: any; - relativeTime: any; - meridiem: (hour: number, minute: number, isLowercase: boolean) => string; - calendar: any; - ordinal: (num: number) => string; - - duration(milliseconds: Number): Duration; - duration(num: Number, unitOfTime: string): Duration; - duration(input: MomentInput): Duration; - duration(object: any): Duration; - duration(): Duration; - - parseZone(date: string): Moment; - - months(): string[]; - months(index: number): string; - months(format: string): string[]; - months(format: string, index: number): string; - monthsShort(): string[]; - monthsShort(index: number): string; - monthsShort(format: string): string[]; - monthsShort(format: string, index: number): string; - - weekdays(): string[]; - weekdays(index: number): string; - weekdays(format: string): string[]; - weekdays(format: string, index: number): string; - weekdaysShort(): string[]; - weekdaysShort(index: number): string; - weekdaysShort(format: string): string[]; - weekdaysShort(format: string, index: number): string; - weekdaysMin(): string[]; - weekdaysMin(index: number): string; - weekdaysMin(format: string): string[]; - weekdaysMin(format: string, index: number): string; - - min(moments: Moment[]): Moment; - max(moments: Moment[]): Moment; - - normalizeUnits(unit: string): string; - relativeTimeThreshold(threshold: string, limit: number): void; - - /** - * Constant used to enable explicit ISO_8601 format parsing. - */ - ISO_8601(): void; - -} - -declare var moment: MomentStatic; - -declare module 'moment' { - export = moment; -} +// Type definitions for Moment.js 2.8.0 +// Project: https://github.com/timrwood/moment +// Definitions by: Michael Lakerveld , Aaron King , Hiroki Horiuchi , Dick van den Brink , Adi Dahiya +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module moment { + + interface MomentInput { + + years?: number; + y?: number; + + months?: number; + M?: number; + + weeks?: number; + w?: number; + + days?: number; + d?: number; + + hours?: number; + h?: number; + + minutes?: number; + m?: number; + + seconds?: number; + s?: number; + + milliseconds?: number; + ms?: number; + + } + + interface Duration { + + humanize(withSuffix?: boolean): string; + + as(units: string): number; + + milliseconds(): number; + asMilliseconds(): number; + + seconds(): number; + asSeconds(): number; + + minutes(): number; + asMinutes(): number; + + hours(): number; + asHours(): number; + + days(): number; + asDays(): number; + + months(): number; + asMonths(): number; + + years(): number; + asYears(): number; + + add(n: number, p: string): Duration; + add(n: number): Duration; + add(d: Duration): Duration; + + subtract(n: number, p: string): Duration; + subtract(n: number): Duration; + subtract(d: Duration): Duration; + + toISOString(): string; + + } + + interface Moment { + + format(format: string): string; + format(): string; + + fromNow(withoutSuffix?: boolean): string; + + startOf(unitOfTime: string): Moment; + endOf(unitOfTime: string): Moment; + + /** + * Mutates the original moment by adding time. (deprecated in 2.8.0) + * + * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) + * @param amount the amount you want to add + */ + add(unitOfTime: string, amount: number): Moment; + /** + * Mutates the original moment by adding time. + * + * @param amount the amount you want to add + * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) + */ + add(amount: number, unitOfTime: string): Moment; + /** + * Mutates the original moment by adding time. Note that the order of arguments can be flipped. + * + * @param amount the amount you want to add + * @param unitOfTime the unit of time you want to add (eg "years" / "hours" etc) + */ + add(amount: string, unitOfTime: string): Moment; + /** + * Mutates the original moment by adding time. + * + * @param objectLiteral an object literal that describes multiple time units {days:7,months:1} + */ + add(objectLiteral: MomentInput): Moment; + /** + * Mutates the original moment by adding time. + * + * @param duration a length of time + */ + add(duration: Duration): Moment; + + /** + * Mutates the original moment by subtracting time. (deprecated in 2.8.0) + * + * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) + * @param amount the amount you want to subtract + */ + subtract(unitOfTime: string, amount: number): Moment; + /** + * Mutates the original moment by subtracting time. + * + * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) + * @param amount the amount you want to subtract + */ + subtract(amount: number, unitOfTime: string): Moment; + /** + * Mutates the original moment by subtracting time. Note that the order of arguments can be flipped. + * + * @param amount the amount you want to add + * @param unitOfTime the unit of time you want to subtract (eg "years" / "hours" etc) + */ + subtract(amount: string, unitOfTime: string): Moment; + /** + * Mutates the original moment by subtracting time. + * + * @param objectLiteral an object literal that describes multiple time units {days:7,months:1} + */ + subtract(objectLiteral: MomentInput): Moment; + /** + * Mutates the original moment by subtracting time. + * + * @param duration a length of time + */ + subtract(duration: Duration): Moment; + + calendar(): string; + calendar(start: Moment): string; + + clone(): Moment; + + /** + * @return Unix timestamp, or milliseconds since the epoch. + */ + valueOf(): number; + + local(): Moment; // current date/time in local mode + + utc(): Moment; // current date/time in UTC mode + + isValid(): boolean; + + year(y: number): Moment; + year(): number; + quarter(): number; + quarter(q: number): Moment; + month(M: number): Moment; + month(M: string): Moment; + month(): number; + day(d: number): Moment; + day(d: string): Moment; + day(): number; + date(d: number): Moment; + date(): number; + hour(h: number): Moment; + hour(): number; + hours(h: number): Moment; + hours(): number; + minute(m: number): Moment; + minute(): number; + minutes(m: number): Moment; + minutes(): number; + second(s: number): Moment; + second(): number; + seconds(s: number): Moment; + seconds(): number; + millisecond(ms: number): Moment; + millisecond(): number; + milliseconds(ms: number): Moment; + milliseconds(): number; + weekday(): number; + weekday(d: number): Moment; + isoWeekday(): number; + isoWeekday(d: number): Moment; + weekYear(): number; + weekYear(d: number): Moment; + isoWeekYear(): number; + isoWeekYear(d: number): Moment; + week(): number; + week(d: number): Moment; + weeks(): number; + weeks(d: number): Moment; + isoWeek(): number; + isoWeek(d: number): Moment; + isoWeeks(): number; + isoWeeks(d: number): Moment; + weeksInYear(): number; + isoWeeksInYear(): number; + dayOfYear(): number; + dayOfYear(d: number): Moment; + + from(f: Moment): string; + from(f: Moment, suffix: boolean): string; + from(d: Date): string; + from(s: string): string; + from(date: number[]): string; + + diff(b: Moment): number; + diff(b: Moment, unitOfTime: string): number; + diff(b: Moment, unitOfTime: string, round: boolean): number; + + toDate(): Date; + toISOString(): string; + unix(): number; + + isLeapYear(): boolean; + zone(): number; + zone(b: number): Moment; + zone(b: string): Moment; + daysInMonth(): number; + isDST(): boolean; + + isBefore(): boolean; + isBefore(b: Moment): boolean; + isBefore(b: string): boolean; + isBefore(b: Number): boolean; + isBefore(b: Date): boolean; + isBefore(b: number[]): boolean; + isBefore(b: Moment, granularity: string): boolean; + isBefore(b: String, granularity: string): boolean; + isBefore(b: Number, granularity: string): boolean; + isBefore(b: Date, granularity: string): boolean; + isBefore(b: number[], granularity: string): boolean; + + isAfter(): boolean; + isAfter(b: Moment): boolean; + isAfter(b: string): boolean; + isAfter(b: Number): boolean; + isAfter(b: Date): boolean; + isAfter(b: number[]): boolean; + isAfter(b: Moment, granularity: string): boolean; + isAfter(b: String, granularity: string): boolean; + isAfter(b: Number, granularity: string): boolean; + isAfter(b: Date, granularity: string): boolean; + isAfter(b: number[], granularity: string): boolean; + + isSame(b: Moment): boolean; + isSame(b: string): boolean; + isSame(b: Number): boolean; + isSame(b: Date): boolean; + isSame(b: number[]): boolean; + isSame(b: Moment, granularity: string): boolean; + isSame(b: String, granularity: string): boolean; + isSame(b: Number, granularity: string): boolean; + isSame(b: Date, granularity: string): boolean; + isSame(b: number[], granularity: string): boolean; + + // Deprecated as of 2.8.0. + lang(language: string): Moment; + lang(reset: boolean): Moment; + lang(): MomentLanguage; + + locale(language: string): Moment; + locale(reset: boolean): Moment; + locale(): string; + + localeData(language: string): Moment; + localeData(reset: boolean): Moment; + localeData(): MomentLanguage; + + // Deprecated as of 2.7.0. + max(date: Date): Moment; + max(date: number): Moment; + max(date: any[]): Moment; + max(date: string): Moment; + max(date: string, format: string): Moment; + max(clone: Moment): Moment; + + // Deprecated as of 2.7.0. + min(date: Date): Moment; + min(date: number): Moment; + min(date: any[]): Moment; + min(date: string): Moment; + min(date: string, format: string): Moment; + min(clone: Moment): Moment; + + get(unit: string): number; + set(unit: string, value: number): Moment; + + } + + interface MomentCalendar { + + lastDay: any; + sameDay: any; + nextDay: any; + lastWeek: any; + nextWeek: any; + sameElse: any; + + } + + interface MomentLanguage { + + months?: any; + monthsShort?: any; + weekdays?: any; + weekdaysShort?: any; + weekdaysMin?: any; + longDateFormat?: MomentLongDateFormat; + relativeTime?: MomentRelativeTime; + meridiem?: (hour: number, minute: number, isLowercase: boolean) => string; + calendar?: MomentCalendar; + ordinal?: (num: number) => string; + + } + + interface MomentLongDateFormat { + + L: string; + LL: string; + LLL: string; + LLLL: string; + LT: string; + l?: string; + ll?: string; + lll?: string; + llll?: string; + lt?: string; + + } + + interface MomentRelativeTime { + + future: any; + past: any; + s: any; + m: any; + mm: any; + h: any; + hh: any; + d: any; + dd: any; + M: any; + MM: any; + y: any; + yy: any; + + } + + interface MomentStatic { + + version: string; + + (): Moment; + (date: number): Moment; + (date: number[]): Moment; + (date: string, format?: string, strict?: boolean): Moment; + (date: string, format?: string, language?: string, strict?: boolean): Moment; + (date: string, formats: string[], strict?: boolean): Moment; + (date: string, formats: string[], language?: string, strict?: boolean): Moment; + (date: string, specialFormat: () => void, strict?: boolean): Moment; + (date: string, specialFormat: () => void, language?: string, strict?: boolean): Moment; + (date: string, formatsIncludingSpecial: any[], strict?: boolean): Moment; + (date: string, formatsIncludingSpecial: any[], language?: string, strict?: boolean): Moment; + (date: Date): Moment; + (date: Moment): Moment; + (date: Object): Moment; + + utc(): Moment; + utc(date: number): Moment; + utc(date: number[]): Moment; + utc(date: string, format?: string, strict?: boolean): Moment; + utc(date: string, format?: string, language?: string, strict?: boolean): Moment; + utc(date: string, formats: string[], strict?: boolean): Moment; + utc(date: string, formats: string[], language?: string, strict?: boolean): Moment; + utc(date: Date): Moment; + utc(date: Moment): Moment; + utc(date: Object): Moment; + + unix(timestamp: number): Moment; + + invalid(parsingFlags?: Object): Moment; + isMoment(): boolean; + isMoment(m: any): boolean; + + // Deprecated in 2.8.0. + lang(language?: string): string; + lang(language?: string, definition?: MomentLanguage): string; + + locale(language?: string): string; + locale(language?: string[]): string; + locale(language?: string, definition?: MomentLanguage): string; + + localeData(language?: string): MomentLanguage; + + longDateFormat: any; + relativeTime: any; + meridiem: (hour: number, minute: number, isLowercase: boolean) => string; + calendar: any; + ordinal: (num: number) => string; + + duration(milliseconds: Number): Duration; + duration(num: Number, unitOfTime: string): Duration; + duration(input: MomentInput): Duration; + duration(object: any): Duration; + duration(): Duration; + + parseZone(date: string): Moment; + + months(): string[]; + months(index: number): string; + months(format: string): string[]; + months(format: string, index: number): string; + monthsShort(): string[]; + monthsShort(index: number): string; + monthsShort(format: string): string[]; + monthsShort(format: string, index: number): string; + + weekdays(): string[]; + weekdays(index: number): string; + weekdays(format: string): string[]; + weekdays(format: string, index: number): string; + weekdaysShort(): string[]; + weekdaysShort(index: number): string; + weekdaysShort(format: string): string[]; + weekdaysShort(format: string, index: number): string; + weekdaysMin(): string[]; + weekdaysMin(index: number): string; + weekdaysMin(format: string): string[]; + weekdaysMin(format: string, index: number): string; + + min(moments: Moment[]): Moment; + max(moments: Moment[]): Moment; + + normalizeUnits(unit: string): string; + relativeTimeThreshold(threshold: string, limit: number): void; + + /** + * Constant used to enable explicit ISO_8601 format parsing. + */ + ISO_8601(): void; + + } + +} + +declare var moment: moment.MomentStatic; + +declare module 'moment' { + export = moment; +} From abdcc85487c63dfa983462def1ddddf07565f6c8 Mon Sep 17 00:00:00 2001 From: Aleksandr Dobkin Date: Sat, 10 Jan 2015 00:03:08 -0800 Subject: [PATCH 022/104] Change type of LaunchDataEntry.entry from File to FileEntry entry property of LaunchDataItem is actually a FileEntry, not a File. See https://developer.chrome.com/apps/app_runtime#event-onLaunched --- chrome/chrome-app.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chrome/chrome-app.d.ts b/chrome/chrome-app.d.ts index 658ea0f8e8..a2b0d5997e 100644 --- a/chrome/chrome-app.d.ts +++ b/chrome/chrome-app.d.ts @@ -18,7 +18,7 @@ declare module chrome.app.runtime { } interface LaunchDataItem { - entry: File; + entry: FileEntry; type: string; } @@ -367,4 +367,4 @@ declare module chrome.sockets.tcpServer { var onAccept: Event; var onAcceptError: Event; -} \ No newline at end of file +} From 5deca4baf3c8ef7abbc919671acb95be27560667 Mon Sep 17 00:00:00 2001 From: David Cook Date: Sat, 10 Jan 2015 14:38:04 -0600 Subject: [PATCH 023/104] optimist: Argument to showHelp should be optional For reference, see https://github.com/substack/node-optimist/blob/master/index.js#L179 --- optimist/optimist.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/optimist/optimist.d.ts b/optimist/optimist.d.ts index 01d44ab630..06c89fcf50 100644 --- a/optimist/optimist.d.ts +++ b/optimist/optimist.d.ts @@ -23,7 +23,7 @@ declare module "optimist" { wrap(columns: number): Optimist; help(): void; - showHelp(fn: Function): void; + showHelp(fn?: Function): void; usage(message: string): Optimist; From 85c97e6cf209c256fe414fb6dd77c0b3fdd1a5c0 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 12:59:56 +1300 Subject: [PATCH 024/104] Add definition for formidable --- formidable/formidable-tests.ts | 81 ++++++++++++++++++++++++++++++++++ formidable/formidable.d.ts | 56 +++++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 formidable/formidable-tests.ts create mode 100644 formidable/formidable.d.ts diff --git a/formidable/formidable-tests.ts b/formidable/formidable-tests.ts new file mode 100644 index 0000000000..f39da3f8c1 --- /dev/null +++ b/formidable/formidable-tests.ts @@ -0,0 +1,81 @@ +/// + +import formidable = require('formidable'); +import http = require('http'); +import util = require('util'); + +http.createServer((req, res) => { + if (req.url == '/upload' && req.method.toLowerCase() == 'post') { + // parse a file upload + var form = new formidable.IncomingForm(); + + form.parse(req, (err, fields, files) => { + res.writeHead(200, {'content-type': 'text/plain'}); + res.write('received upload:\n\n'); + res.end(util.inspect({fields: fields, files: files})); + }); + + return; + } + + // show a file upload form + res.writeHead(200, {'content-type': 'text/html'}); + res.end( + '
'+ + '
'+ + '
'+ + ''+ + '
' + ); +}); + + +var form = new formidable.IncomingForm(); + +form.encoding = 'utf-8'; +form.uploadDir = '/my/dir'; +form.keepExtensions = false; +form.maxFieldsSize = 2 * 1024 * 1024; +form.maxFields = 1000; +// form.hash = false; TODO: Waiting on unions +form.hash = 'sha1'; +form.multiples = false; + +if (form.type === 'multipart') { +} +if (form.bytesReceived > 100) { +} +if (form.bytesExpected > 100) { +} + +var req: http.ServerRequest; + +form.parse(req); +form.parse(req, (err: any, fields: formidable.Fields, files: formidable.Files) => { + var key: string; + for (key in fields) { + console.log(key, '=', fields[key]); + } + + for (key in files) { + console.log('file', key, 'is', files[key].type); + } +}); + +form.onPart = function (part: formidable.Part) { + if (!part.filename) { + form.handlePart(part); + } +}; + +var file: formidable.File; + +file.size = 0; +file.path = '/tmp/whatever'; +file.name = 'a_file'; +file.type = 'application/json'; +file.lastModifiedDate = new Date(); +file.hash = '12345'; +JSON.stringify(file.toJSON()); + +form.on('progess', (bytesReceived: number, bytesExpected: number) => {}); diff --git a/formidable/formidable.d.ts b/formidable/formidable.d.ts new file mode 100644 index 0000000000..bd35c757dc --- /dev/null +++ b/formidable/formidable.d.ts @@ -0,0 +1,56 @@ +// Type definitions for Formidable 1.0.16 +// Project: https://github.com/felixge/node-formidable/ +// Definitions by: Wim Looman +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "formidable" { + import http = require("http"); + import stream = require("stream"); + import events = require("events"); + + export class IncomingForm extends events.EventEmitter { + encoding: string; + uploadDir: string; + keepExtensions: boolean; + maxFieldsSize: number; + maxFields: number; + hash: string; + multiples: boolean; + type: string; + bytesReceived: number; + bytesExpected: number; + + onPart: (part: Part) => void; + + handlePart(part: Part): void; + parse(req: http.ServerRequest, callback?: (err: any, fields: Fields, files: Files) => any): void; + } + + export interface Fields { + [key: string]: string; + } + + export interface Files { + [key: string]: File; // | File[]; + } + + export interface Part extends stream.Stream { + headers: { [key: string]: string }; + name: string; + filename?: string; + mime?: string; + } + + export interface File { + size: number; + path: string; + name: string; + type: string; + lastModifiedDate?: Date; + hash?: string; + + toJSON(): Object; + } +} From b1ce1cc514dabd8bdbfa9a6c41fedd04af00043b Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 13:24:35 +1300 Subject: [PATCH 025/104] Add definition for sanitize-filename --- sanitize-filename/sanitize-filename-tests.ts | 12 ++++++++++++ sanitize-filename/sanitize-filename.d.ts | 16 ++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 sanitize-filename/sanitize-filename-tests.ts create mode 100644 sanitize-filename/sanitize-filename.d.ts diff --git a/sanitize-filename/sanitize-filename-tests.ts b/sanitize-filename/sanitize-filename-tests.ts new file mode 100644 index 0000000000..9ea38993a8 --- /dev/null +++ b/sanitize-filename/sanitize-filename-tests.ts @@ -0,0 +1,12 @@ +/// + +import sanitize = require('sanitize-filename'); + +// Some string that may be unsafe as a filesystem filename +var UNSAFE_FILENAME = "h*ello:/world?\u0000"; + +// Sanitize the unsafe filename to be safe for use as a filename +var filename: string; + +filename = sanitize(UNSAFE_FILENAME); +filename = sanitize(UNSAFE_FILENAME, { replacement: '--' }); diff --git a/sanitize-filename/sanitize-filename.d.ts b/sanitize-filename/sanitize-filename.d.ts new file mode 100644 index 0000000000..c439537454 --- /dev/null +++ b/sanitize-filename/sanitize-filename.d.ts @@ -0,0 +1,16 @@ +// Type definitions for sanitize-filename v1.1.1 +// Project: https://github.com/parshap/node-sanitize-filename +// Definitions by: Wim Looman +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "sanitize-filename" { + function sanitize(filename: string, options?: sanitize.Options): string; + + module sanitize { + interface Options { + replacement: string; + } + } + + export = sanitize; +} From dc0db579e135f2c8483ec5e51e6304184af249d5 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 13:36:12 +1300 Subject: [PATCH 026/104] Add rest interceptor definitions --- rest/rest-tests.ts | 29 +++++++++++++ rest/rest.d.ts | 102 +++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 128 insertions(+), 3 deletions(-) diff --git a/rest/rest-tests.ts b/rest/rest-tests.ts index b19416c119..e5ca243d60 100644 --- a/rest/rest-tests.ts +++ b/rest/rest-tests.ts @@ -1,8 +1,22 @@ /// import rest = require('rest'); + +import defaultRequest = require('rest/interceptor/defaultRequest'); +import hateoas = require('rest/interceptor/hateoas'); +import location = require('rest/interceptor/location'); import mime = require('rest/interceptor/mime'); +import pathPrefix = require('rest/interceptor/pathPrefix'); +import basicAuth = require('rest/interceptor/basicAuth'); +import oAuth = require('rest/interceptor/oAuth'); +import csrf = require('rest/interceptor/csrf'); import errorCode = require('rest/interceptor/errorCode'); +import retry = require('rest/interceptor/retry'); +import timeout = require('rest/interceptor/timeout'); +import jsonp = require('rest/interceptor/jsonp'); +import xdomain = require('rest/interceptor/ie/xdomain'); +import xhr = require('rest/interceptor/ie/xhr'); + import registry = require('rest/mime/registry'); rest('/').then(function(response) { @@ -38,3 +52,18 @@ registry.register('application/vnd.com.example', { } }); +client = rest + .wrap(defaultRequest) + .wrap(hateoas) + .wrap(location) + .wrap(mime) + .wrap(pathPrefix) + .wrap(basicAuth) + .wrap(oAuth) + .wrap(csrf) + .wrap(errorCode) + .wrap(retry) + .wrap(timeout) + .wrap(jsonp) + .wrap(xdomain) + .wrap(xhr); diff --git a/rest/rest.d.ts b/rest/rest.d.ts index 3bec656c33..e3b6fed3ac 100644 --- a/rest/rest.d.ts +++ b/rest/rest.d.ts @@ -62,12 +62,28 @@ declare module "rest" { } } -declare module "rest/interceptor/errorCode" { +declare module "rest/interceptor/defaultRequest" { import rest = require("rest"); - var errorCode: rest.Interceptor; + var defaultRequest: rest.Interceptor; - export = errorCode; + export = defaultRequest; +} + +declare module "rest/interceptor/hateoas" { + import rest = require("rest"); + + var hateoas: rest.Interceptor; + + export = hateoas; +} + +declare module "rest/interceptor/location" { + import rest = require("rest"); + + var location: rest.Interceptor; + + export = location; } declare module "rest/interceptor/mime" { @@ -78,6 +94,86 @@ declare module "rest/interceptor/mime" { export = mime; } +declare module "rest/interceptor/pathPrefix" { + import rest = require("rest"); + + var pathPrefix: rest.Interceptor; + + export = pathPrefix; +} + +declare module "rest/interceptor/basicAuth" { + import rest = require("rest"); + + var basicAuth: rest.Interceptor; + + export = basicAuth; +} + +declare module "rest/interceptor/oAuth" { + import rest = require("rest"); + + var oAuth: rest.Interceptor; + + export = oAuth; +} + +declare module "rest/interceptor/csrf" { + import rest = require("rest"); + + var csrf: rest.Interceptor; + + export = csrf; +} + +declare module "rest/interceptor/errorCode" { + import rest = require("rest"); + + var errorCode: rest.Interceptor; + + export = errorCode; +} + +declare module "rest/interceptor/retry" { + import rest = require("rest"); + + var retry: rest.Interceptor; + + export = retry; +} + +declare module "rest/interceptor/timeout" { + import rest = require("rest"); + + var timeout: rest.Interceptor; + + export = timeout; +} + +declare module "rest/interceptor/jsonp" { + import rest = require("rest"); + + var jsonp: rest.Interceptor; + + export = jsonp; +} + +declare module "rest/interceptor/ie/xdomain" { + import rest = require("rest"); + + var xdomain: rest.Interceptor; + + export = xdomain; +} + +declare module "rest/interceptor/ie/xhr" { + import rest = require("rest"); + + var xhr: rest.Interceptor; + + export = xhr; +} + declare module "rest/mime/registry" { import when = require("when"); From edd32617ace7e076cdfe586665231365f9988615 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 14:22:58 +1300 Subject: [PATCH 027/104] Add definition for chai-http --- chai-http/chai-http-tests.ts | 103 +++++++++++++++++++++++++++++++++++ chai-http/chai-http.d.ts | 87 +++++++++++++++++++++++++++++ 2 files changed, 190 insertions(+) create mode 100644 chai-http/chai-http-tests.ts create mode 100644 chai-http/chai-http.d.ts diff --git a/chai-http/chai-http-tests.ts b/chai-http/chai-http-tests.ts new file mode 100644 index 0000000000..e6e4713213 --- /dev/null +++ b/chai-http/chai-http-tests.ts @@ -0,0 +1,103 @@ +/// +/// + +import fs = require('fs'); +import http = require('http'); +import chai = require('chai'); +import chaiHttp = require('chai-http'); +import when = require('when'); + +chai.use(chaiHttp); + +// Add promise support if this does not exist natively. +if (!global.Promise) { + chai.request.addPromises(when.promise); +} + + +var app: http.Server; + +chai.request(app).get('/'); +chai.request('http://localhost:8080').get('/'); + +chai.request(app) + .put('/user/me') + .set('X-API-Key', 'foobar') + .send({ password: '123', confirmPassword: '123' }); + +chai.request(app) + .post('/user/me') + .field('_method', 'put') + .field('password', '123') + .field('confirmPassword', '123'); + +chai.request(app) + .post('/user/avatar') + .attach('imageField', fs.readFileSync('avatar.png'), 'avatar.png'); + +chai.request(app) + .get('/protected') + .auth('user', 'pass'); + +chai.request(app) + .get('/search') + .query('name', 'foo') + .query('limit', '10'); + +chai.request(app) + .put('/user/me') + .send({ passsword: '123', confirmPassword: '123' }) + .end((err: any, res: chaiHttp.Response) => { + chai.expect(err).to.be.null; + chai.expect(res).to.have.status(200); + }); + +chai.request(app) + .put('/user/me') + .send({ passsword: '123', confirmPassword: '123' }) + .then((res: chaiHttp.Response) => chai.expect(res).to.have.status(200)) + .catch((err: any) => { throw err; }); + +var agent = chai.request.agent(app); + +agent + .post('/session') + .send({ username: 'me', password: '123' }) + .then((res: chaiHttp.Response) => { + chai.expect(res).to.have.cookie('sessionid'); + // The `agent` now has the sessionid cookie saved, and will send it + // back to the server in the next request: + return agent.get('/user/me') + .then((res: chaiHttp.Response) => chai.expect(res).to.have.status(200)); + }); + +function test1() { + var req = chai.request(app).get('/'); + req.then((res: chaiHttp.Response) => { + chai.expect(res).to.have.status(200); + chai.expect(res).to.have.header('content-type', 'text/plain'); + chai.expect(res).to.have.header('content-type', /^text/); + chai.expect(res).to.have.headers; + chai.expect('127.0.0.1').to.be.an.ip; + chai.expect(res).to.be.json; + chai.expect(res).to.be.html; + chai.expect(res).to.be.text; + chai.expect(res).to.redirect; + chai.expect(res).to.redirectTo('http://example.com'); + chai.expect(res).to.have.param('orderby'); + chai.expect(res).to.have.param('orderby', 'date'); + chai.expect(res).to.not.have.param('limit'); + chai.expect(req).to.have.cookie('session_id'); + chai.expect(req).to.have.cookie('session_id', '1234'); + chai.expect(req).to.not.have.cookie('PHPSESSID'); + chai.expect(res).to.have.cookie('session_id'); + chai.expect(res).to.have.cookie('session_id', '1234'); + chai.expect(res).to.not.have.cookie('PHPSESSID'); + chai.expect(res.body).to.have.property('version', '4.0.0'); + }, (err: any) => { + throw err; + }); +} + + +when(chai.request(app).get('/')).done(() => console.log('success'), () => console.log('failure')); diff --git a/chai-http/chai-http.d.ts b/chai-http/chai-http.d.ts new file mode 100644 index 0000000000..fed2a84161 --- /dev/null +++ b/chai-http/chai-http.d.ts @@ -0,0 +1,87 @@ +// Type definitions for chai-http +// Project: https://github.com/chaijs/chai-http +// Definitions by: Wim Looman +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module chai { + export function request(server: any): chaiHttp.Agent; + + export module request { + export function agent(server: any): chaiHttp.Agent; + export function addPromises(promiseConstructor: chaiHttp.PromiseConstructor): void; + } + + interface Assertions extends chaiHttp.Assertions { + } + + interface TypeComparison extends chaiHttp.TypeComparison { + } +} + +declare function chaiHttp(chai: any, utils: any): void; +declare module chaiHttp { + interface PromiseConstructor { + (resolver: (resolve: (value: T) => void, reject: (reason: any) => void) => void): Promise; + } + + interface Promise { + then(onFulfilled: (value: T) => U, onRejected?: (reason: any) => U): Promise; + } + + interface Response { + body: any; + type: string; + status: number; + } + + interface Request extends FinishedRequest { + attach(field: string, file: string, filename: string): Request; + attach(field: string, file: Buffer, filename: string): Request; + set(field: string, val: string): Request; + query(key: string, value: string): Request; + send(data: Object): Request; + auth(user: string, name: string): Request; + field(name: string, val: string): Request; + end(callback?: (err: any, res: Response) => void): FinishedRequest; + } + + interface FinishedRequest { + then(success?: (res: Response) => void, failure?: (err: any) => void): FinishedRequest; + catch(failure?: (err: any) => void): FinishedRequest; + } + + interface Agent { + get(url: string, callback?: (err: any, res: Response) => void): Request; + post(url: string, callback?: (err: any, res: Response) => void): Request; + put(url: string, callback?: (err: any, res: Response) => void): Request; + head(url: string, callback?: (err: any, res: Response) => void): Request; + del(url: string, callback?: (err: any, res: Response) => void): Request; + options(url: string, callback?: (err: any, res: Response) => void): Request; + patch(url: string, callback?: (err: any, res: Response) => void): Request; + } + + interface Assertions { + status(code: number): any; + header(key: string, value?: string): any; + header(key: string, value?: RegExp): any; + headers: any; + json: any; + // text: any; + // html: any; + redirect: any; + redirectTo(location: string): any; + param(key: string, value?: string): any; + cookie(key: string, value?: string): any; + } + + interface TypeComparison { + ip: any; + } +} + +declare module "chai-http" { + export = chaiHttp; +} From e4d5176b09c353d0ae950c9d96f64857ef6671eb Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 14:47:39 +1300 Subject: [PATCH 028/104] Add definition for custom interceptors --- rest/rest-tests.ts | 65 ++++++++++++++++++++++++++++++++++++---------- rest/rest.d.ts | 33 +++++++++++++++++++++++ 2 files changed, 84 insertions(+), 14 deletions(-) diff --git a/rest/rest-tests.ts b/rest/rest-tests.ts index e5ca243d60..be3887246e 100644 --- a/rest/rest-tests.ts +++ b/rest/rest-tests.ts @@ -1,5 +1,6 @@ /// +import when = require('when'); import rest = require('rest'); import defaultRequest = require('rest/interceptor/defaultRequest'); @@ -17,6 +18,7 @@ import jsonp = require('rest/interceptor/jsonp'); import xdomain = require('rest/interceptor/ie/xdomain'); import xhr = require('rest/interceptor/ie/xhr'); +import interceptor = require('rest/interceptor'); import registry = require('rest/mime/registry'); rest('/').then(function(response) { @@ -52,18 +54,53 @@ registry.register('application/vnd.com.example', { } }); +var noop = interceptor({ + init: (config: any) => { + return config; + }, + request: (request: rest.Request, config: any, meta: rest.Meta) => { + return request; + }, + response: (response: rest.Response, config: any, meta: rest.Meta) => { + return response; + }, + success: (response: rest.Response, config: any, meta: rest.Meta) => { + return response; + }, + error: (response: rest.Response, config: any, meta: rest.Meta) => { + return response; + } +}); + +var fail = interceptor({ + success: (response: rest.Response) => when.reject(response), +}); + +var succeed = interceptor({ + error: (response: rest.Response) => when(response), +}); + +var defaulted = interceptor({ + init: (config: any) => { + config.prop = config.prop || 'default-value'; + return config; + }, +}); + client = rest - .wrap(defaultRequest) - .wrap(hateoas) - .wrap(location) - .wrap(mime) - .wrap(pathPrefix) - .wrap(basicAuth) - .wrap(oAuth) - .wrap(csrf) - .wrap(errorCode) - .wrap(retry) - .wrap(timeout) - .wrap(jsonp) - .wrap(xdomain) - .wrap(xhr); + .wrap(defaultRequest) + .wrap(hateoas) + .wrap(location) + .wrap(mime) + .wrap(pathPrefix) + .wrap(basicAuth) + .wrap(oAuth) + .wrap(csrf) + .wrap(errorCode) + .wrap(retry) + .wrap(timeout) + .wrap(jsonp) + .wrap(xdomain) + .wrap(xhr) + .wrap(noop) + .wrap(fail); diff --git a/rest/rest.d.ts b/rest/rest.d.ts index e3b6fed3ac..37ecc4675f 100644 --- a/rest/rest.d.ts +++ b/rest/rest.d.ts @@ -59,9 +59,42 @@ declare module "rest" { skip(): Client; wrap(interceptor: Interceptor, config?: any): Client; } + + export interface Meta { + client: Client; + arguments: any; + } } } +declare module "rest/interceptor" { + import when = require("when"); + import rest = require("rest"); + + // TODO: These two configs should be merged to use union output types. + + interface Config { + init?: (config: any) => any; + request?: (request: rest.Request, config: any, meta: rest.Meta) => rest.Request; + response?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + success?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + error?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + } + + interface PromiseConfig { + init?: (config: any) => any; + request?: (request: rest.Request, config: any, meta: rest.Meta) => when.Promise; + response?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + success?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + error?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + } + + function interceptor(config: Config): rest.Interceptor; + function interceptor(config: PromiseConfig): rest.Interceptor; + + export = interceptor; +} + declare module "rest/interceptor/defaultRequest" { import rest = require("rest"); From b55b8945588635f9605c5a75a66d8b8467f8e942 Mon Sep 17 00:00:00 2001 From: vvakame Date: Mon, 12 Jan 2015 11:19:59 +0900 Subject: [PATCH 029/104] add which/which.d.ts --- which/which-tests.ts | 10 ++++++++++ which/which.d.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 which/which-tests.ts create mode 100644 which/which.d.ts diff --git a/which/which-tests.ts b/which/which-tests.ts new file mode 100644 index 0000000000..172cff91c9 --- /dev/null +++ b/which/which-tests.ts @@ -0,0 +1,10 @@ +/// + +import when = require("when"); + +when("cat", (err, path) => { + console.log(path); +}); + +var path = when.sync("cat"); +console.log(path); diff --git a/which/which.d.ts b/which/which.d.ts new file mode 100644 index 0000000000..d25ac4fd7f --- /dev/null +++ b/which/which.d.ts @@ -0,0 +1,13 @@ +// Type definitions for which 1.0.8 +// Project: https://github.com/isaacs/node-which +// Definitions by: vvakame +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "which" { + function when (cmd: string, cb: (err: Error, path: string) => void): void; + module when { + function sync(cmd: string): string; + } + + export = when; +} From f3617cc5229f2c9149ca4a88d420d1bcfd5462ce Mon Sep 17 00:00:00 2001 From: vvakame Date: Mon, 12 Jan 2015 11:24:20 +0900 Subject: [PATCH 030/104] fix typo... hehe :P --- which/which-tests.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/which/which-tests.ts b/which/which-tests.ts index 172cff91c9..45a376dcb3 100644 --- a/which/which-tests.ts +++ b/which/which-tests.ts @@ -1,10 +1,10 @@ /// -import when = require("when"); +import which = require("which"); -when("cat", (err, path) => { +which("cat", (err, path) => { console.log(path); }); -var path = when.sync("cat"); +var path = which.sync("cat"); console.log(path); From 92249d14aea411d89c3dcab37253efcaab5e9ead Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Mon, 12 Jan 2015 15:28:31 +1300 Subject: [PATCH 031/104] Move interfaces into exported module --- rest/rest.d.ts | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/rest/rest.d.ts b/rest/rest.d.ts index 37ecc4675f..d8126b72d7 100644 --- a/rest/rest.d.ts +++ b/rest/rest.d.ts @@ -71,27 +71,29 @@ declare module "rest/interceptor" { import when = require("when"); import rest = require("rest"); - // TODO: These two configs should be merged to use union output types. + function interceptor(config: interceptor.Config): rest.Interceptor; + function interceptor(config: interceptor.PromiseConfig): rest.Interceptor; - interface Config { - init?: (config: any) => any; - request?: (request: rest.Request, config: any, meta: rest.Meta) => rest.Request; - response?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; - success?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; - error?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + module interceptor { + // TODO: These two configs should be merged to use union output types. + + interface Config { + init?: (config: any) => any; + request?: (request: rest.Request, config: any, meta: rest.Meta) => rest.Request; + response?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + success?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + error?: (response: rest.Response, config: any, meta: rest.Meta) => rest.Response; + } + + interface PromiseConfig { + init?: (config: any) => any; + request?: (request: rest.Request, config: any, meta: rest.Meta) => when.Promise; + response?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + success?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + error?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; + } } - interface PromiseConfig { - init?: (config: any) => any; - request?: (request: rest.Request, config: any, meta: rest.Meta) => when.Promise; - response?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; - success?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; - error?: (response: rest.Response, config: any, meta: rest.Meta) => when.Promise; - } - - function interceptor(config: Config): rest.Interceptor; - function interceptor(config: PromiseConfig): rest.Interceptor; - export = interceptor; } From 223211fd98fc302334105bcbc9f7565cb76481f9 Mon Sep 17 00:00:00 2001 From: Rogier Schouten Date: Mon, 12 Jan 2015 09:45:52 +0100 Subject: [PATCH 032/104] jsdom: bugfixes, add comments, add defaultFeatures variable. --- jsdom/jsdom-tests.ts | 41 +++-------- jsdom/jsdom.d.ts | 160 +++++++++++++++++++++++++++++++++++-------- 2 files changed, 141 insertions(+), 60 deletions(-) diff --git a/jsdom/jsdom-tests.ts b/jsdom/jsdom-tests.ts index 87eddbfc5f..cb6992b49a 100644 --- a/jsdom/jsdom-tests.ts +++ b/jsdom/jsdom-tests.ts @@ -1,17 +1,17 @@ import jsdom = require("jsdom"); +jsdom.defaultDocumentFeatures.FetchExternalResources = ["img"]; + jsdom.env( "http://nodejs.org/dist/", ["http://code.jquery.com/jquery.js"], - function (errors, window) { - console.log("there have been nodejs releases!"); + function (errors: Error[], window: Window) { } ); jsdom.env( "http://nodejs.org/dist/", - function (errors, window) { - console.log("there have been nodejs releases!"); + function (errors: Error[], window: Window) { } ); @@ -20,28 +20,21 @@ jsdom.env( { scripts: ["http://code.jquery.com/jquery.js"], }, - function (errors, window) { - console.log("there have been nodejs releases!"); + function (errors: Error[], window: Window) { } ); jsdom.env( '

jsdom!

', ["http://code.jquery.com/jquery.js"], - function (errors, window) { - console.log("contents of a.the-link:", (window).$("a.the-link").text()); + function (errors: Error[], window: Window) { } ); jsdom.env({ url: "http://news.ycombinator.com/", scripts: ["http://code.jquery.com/jquery.js"], - done: function (errors, window) { - var $ = (window).$; - console.log("HN Links"); - $("td.title:not(:last) a").each(function() { - console.log(" -", $(this).text()); - }); + done: function (errors: Error[], window: Window) { } }); @@ -50,23 +43,9 @@ var jquery: string; jsdom.env({ url: "http://news.ycombinator.com/", src: [jquery], - done: function (errors, window) { - var $ = (window).$; - console.log("HN Links"); - $("td.title:not(:last) a").each(function () { - console.log(" -", $(this).text()); - }); + done: function (errors: Error[], window: Window) { } }); -var window = jsdom.jsdom().parentWindow; -var window = jsdom.jsdom("
foobar
").parentWindow; -var window = jsdom.jsdom("
foobar
", { -scripts: ["http://code.jquery.com/jquery.js"], -done: function (errors, window) { - var $ = (window).$; - console.log("HN Links"); - $("td.title:not(:last) a").each(function() { - console.log(" -", $(this).text()); - }); -}}).parentWindow; \ No newline at end of file +var window: Window = jsdom.jsdom("
foobar
").parentWindow; +var document: Document = jsdom.jsdom(""); \ No newline at end of file diff --git a/jsdom/jsdom.d.ts b/jsdom/jsdom.d.ts index 4dbcb086e9..b9864b3b79 100644 --- a/jsdom/jsdom.d.ts +++ b/jsdom/jsdom.d.ts @@ -4,38 +4,140 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped declare module "jsdom" { - export function env(config: Config): void; - export function env(htmlRef: string, callback: Callback): void; - export function env(htmlRef: string, scripts: string[], callback: Callback): void; - export function env(htmlRef: string, config: Config, callback: Callback): void; - export function env(htmlRef: string, scripts: string[], config: Config, callback: Callback): void; - export function jsdom(markup?: string, options?: Config): Document; + /** + * The do-what-I-mean API. + * + * Example: + * jsdom.env(html, function (errors, window) { + * // free memory associated with the window + * window.close(); + * }); + * + * @param urlOrSource may be a URL, file name, or HTML fragment + * @param scriptUrlsOrSources a string or array of strings, containing file names or URLs that will be inserted as + * @param config Configuration object + * @param callback + */ + export function env(urlOrHtml: string, scripts: string, config: Config, callback?: Callback): void; + export function env(urlOrHtml: string, scripts: string, callback: Callback): void; + export function env(urlOrHtml: string, scripts: string[], config: Config, callback?: Callback): void; + export function env(urlOrHtml: string, scripts: string[], callback: Callback): void; + export function env(urlOrHtml: string, callback: Callback): void; + export function env(urlOrHtml: string, config: Config, callback?: Callback): void; + export function env(config: Config, callback?: Callback): void; - interface Callback { + /** + * The jsdom.jsdom method does less things automatically; it takes in only HTML source, and does not let you to + * separately supply script that it will inject and execute. It just gives you back a document object, + * with usable document.parentWindow, and starts asynchronously executing any