From 709f97cb32513e322a3ad98b71af51a48788b3e8 Mon Sep 17 00:00:00 2001 From: Dan Marshall Date: Sat, 14 Nov 2015 12:47:05 -0800 Subject: [PATCH 01/18] update to maker.js 0.5.3 --- maker.js/makerjs-tests.ts | 10 +++ maker.js/makerjs.d.ts | 135 +++++++++++++++++++++++++++++++++++--- 2 files changed, 135 insertions(+), 10 deletions(-) diff --git a/maker.js/makerjs-tests.ts b/maker.js/makerjs-tests.ts index 59a50e4fc..ae17a8fe9 100644 --- a/maker.js/makerjs-tests.ts +++ b/maker.js/makerjs-tests.ts @@ -40,6 +40,8 @@ function test() { function testExporter() { new makerjs.exporter.Exporter({}); makerjs.exporter.toDXF(model); + makerjs.exporter.toOpenJsCad(model); + makerjs.exporter.toSTL(model); makerjs.exporter.toSVG(model); makerjs.exporter.tryGetModelUnits(model); } @@ -66,12 +68,17 @@ function test() { function testModel(){ makerjs.model.combine(model, model, true, false, true, false); makerjs.model.convertUnits(model, makerjs.unitType.Centimeter); + makerjs.model.countChildModels(model); + makerjs.model.detachLoop(model); + makerjs.model.findLoops(model); makerjs.model.getSimilarPathId(model, 'foo'); + makerjs.model.isPathInsideModel(paths.line, model); makerjs.model.mirror(model, false, true); makerjs.model.move(makerjs.model.originate(model, [9,9]), [0,0]); makerjs.model.moveRelative(model, [1,1]); makerjs.model.originate(model); makerjs.model.rotate(makerjs.model.scale(model, 6), 45, [0,0]); + makerjs.model.scale(model, 7); makerjs.model.walkPaths(model, (modelContext: MakerJs.IModel, pathId: string, pathContext: MakerJs.IPath) => {}); } @@ -80,6 +87,7 @@ function test() { new makerjs.models.BoltCircle(7, 7, 7, 7), new makerjs.models.BoltRectangle(2, 2, 2), new makerjs.models.ConnectTheDots(true, [ [0,0], [1,1] ]), + new makerjs.models.Dome(5, 7), new makerjs.models.Oval(7, 7), new makerjs.models.OvalArc(6, 4, 2, 12), new makerjs.models.Polygon(7, 5), @@ -141,7 +149,9 @@ function test() { makerjs.point.middle(paths.line); makerjs.point.mirror(p1, true, false); makerjs.point.rotate(p1, 5, p2); + makerjs.point.rounded(p1); makerjs.point.scale(p2, 8); + makerjs.point.serialize(p1); makerjs.point.subtract(p2, p1); makerjs.point.zero(); } diff --git a/maker.js/makerjs.d.ts b/maker.js/makerjs.d.ts index 69cd3dbb7..779af0534 100644 --- a/maker.js/makerjs.d.ts +++ b/maker.js/makerjs.d.ts @@ -247,6 +247,37 @@ declare module MakerJs { */ path2Angles?: number[]; } + /** + * Options when matching points + */ + interface IPointMatchOptions { + /** + * Optional exemplar of number of decimal places. + */ + accuracy?: number; + } + /** + * Options to pass to model.findLoops. + */ + interface IFindLoopsOptions extends IPointMatchOptions { + /** + * Flag to remove looped paths from the original model. + */ + removeFromOriginal?: boolean; + } + /** + * A path that may be indicated to "flow" in either direction between its endpoints. + */ + interface IPathDirectional extends IPath { + /** + * The endpoints of the path. + */ + endPoints: IPoint[]; + /** + * Path flows forwards or reverse. + */ + reversed?: boolean; + } /** * Path objects by id. */ @@ -302,6 +333,12 @@ declare module MakerJs { */ layer?: string; } + /** + * Callback signature for model.walkPaths(). + */ + interface IModelPathCallback { + (modelContext: IModel, pathId: string, pathContext: IPath): void; + } /** * Test to see if an object implements the required properties of a model. */ @@ -408,6 +445,7 @@ declare module MakerJs.point { * * @param a First point. * @param b Second point. + * @param accuracy Optional exemplar of number of decimal places. * @returns true if points are the same, false if they are not */ function areEqualRounded(a: IPoint, b: IPoint, accuracy?: number): boolean; @@ -456,7 +494,7 @@ declare module MakerJs.point { */ function fromPathEnds(pathContext: IPath): IPoint[]; /** - * Get the middle point of a path. Currently only supports Arc and Line paths. + * Get the middle point of a path. * * @param pathContext The path object. * @param ratio Optional ratio (between 0 and 1) of point along the path. Default is .5 for middle. @@ -472,6 +510,14 @@ declare module MakerJs.point { * @returns Mirrored point. */ function mirror(pointToMirror: IPoint, mirrorX: boolean, mirrorY: boolean): IPoint; + /** + * Round the values of a point. + * + * @param pointContext The point to serialize. + * @param accuracy Optional exemplar number of decimal places. + * @returns A new point with the values rounded. + */ + function rounded(pointContext: IPoint, accuracy?: number): IPoint; /** * Rotate a point. * @@ -489,6 +535,14 @@ declare module MakerJs.point { * @returns A new point. */ function scale(pointToScale: IPoint, scaleValue: number): IPoint; + /** + * Get a string representation of a point. + * + * @param pointContext The point to serialize. + * @param accuracy Optional exemplar of number of decimal places. + * @returns String representing the point. + */ + function serialize(pointContext: IPoint, accuracy?: number): string; /** * Subtract a point from another point, and return the result as a new point. Shortcut to Add(a, b, subtract = true). * @@ -637,6 +691,13 @@ declare module MakerJs.paths { } } declare module MakerJs.model { + /** + * Count the number of child models within a given model. + * + * @param modelContext The model containing other models. + * @returns Number of child models. + */ + function countChildModels(modelContext: IModel): number; /** * Get an unused id in the paths map with the same prefix. * @@ -702,12 +763,6 @@ declare module MakerJs.model { * @returns The scaled model (for chaining). */ function convertUnits(modeltoConvert: IModel, destUnitType: string): IModel; - /** - * Callback signature for walkPaths. - */ - interface IModelPathCallback { - (modelContext: IModel, pathId: string, pathContext: IPath): void; - } /** * Recursively walk through all paths for a given model. * @@ -717,6 +772,15 @@ declare module MakerJs.model { function walkPaths(modelContext: IModel, callback: IModelPathCallback): void; } declare module MakerJs.model { + /** + * Check to see if a path is inside of a model. + * + * @param pathContext The path to check. + * @param modelContext The model to check against. + * @param farPoint Optional point of reference which is outside the bounds of the modelContext. + * @returns Boolean true if the path is inside of the modelContext. + */ + function isPathInsideModel(pathContext: IPath, modelContext: IModel, farPoint?: IPoint): boolean; /** * Combine 2 models. The models should be originated. * @@ -726,9 +790,10 @@ declare module MakerJs.model { * @param includeAOutsideB Flag to include paths from modelA which are outside of modelB. * @param includeBInsideA Flag to include paths from modelB which are inside of modelA. * @param includeBOutsideA Flag to include paths from modelB which are outside of modelA. + * @param keepDuplicates Flag to include paths which are duplicate in both models. * @param farPoint Optional point of reference which is outside the bounds of both models. */ - function combine(modelA: IModel, modelB: IModel, includeAInsideB: boolean, includeAOutsideB: boolean, includeBInsideA: boolean, includeBOutsideA: boolean, farPoint?: IPoint): void; + function combine(modelA: IModel, modelB: IModel, includeAInsideB?: boolean, includeAOutsideB?: boolean, includeBInsideA?: boolean, includeBOutsideA?: boolean, keepDuplicates?: boolean, farPoint?: IPoint): void; } declare module MakerJs.units { /** @@ -927,7 +992,7 @@ declare module MakerJs.path { * @param line2 Second line to fillet, which will be modified to fit the fillet. * @returns Arc path object of the new fillet. */ - function dogbone(line1: IPathLine, line2: IPathLine, filletRadius: number): IPathArc; + function dogbone(line1: IPathLine, line2: IPathLine, filletRadius: number, options?: IPointMatchOptions): IPathArc; /** * Adds a round corner to the inside angle between 2 paths. The paths must meet at one point. * @@ -935,7 +1000,7 @@ declare module MakerJs.path { * @param path2 Second path to fillet, which will be modified to fit the fillet. * @returns Arc path object of the new fillet. */ - function fillet(path1: IPath, path2: IPath, filletRadius: number): IPathArc; + function fillet(path1: IPath, path2: IPath, filletRadius: number, options?: IPointMatchOptions): IPathArc; } declare module MakerJs.kit { /** @@ -998,6 +1063,22 @@ declare module MakerJs.kit { */ function getParameterValues(ctor: IKit): any[]; } +declare module MakerJs.model { + /** + * Find paths that have common endpoints and form loops. + * + * @param modelContext The model to search for loops. + * @param options Optional options object. + * @returns A new model with child models ranked according to their containment within other found loops. The paths of models will be IPathDirectionalWithPrimeContext. + */ + function findLoops(modelContext: IModel, options?: IFindLoopsOptions): IModel; + /** + * Remove all paths in a loop model from the model(s) which contained them. + * + * @param loopToDetach The model to search for loops. + */ + function detachLoop(loopToDetach: IModel): void; +} declare module MakerJs.exporter { /** * Attributes for an XML tag. @@ -1052,6 +1133,34 @@ declare module MakerJs.exporter { toString(): string; } } +declare module MakerJs.exporter { + function toOpenJsCad(modelToExport: IModel, options?: IOpenJsCadOptions): string; + function toOpenJsCad(pathsToExport: IPath[], options?: IOpenJsCadOptions): string; + function toOpenJsCad(pathToExport: IPath, options?: IOpenJsCadOptions): string; + /** + * Executes a JavaScript string with the OpenJsCad engine - converts 2D to 3D. + * + * @param modelToExport Model object to export. + * @param options Export options object. + * @param options.extrusion Height of 3D extrusion. + * @param options.resolution Size of facets. + * @returns String of STL format of 3D object. + */ + function toSTL(modelToExport: IModel, options?: IOpenJsCadOptions): string; + /** + * OpenJsCad export options. + */ + interface IOpenJsCadOptions extends IFindLoopsOptions { + /** + * Optional depth of 3D extrusion. + */ + extrusion?: number; + /** + * Optional size of curve facets. + */ + facetSize?: number; + } +} declare module MakerJs.exporter { function toSVG(modelToExport: IModel, options?: ISVGRenderOptions): string; function toSVG(pathsToExport: IPath[], options?: ISVGRenderOptions): string; @@ -1118,6 +1227,12 @@ declare module MakerJs.models { constructor(width: number, height: number, holeRadius: number); } } +declare module MakerJs.models { + class Dome implements IModel { + paths: IPathMap; + constructor(width: number, height: number, radius?: number); + } +} declare module MakerJs.models { class RoundRectangle implements IModel { paths: IPathMap; From 07deed85edf73b0d794db713559eb9a4f1f476ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e?= Date: Thu, 10 Dec 2015 19:16:01 +0100 Subject: [PATCH 02/18] Fix electron.nativeImage's type --- github-electron/github-electron.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github-electron/github-electron.d.ts b/github-electron/github-electron.d.ts index 7c5fa8b4d..48f893d06 100644 --- a/github-electron/github-electron.d.ts +++ b/github-electron/github-electron.d.ts @@ -1700,7 +1700,7 @@ declare module GitHubElectron { interface Electron { clipboard: GitHubElectron.Clipboard; crashReporter: GitHubElectron.CrashReporter; - nativeImage: GitHubElectron.NativeImage; + nativeImage: typeof GitHubElectron.NativeImage; screen: GitHubElectron.Screen; shell: GitHubElectron.Shell; remote: GitHubElectron.Remote; From 2e21448655e5819dce96ad255a9f119f5a6fd982 Mon Sep 17 00:00:00 2001 From: phiresky Date: Mon, 21 Sep 2015 00:45:56 +0200 Subject: [PATCH 03/18] add wu typings --- wu/wu-tests.ts | 411 +++++++++++++++++++++++++++++++++++++++ wu/wu-tests.ts.tscparams | 1 + wu/wu.d.ts | 117 +++++++++++ wu/wu.d.ts.tscparams | 1 + 4 files changed, 530 insertions(+) create mode 100644 wu/wu-tests.ts create mode 100644 wu/wu-tests.ts.tscparams create mode 100644 wu/wu.d.ts create mode 100644 wu/wu.d.ts.tscparams diff --git a/wu/wu-tests.ts b/wu/wu-tests.ts new file mode 100644 index 000000000..c20782030 --- /dev/null +++ b/wu/wu-tests.ts @@ -0,0 +1,411 @@ +// adapted from `cat wu.js/test/* |sed '/= require/d'> wu-tests.ts` +/// +declare var describe: any, it: any, mocha: any, assert: { + iterable:any; + eqSet(expected:Set, actual: Iterable): any; + ok:any; + equal(x:T, y:T): any; + eqArray(x:T[], y:Iterable): any; + deepEqual(x:T, y:T): any; +} + +// Helper for asserting that the given thing is iterable. +assert.iterable = thing => { + assert.ok(wu(thing)); +}; + +// Helper for asserting that all the elements yielded from the |actual| +// iterator are in the |expected| set. +assert.eqSet = (expected, actual) => { + assert.iterable(actual); + for (var x of actual) { + assert.ok(expected.has(x)); + expected.delete(x); + } +}; + +// Helper for asserting that all the elements yielded from the |actual| +// iterator are equal to and in the same order as the elements of the +// |expected| array. +assert.eqArray = (expected, actual) => { + assert.iterable(actual); + assert.deepEqual(expected, [...actual]); +}; + +mocha.setup('bdd'); +describe("wu.asyncEach", () => { + it("should iterate over each item", () => { + const arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; + let n = 0; + + return wu(arr) + .asyncEach(x => { + n++; + const start = Date.now(); + while (Date.now() - start <= 3) { + // Kill time. + } + }, 3) + .then(() => { + assert.equal(n, arr.length); + }); + }); +}); +describe("wu.chain", () => { + it("should concatenate iterables", () => { + assert.eqArray([1, 2, 3, 4, 5, 6], + wu.chain([1, 2], [3, 4], [5, 6])); + }); +}); +describe("wu.chunk", () => { + it("should chunk items into tuples", () => { + assert.eqArray([[1,2,3], [4,5,6]], + wu.chunk(3, [1,2,3,4,5,6])); + }); +}); +describe("wu.concatMap", () => { + it("should map the function over the iterable and concatenate results", () => { + assert.eqArray([1, 1, 2, 4, 3, 9], + wu.concatMap(x => [x, x * x], [1, 2, 3])); + }); +}); +describe("wu.count", () => { + it("should keep incrementing", () => { + const count = wu.count(); + assert.equal(count.next().value, 0); + assert.equal(count.next().value, 1); + assert.equal(count.next().value, 2); + assert.equal(count.next().value, 3); + assert.equal(count.next().value, 4); + assert.equal(count.next().value, 5); + }); + + it("should start at the provided number", () => { + const count = wu.count(5); + assert.equal(count.next().value, 5); + assert.equal(count.next().value, 6); + assert.equal(count.next().value, 7); + }); + + it("should increment by the provided step", () => { + const count = wu.count(0, 2); + assert.equal(count.next().value, 0); + assert.equal(count.next().value, 2); + assert.equal(count.next().value, 4); + }); +}); +describe("wu.curryable", () => { + it("should wait until its given enough arguments", () => { + var f = wu.curryable((a, b) => a + b); + + var f0 = f()()()()(); + assert.equal(typeof f0, "function"); + + var f1 = f(1); + assert.equal(typeof f1, "function"); + assert.equal(f1(2), 3); + }); + + it("should just call the function when given enough arguments", () => { + var f = wu.curryable((a, b) => a + b); + assert.equal(f(1, 2), 3); + }); + + it("should expect the number of arguments we tell it to", () => { + var f = wu.curryable((...args) => 5, 5); + assert.equal(typeof f(1, 2, 3, 4), "function"); + assert.equal(f(1, 2, 3, 4, 5), 5); + }); +}); +describe("wu.cycle", () => { + it("should keep yielding items from the original iterable", () => { + let i = 0; + const arr = [1, 2, 3]; + for (let x of wu.cycle(arr)) { + assert.equal(x, arr[i % 3]); + if (i++ > 9) { + break; + } + } + }); +}); +describe("wu.drop", () => { + it("should drop the number of items specified", () => { + const count = wu.count().drop(5); + assert.equal(count.next().value, 5); + }); +}); +describe("wu.dropWhile", () => { + it("should drop items while the predicate is true", () => { + const count = wu.dropWhile(x => x < 5, wu.count()); + assert.equal(count.next().value, 5); + }); +}); +describe("wu.entries", () => { + it("should iterate over entries", () => { + const expected = new Map([["foo", 1], ["bar", 2], ["baz", 3]]); + for (let [k, v] of wu.entries({ foo: 1, bar: 2, baz: 3 })) { + assert.equal(expected.get(k), v); + } + }); +}); +describe("wu.enumerate", () => { + it("should yield items with their index", () => { + assert.eqArray([["a", 0], ["b", 1], ["c", 2]], + wu.enumerate("abc")); + }); +}); +describe("wu.every", () => { + it("should return true when the predicate succeeds for all items", () => { + assert.equal(true, wu.every(x => typeof x === "number", [1, 2, 3])); + }); + + it("should return false when the predicate fails for any item", () => { + assert.equal(false, wu.every(x => typeof x === "number", [1, 2, "3"])); + }); +}); +describe("wu.filter", () => { + it("should filter based on the predicate", () => { + assert.eqArray(["a", "b", "c"], + wu.filter(x => typeof x === "string", + [1, "a", true, "b", {}, "c"])); + }); +}); +describe("wu.find", () => { + it("should return the first item that matches the predicate", () => { + assert.deepEqual({ name: "rza" }, + wu.find(x => !!x.name.match(/.za$/), + [{ name: "odb" }, + { name: "method man" }, + { name: "rza" }, + { name: "gza" }])); + }); + + it("should return undefined if no items match the predicate", () => { + assert.equal(undefined, + wu.find(x => (x) === "raekwon", + [{ name: "odb" }, + { name: "method man" }, + { name: "rza" }, + { name: "gza" }])); + }); +}); +describe("wu.flatten", () => { + it("should flatten iterables", () => { + assert.eqArray(["I", "like", "LISP"], + wu(["I", ["like", ["LISP"]]]).flatten()); + }); + + it("should shallowly flatten iterables", () => { + assert.eqArray([1, 2, 3, [[4]]], + wu.flatten(true, [1, [2], [3, [[4]]]])); + }); +}); +describe("wu.forEach", () => { + it("should iterate over every item", () => { + const items = []; + wu.forEach(x => items.push(x), [1,2,3]); + assert.eqArray([1,2,3], items); + }); +}); +describe("wu.has", () => { + it("should return true if the item is in the iterable", () => { + assert.ok(wu.has(3, [1,2,3])); + }); + + it("should return false if the item is not in the iterable", () => { + assert.ok(!wu.has("36 chambers", [1,2,3])); + }); +}); +describe("wu.invoke", () => { + it("should yield the method invokation on each item", () => { + function Greeter(name) { + this.name = name + } + Greeter.prototype.greet = function (tail) { + return "hello " + this.name + tail; + }; + assert.eqArray(["hello world!", "hello test!"], + wu.invoke("greet", "!", + [new Greeter("world"), new Greeter("test")])); + }); +}); +describe("wu.keys", () => { + it("should iterate over keys", () => { + assert.eqSet(new Set(["foo", "bar", "baz"]), + wu.keys({ foo: 1, bar: 2, baz: 3 })); + }); +}); +describe("wu.map", () => { + it("should map the function over the iterable", () => { + assert.eqArray([1, 4, 9], + wu.map(x => x * x, [1, 2, 3])); + }); +}); +describe("wu.pluck", () => { + it("should access the named property of each item in the iterable", () => { + assert.eqArray([1, 2, 3], + wu.pluck("i", [{ i: 1 }, { i: 2 }, { i: 3 }])); + }); +}); +describe("wu.reduce", () => { + it("should reduce the iterable with the function", () => { + assert.equal(6, wu([1,2,3]).reduce((x, y) => x + y)); + }); + + it("should accept an initial state for the reducer function", () => { + assert.equal(16, wu.reduce((x, y) => x + y, 10, [1,2,3])); + }); +}); +describe("wu.reductions", () => { + it("should yield the intermediate reductions of the iterable", () => { + assert.eqArray([1, 3, 6], + wu.reductions((x, y) => x + y, undefined, [1, 2, 3])); + }); +}); +describe("wu.reject", () => { + it("should yield items for which the predicate is false", () => { + assert.eqArray([1, true, {}], + wu.reject(x => typeof x === "string", + [1, "a", true, "b", {}, "c"])); + }); +}); +describe("wu.repeat", () => { + it("should keep yielding its item", () => { + const repeat = wu.repeat(3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + }); + + it("should repeat n times", () => { + const repeat = wu.repeat(3, 2); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, 3); + assert.equal(repeat.next().value, undefined); + assert.equal(repeat.next().done, true); + }); +}); +describe("wu.slice", () => { + it("should slice the front of iterables", () => { + assert.eqArray([3, 4, 5], + wu.slice(3, undefined, [0, 1, 2, 3, 4, 5])); + }); + + it("should slice the end of iterables", () => { + assert.eqArray([0, 1, 2], + wu.slice(undefined, + 3, + [0, 1, 2, 3, 4, 5])); + }); +}); +describe("wu.some", () => { + it("should return true if any item matches the predicate", () => { + assert.ok(wu.some(x => x % 2 === 0, [1,2,3])); + }); + + it("should return false if no items match the predicate", () => { + assert.ok(!wu.some(x => x % 5 === 0, [1,2,3])); + }); +}); +describe("wu.spreadMap", () => { + it("should map the function over the iterable with spread arguments", () => { + assert.eqArray([32, 9, 1000], + wu.spreadMap(Math.pow, [[2, 5], [3, 2], [10, 3]])); + }); +}); +describe("wu.take", () => { + it("should yield as many items as requested", () => { + assert.eqArray([0, 1, 2, 3, 4], + wu.take(5, wu.count())); + }); +}); +describe("wu.takeWhile", () => { + it("should keep yielding items from the iterable until the predicate is false", () => { + assert.eqArray([0, 1, 2, 3, 4], + wu.takeWhile(x => x < 5, wu.count())); + }); +}); +describe("wu.tap", () => { + it("should perform side effects and yield the original item", () => { + let i = 0; + assert.eqArray([1, 2, 3], + wu.tap(x => i++, [1, 2, 3])); + assert.equal(i, 3); + }); +}); +describe("wu.tee", () => { + it("should clone iterables", () => { + const factorials = wu(wu.count(1)).reductions((a, b) => a * b); + const [i1, i2] = wu(factorials).tee(); + + assert.equal(i1.next().value, 1); + assert.equal(i1.next().value, 2); + assert.equal(i1.next().value, 6); + assert.equal(i1.next().value, 24); + + assert.equal(i2.next().value, 1); + assert.equal(i2.next().value, 2); + assert.equal(i2.next().value, 6); + assert.equal(i2.next().value, 24); + }); +}); +describe("wu.unique", () => { + it("should yield only the unique items from the iterable", () => { + assert.eqArray([1, 2, 3], + wu.unique([1,1,2,2,1,1,3,3])); + }); +}); +describe("wu.unzip", () => { + it("should create iterables from zipped items", () => { + const pairs = [ + ["one", 1], + ["two", 2], + ["three", 3] + ]; + const [i1, i2] = wu(pairs).unzip(); + assert.eqArray(["one", "two", "three"], [...i1]); + assert.eqArray([1, 2, 3], [...i2]); + }); +}); +describe("wu.values", () => { + it("should iterate over values", () => { + assert.eqSet(new Set([1, 2, 3]), + wu.values({ foo: 1, bar: 2, baz: 3 })); + }); +}); +describe("wu.zip", () => { + it("should zip two iterables together", () => { + assert.eqArray([["a", 1], ["b", 2], ["c", 3]], + wu.zip("abc", [1, 2, 3])); + }); + + it("should stop with the shorter iterable", () => { + assert.eqArray([["a", 1], ["b", 2], ["c", 3]], + wu.zip("abc", wu.count(1))); + }); +}); +describe("wu.zipLongest", () => { + it("should stop with the longer iterable", () => { + const arr1 = []; + arr1[1] = 2; + const arr2 = []; + arr2[1] = 3; + assert.eqArray([["a", 1], arr1, arr2], + wu.zipLongest("a", [1, 2, 3])); + }); +}); +describe("wu.zipWith", () => { + it("should spread map over the zipped iterables", () => { + const add3 = (a, b, c) => a + b + c; + assert.eqArray([12, 15, 18], + wu.zipWith(add3, + [1, 2, 3], + [4, 5, 6], + [7, 8, 9])); + }); +}); diff --git a/wu/wu-tests.ts.tscparams b/wu/wu-tests.ts.tscparams new file mode 100644 index 000000000..14fce22a5 --- /dev/null +++ b/wu/wu-tests.ts.tscparams @@ -0,0 +1 @@ +--target ES6 diff --git a/wu/wu.d.ts b/wu/wu.d.ts new file mode 100644 index 000000000..61a0e6e97 --- /dev/null +++ b/wu/wu.d.ts @@ -0,0 +1,117 @@ +// Type definitions for wu.js v2.1.0 +// Project: http://backbonejs.org/ +// Definitions by: phiresky +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module Wu { + type Consumer = (t: T) => void; + type Filter = (t: T) => boolean; + + export interface WuStatic { + (iterable: Iterable): WuIterable; + // only static + chain(...iters: Iterable[]): WuIterable; + count(start?: number, step?: number): WuIterable; + curryable(fun: (...x: any[]) => T, expected?: number): any; + entries(obj: { [i: string]: T }): WuIterable<[string, T]>; + keys(obj: { [i: string]: T }): WuIterable; + values(obj: { [i: string]: T }): WuIterable; + repeat(obj: T, times?: number): WuIterable; + // also copied to WuInterface + asyncEach(fn: Consumer, maxBlock?: number, timeout?: number): void; + drop(n: number, iter: Iterable): WuIterable; + dropWhile(fn: Filter, iter: Iterable): WuIterable; + cycle(iter: Iterable): Iterable; + chunk(n: number, iter: Iterable): WuIterable; + concatMap(fn: (t: T) => Iterable, iter: Iterable): WuIterable; + dropWhile(fn: Filter, iter: Iterable): WuIterable; + enumerate(iter: Iterable): Iterable<[number, T]>; + every(fn: Filter, iter: Iterable): boolean; + filter(fn: Filter, iter: Iterable): WuIterable; + find(fn: Filter, iter: Iterable): T; + flatten(iter: Iterable): WuIterable; + flatten(shallow: boolean, iter: Iterable): WuIterable; + forEach(fn: Consumer, iter: Iterable): void; + has(t: T, iter: Iterable): boolean; + // invoke(name:string, ...t:T[], iter: Iterable<(t:T)=>U>): WuIterable; + invoke: any; + map(fn: (t: T) => U, iter: Iterable): WuIterable; + // pluck(attribute:string, iter: Iterable<{[attribute]: T}>): WuIterable; + pluck(attribute: string, iter: Iterable): WuIterable; + reduce(fn: (a: T, b: T) => T, iter: Iterable): T; + reduce(fn: (a: T, b: T) => T, initial: T, iter: Iterable): T; + reduce(fn: (a: U, b: T) => U, iter: Iterable): U; + reduce(fn: (a: U, b: T) => U, initial: U, iter: Iterable): U; + reductions(fn: (a: T, b: T) => T, iter: Iterable): WuIterable; + reductions(fn: (a: T, b: T) => T, initial: T, iter: Iterable): WuIterable; + reductions(fn: (a: U, b: T) => U, iter: Iterable): WuIterable; + reductions(fn: (a: U, b: T) => U, initial: U, iter: Iterable): WuIterable; + reject(fn: Filter, iter: Iterable): WuIterable; + slice(iter: Iterable): WuIterable; + slice(start: number, iter: Iterable): WuIterable; + slice(start: number, stop: number, iter: Iterable): WuIterable; + some(fn: Filter, iter: Iterable): WuIterable; + spreadMap(fn: (...x: any[]) => T, iter: Iterable): WuIterable; + take(n: number, iter: Iterable): WuIterable; + takeWhile(fn: Filter, iter: Iterable): WuIterable; + tap(fn: Consumer, iter: Iterable): WuIterable; + unique(iter: Iterable): WuIterable; + zip(iter2: Iterable, iter: Iterable): WuIterable<[T, U]>; + zipLongest(iter2: Iterable, iter: Iterable): WuIterable<[T, U]>; + zipWith: any; + unzip: any; + tee(iter: Iterable): WuIterable[]; + tee(n: number, iter: Iterable): WuIterable[]; + } + export interface WuIterable extends IterableIterator { + // generated from section "copied to WuIterable" above via + // sed -r 's/(, )?iter: Iterable<\w+>//' | + // sed -r 's/^(\s+\w+)/\1/' | + // sed -r 's/^(\s+\w+)(fn: Consumer, maxBlock?: number, timeout?: number): any; + drop(n: number): WuIterable; + dropWhile(fn: Filter): WuIterable; + cycle(): Iterable; + chunk(n: number): WuIterable; + concatMap(fn: (t: T) => Iterable): WuIterable; + dropWhile(fn: Filter): WuIterable; + enumerate(): Iterable<[number, T]>; + every(fn: Filter): boolean; + filter(fn: Filter): WuIterable; + find(fn: Filter): T; + flatten(): WuIterable; + flatten(shallow: boolean): WuIterable; + forEach(fn: Consumer): void; + has(t: T): boolean; + // invoke(name:string, ...t:T[], iter: Iterable<(t:T)=>U>): WuIterable; + invoke: any; + map(fn: (t: T) => U): WuIterable; + // pluck(attribute:string, iter: Iterable<{[attribute]: T}>): WuIterable; + pluck(attribute: string): WuIterable; + reduce(fn: (a: T, b: T) => T): T; + reduce(fn: (a: T, b: T) => T, initial: T): T; + reduce(fn: (a: U, b: T) => U): U; + reduce(fn: (a: U, b: T) => U, initial: U): U; + reductions(fn: (a: T, b: T) => T): WuIterable; + reductions(fn: (a: T, b: T) => T, initial: T): WuIterable; + reductions(fn: (a: U, b: T) => U): WuIterable; + reductions(fn: (a: U, b: T) => U, initial: U): WuIterable; + reject(fn: Filter): WuIterable; + slice(): WuIterable; + slice(start: number): WuIterable; + slice(start: number, stop: number): WuIterable; + some(fn: Filter): WuIterable; + spreadMap(fn: (...x: any[]) => T, iter: Iterable): WuIterable; + take(n: number): WuIterable; + takeWhile(fn: Filter): WuIterable; + tap(fn: Consumer): WuIterable; + unique(): WuIterable; + zip(iter2: Iterable): WuIterable<[T, U]>; + zipLongest(iter2: Iterable): WuIterable<[T, U]>; + zipWith: any; + unzip: any; + tee(): WuIterable[]; + tee(n: number): WuIterable[]; + } +} +declare var wu: Wu.WuStatic; diff --git a/wu/wu.d.ts.tscparams b/wu/wu.d.ts.tscparams new file mode 100644 index 000000000..14fce22a5 --- /dev/null +++ b/wu/wu.d.ts.tscparams @@ -0,0 +1 @@ +--target ES6 From 0eaa2e33f76641182d1713c2f865c1417c68a37c Mon Sep 17 00:00:00 2001 From: Nick Zamosenchuk Date: Fri, 11 Dec 2015 14:13:49 +0100 Subject: [PATCH 04/18] [ngNotify] create Type Definition for Angular JS ngNotify library ngNotify is a simple, lightweight and elegant notification service for AngularJS applications. This commit/pull request contains a type definition for the latest version of this library --- ng-notify/ng-notify-tests.ts | 11 ++++++ ng-notify/ng-notify.d.ts | 72 ++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 ng-notify/ng-notify-tests.ts create mode 100644 ng-notify/ng-notify.d.ts diff --git a/ng-notify/ng-notify-tests.ts b/ng-notify/ng-notify-tests.ts new file mode 100644 index 000000000..4a03d62ce --- /dev/null +++ b/ng-notify/ng-notify-tests.ts @@ -0,0 +1,11 @@ +/// +/// + +class NgNotifyTestController { + + static $inject = ['$scope', 'ngNotify']; + + constructor($scope:ng.IScope, ngNotify:ngNotify.INotifyService) { + ngNotify.set('Your error message goes here!', 'error'); + } +}; \ No newline at end of file diff --git a/ng-notify/ng-notify.d.ts b/ng-notify/ng-notify.d.ts new file mode 100644 index 000000000..f1092df62 --- /dev/null +++ b/ng-notify/ng-notify.d.ts @@ -0,0 +1,72 @@ +// Type definitions for ng-notify 0.7.1 +// Project: https://github.com/matowens/ng-notify +// Definitions by: Nick Zamosenchuk +// Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + +declare module ngNotify { + + /** + * Contains the options used to configure notification. + */ + interface IUserOptions{ + type?: string; + theme?: string; + position?: string; + duration?: number; + sticky?: boolean; + button?: boolean; + html?: boolean; + } + + /** + * Simply and lightweight notification service for AngularJS + */ + interface INotifyService { + + /** + * Allows to create a whole new set of styles for each notification type. + * @param themeName The name used when setting the theme in the config object. + * @param className The class used to target this theme in the stylesheet. + */ + addTheme(themeName:string, className:string):void; + + /** + * Allows to create a new type of notification to use in their app. + * @param typeName The name used to trigger this notification type in the set method. + * @param className The class used to target this type in the stylesheet. + */ + addType(typeName:string, className:string):void; + + /** + * Sets default settings for all notifications to take into account when displaying. + * @param userOptions Notification configuration object + */ + config(userOptions: IUserOptions):void; + + /** + * Manually dismisses any sticky notifications that may still be set. + */ + dismiss():void; + + /** + * Displays a notification message. + * @param message A message text to display. + */ + set(message: string):void; + + /** + * Displays a notification message and sets the type for this one notification. + * @param message A message text to display. + * @param type The type of the notification. + */ + set(message: string, type: string):void; + + /** + * displays a notification message and sets the formatting/behavioral options for this one notification. + * @param message A message text to display. + * @param userOptions Notification configuration object. + */ + set(message: string, userOptions: IUserOptions):void; + } +} From 5c9b77c2db4f324ab2431f27b35a0b9c44383dbe Mon Sep 17 00:00:00 2001 From: George Wu Date: Fri, 11 Dec 2015 21:49:53 +0800 Subject: [PATCH 05/18] Added type definitions for sql.js. --- sql.js/sql.js-tests.ts | 81 ++++++++++++++++++++++++++++++++++++++++++ sql.js/sql.js.d.ts | 71 ++++++++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 sql.js/sql.js-tests.ts create mode 100644 sql.js/sql.js.d.ts diff --git a/sql.js/sql.js-tests.ts b/sql.js/sql.js-tests.ts new file mode 100644 index 000000000..eeba3f080 --- /dev/null +++ b/sql.js/sql.js-tests.ts @@ -0,0 +1,81 @@ +/// +/// + +import fs = require("fs"); +import SQL = require("sql.js"); + +var DB_PATH = "data.db"; + +function createFile(path: string): void { + var fd = fs.openSync(path, "a"); + fs.closeSync(fd); +} + +// Open the database file. If it does not exist, create a blank database in memory. +var databaseData: Buffer; +databaseData = fs.existsSync(DB_PATH) ? fs.readFileSync(DB_PATH) : null; +var db = new SQL.Database(databaseData); + +// Create a new table 'test_table' in the database in memory. +var createTableStatement = + "DROP TABLE IF EXISTS test_table;" + + "CREATE TABLE test_table (id INTEGER PRIMARY KEY, content TEXT);"; +db.run(createTableStatement); + +// Insert 2 records for testing. +var insertRecordStatement = + "INSERT INTO test_table (id, content) VALUES (@id, @content);"; +db.run(insertRecordStatement, { + "@id": 1, + "@content": "Content 1" +}); +db.run(insertRecordStatement, { + "@id": 2, + "@content": "Content 2" +}); + +try { + // This query will throw exception: primary key constraint failed. + db.run(insertRecordStatement, { + "@id": 1, + "@content": "Content 3" + }); +} catch (ex) { + console.warn(ex); +} + +// A simple SELECT query. +var selectRecordStatement = + "SELECT * FROM test_table WHERE id = @id;" +var selectStatementObject = db.prepare(selectRecordStatement); +var results = selectStatementObject.get({ + "@id": 1 +}); +console.log(results); +selectStatementObject.free(); + +// Access the results one by one, asynchronously. +var selectRecordsStatement = + "SELECT * FROM test_table;"; +db.each( + selectRecordsStatement, + (obj: SQL.SQLValueObject): void => { + console.log(obj); + }, + (): void => { + console.info("Iteration done."); + dbAccessDone(); + }); + + +function dbAccessDone(): void { + // Save the database into SQLite version 3 format. + if (!fs.existsSync(DB_PATH)) { + createFile(DB_PATH); + } + var exportedData = db.export(); + fs.writeFileSync(DB_PATH, exportedData); + + // Finally, close the database connection and release the resources in memory. + db.close(); +} diff --git a/sql.js/sql.js.d.ts b/sql.js/sql.js.d.ts new file mode 100644 index 000000000..5f2ddd069 --- /dev/null +++ b/sql.js/sql.js.d.ts @@ -0,0 +1,71 @@ + +// Type definitions for sql.js (Sep. 6 2015 snapshot) +// Project: https://github.com/kripken/sql.js +// Definitions by: George Wu +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "sql.js" { + + type SQLValue = number | string | Uint8Array; + type KeyValueObject = { [key: string]: SQLValue }; + type SQLValueObject = { [columnName: string]: SQLValue }; + type DataRow = SQLValue[]; + + class Database { + constructor(data: Buffer); + constructor(data: Uint8Array); + constructor(data: number[]); + + run(sql: string): Database; + run(sql: string, params: KeyValueObject): Database; + run(sql: string, params: SQLValue[]): Database; + + exec(sql: string): QueryResults[]; + + each(sql: string, callback: (obj: SQLValueObject) => void, done: () => void): void; + each(sql: string, params: KeyValueObject, callback: (obj: SQLValueObject) => void, done: () => void): void; + each(sql: string, params: SQLValue[], callback: (obj: SQLValueObject) => void, done: () => void): void; + + prepare(sql: string): Statement; + prepare(sql: string, params: KeyValueObject): Statement; + prepare(sql: string, params: SQLValue[]): Statement; + + export(): Uint8Array; + + close(): void; + } + + class Statement { + bind(): boolean; + bind(values: KeyValueObject): boolean; + bind(values: SQLValue[]): boolean; + + step(): boolean; + + get(): DataRow; + get(params: KeyValueObject): DataRow; + get(params: SQLValue[]): DataRow; + + getColumnNames(): string[]; + + getAsObject(): SQLValueObject; + getAsObject(params: KeyValueObject): SQLValueObject; + getAsObject(params: SQLValue[]): SQLValueObject; + + run(): void; + run(values: KeyValueObject): void; + run(values: SQLValue[]): void; + + reset(): void; + + freemem(): void; + + free(): boolean; + } + + interface QueryResults { + columns: string[]; + values: DataRow[]; + } + +} From 98339951b7a45fe9679a83777d61bad70a037976 Mon Sep 17 00:00:00 2001 From: George Wu Date: Fri, 11 Dec 2015 22:09:48 +0800 Subject: [PATCH 06/18] Renewed code to follow DefinitelyTyped's contribution guidelines. --- sql.js/sql.js-tests.ts | 2 +- sql.js/sql.js.d.ts | 46 +++++++++++++++++++----------------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/sql.js/sql.js-tests.ts b/sql.js/sql.js-tests.ts index eeba3f080..40fceb8fb 100644 --- a/sql.js/sql.js-tests.ts +++ b/sql.js/sql.js-tests.ts @@ -59,7 +59,7 @@ var selectRecordsStatement = "SELECT * FROM test_table;"; db.each( selectRecordsStatement, - (obj: SQL.SQLValueObject): void => { + (obj: { [columnName: string]: number | string | Uint8Array }): void => { console.log(obj); }, (): void => { diff --git a/sql.js/sql.js.d.ts b/sql.js/sql.js.d.ts index 5f2ddd069..d3f22afc1 100644 --- a/sql.js/sql.js.d.ts +++ b/sql.js/sql.js.d.ts @@ -1,15 +1,11 @@ - -// Type definitions for sql.js (Sep. 6 2015 snapshot) +// Type definitions for sql.js // Project: https://github.com/kripken/sql.js // Definitions by: George Wu // Definitions: https://github.com/borisyankov/DefinitelyTyped -declare module "sql.js" { +/// - type SQLValue = number | string | Uint8Array; - type KeyValueObject = { [key: string]: SQLValue }; - type SQLValueObject = { [columnName: string]: SQLValue }; - type DataRow = SQLValue[]; +declare module "sql.js" { class Database { constructor(data: Buffer); @@ -17,18 +13,18 @@ declare module "sql.js" { constructor(data: number[]); run(sql: string): Database; - run(sql: string, params: KeyValueObject): Database; - run(sql: string, params: SQLValue[]): Database; + run(sql: string, params: { [key: string]: number | string | Uint8Array }): Database; + run(sql: string, params: (number | string | Uint8Array)[]): Database; exec(sql: string): QueryResults[]; - each(sql: string, callback: (obj: SQLValueObject) => void, done: () => void): void; - each(sql: string, params: KeyValueObject, callback: (obj: SQLValueObject) => void, done: () => void): void; - each(sql: string, params: SQLValue[], callback: (obj: SQLValueObject) => void, done: () => void): void; + each(sql: string, callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void; + each(sql: string, params: { [key: string]: number | string | Uint8Array }, callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void; + each(sql: string, params: (number | string | Uint8Array)[], callback: (obj: { [columnName: string]: number | string | Uint8Array }) => void, done: () => void): void; prepare(sql: string): Statement; - prepare(sql: string, params: KeyValueObject): Statement; - prepare(sql: string, params: SQLValue[]): Statement; + prepare(sql: string, params: { [key: string]: number | string | Uint8Array }): Statement; + prepare(sql: string, params: (number | string | Uint8Array)[]): Statement; export(): Uint8Array; @@ -37,24 +33,24 @@ declare module "sql.js" { class Statement { bind(): boolean; - bind(values: KeyValueObject): boolean; - bind(values: SQLValue[]): boolean; + bind(values: { [key: string]: number | string | Uint8Array }): boolean; + bind(values: (number | string | Uint8Array)[]): boolean; step(): boolean; - get(): DataRow; - get(params: KeyValueObject): DataRow; - get(params: SQLValue[]): DataRow; + get(): (number | string | Uint8Array)[]; + get(params: { [key: string]: number | string | Uint8Array }): (number | string | Uint8Array)[]; + get(params: (number | string | Uint8Array)[]): (number | string | Uint8Array)[]; getColumnNames(): string[]; - getAsObject(): SQLValueObject; - getAsObject(params: KeyValueObject): SQLValueObject; - getAsObject(params: SQLValue[]): SQLValueObject; + getAsObject(): { [columnName: string]: number | string | Uint8Array }; + getAsObject(params: { [key: string]: number | string | Uint8Array }): { [columnName: string]: number | string | Uint8Array }; + getAsObject(params: (number | string | Uint8Array)[]): { [columnName: string]: number | string | Uint8Array }; run(): void; - run(values: KeyValueObject): void; - run(values: SQLValue[]): void; + run(values: { [key: string]: number | string | Uint8Array }): void; + run(values: (number | string | Uint8Array)[]): void; reset(): void; @@ -65,7 +61,7 @@ declare module "sql.js" { interface QueryResults { columns: string[]; - values: DataRow[]; + values: (number | string | Uint8Array)[][]; } } From bd1d3d2e0bf4a16d9d0aa3fee767b1d3658dc801 Mon Sep 17 00:00:00 2001 From: stephenjelfs Date: Fri, 11 Dec 2015 17:45:26 +0100 Subject: [PATCH 07/18] Initial definitions for react-datagrid. --- react-datagrid/react-datagrid-test.tsx | 82 +++++++ react-datagrid/react-datagrid.d.ts | 310 +++++++++++++++++++++++++ 2 files changed, 392 insertions(+) create mode 100644 react-datagrid/react-datagrid-test.tsx create mode 100644 react-datagrid/react-datagrid.d.ts diff --git a/react-datagrid/react-datagrid-test.tsx b/react-datagrid/react-datagrid-test.tsx new file mode 100644 index 000000000..c0ca90a1a --- /dev/null +++ b/react-datagrid/react-datagrid-test.tsx @@ -0,0 +1,82 @@ +/// +/// +/// + +import * as React from "react"; +import ReactDataGrid = require("react-datagrid"); + +var data: any[] = []; + +var columns: ReactDataGrid.Column[] = [ + { name: 'index', title: '#', width: 50 }, + { name: 'firstName', style: { color: 'red' }, visible: true}, + { name: 'lastName', render: (v) => {return v + " Phd"}}, + { name: 'city', textAlign: 'right', defaultVisible: true}, + { name: 'email', defaultHidden: true } +]; +var selected = {}; +var sortInfo: ReactDataGrid.SortInfo[] = [ { name: 'country', dir: 'asc'}] + +export module X { +export class ExampleBasic extends React.Component<{},{}> { + render(): React.ReactElement { + return ( + + ); + } +} +} + +class ExampleFull extends React.Component<{},{}> { + + render(): React.ReactElement { + return ( + {}} + onPageSizeChange={(pageSize: number, props: ReactDataGrid.DataGridProps) => {}} + onColumnOrderChange={(index: number, dropIndex: number) => {}} + onColumnResize={(firstCol: ReactDataGrid.Column, firstSize: number, secondCol: ReactDataGrid.Column, secondSize: number) => {}} + onSelectionChange={(newSelectedId: string, data: any) => {}} + onSortChange={(sortInfo: ReactDataGrid.SortInfo[]) => {}} + onFilter={(column: ReactDataGrid.Column, value: any, allFilterValues: any[]) => {} } + /> + ); + } +} diff --git a/react-datagrid/react-datagrid.d.ts b/react-datagrid/react-datagrid.d.ts new file mode 100644 index 000000000..aca7d355e --- /dev/null +++ b/react-datagrid/react-datagrid.d.ts @@ -0,0 +1,310 @@ +// Type definitions for react-datagrid 1.2.15 +// Project: https://github.com/zippyui/react-datagrid.git +// Definitions by: Stephen Jelfs +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "react-datagrid" { + import DataGrid = ReactDataGrid.DataGrid; + export = DataGrid; +} + +declare namespace ReactDataGrid { + import React = __React; + + interface DataGridProps extends React.Props { + /** + * Array/String/Function/Promise - for local data, an array of object + * to render in the grid. For remote data, a string url, or a function + * that returns a promise. + */ + dataSource: any[] | string | ((query: {pageSize: number, skip: number}) => Promise); + + dataSourceCount?: number; + + /** + * String - the name of the property where the id is found for each + * object in the data array. + */ + idProperty: string; + + /** + * Array - an array of columns that are going to be rendered in the + * grid. + */ + columns: Column[]; + + /** + * Sorting the data array is not done by the grid. You can however + * pass in sort info so the grid renders with sorting icons as needed. + */ + onSortChange?: (sortInfo: SortInfo[]) => void; + + /** + * Array - an array with sorting information. + */ + sortInfo?: SortInfo[]; + + style?: __React.CSSProperties; + + /** + * Object/Function - you can specify either a style object to be + * applied to all rows, or a function. The function is called with + * (data, props) (so you have access to props.index for example) and + * is expected to return a style object. + */ + rowStyle?: __React.CSSProperties | ((data: any, props: RowProps) => React.CSSProperties); + + /** + * Boolean - show a column menu to show/hide columns. + */ + withColumnMenu?: boolean; + + /** + * If you want to enable column reordering, just specify the + * onColumnOrderChange prop on the grid: + */ + onColumnOrderChange?: (index: number, dropIndex: number) => void; + + /** + * If you want to enable column resized, just specify the + * onColumnResize prop on the grid: + */ + onColumnResize?: (firstCol: Column, firstSize: number, + secondCol: Column, secondSize: number) => void; + + /** + * If you want to enable selection, just specify the + * onSelectionChange prop on the grid: + */ + onSelectionChange?: (newSelected: {}, data: any) => void; + + /** + * When a column is shown/hidden, you can be notified using the + * onColumnVisibilityChange callback prop. + */ + onColumnVisibilityChange?: (column: Column, visibility: boolean) => void; + + /** + * The current selection. + */ + selected?: {}; + + /** + * Group rows by matching values. + */ + groupBy?: any[]; + + /** + * If you want to enable filter, just specify the + * onFilter prop on the grid: + */ + onFilter?: (column: Column, value: any, allFilterValues: any[]) => void; + + /** + * To apply the filter while typing. + */ + liveFilter?: boolean; + + /** + * Empty text for no records. + */ + emptyText?: string; + + /** + * Loading grid. + */ + loading?: boolean; + + /** + * If you dont want loadMask over header, specify + */ + loadMaskOverHeader?: boolean; + + /** + * Show cell borders. Other valid values: 'horizontal', 'vertical'. + */ + showCellBorders?: boolean | string; + + /** + * Custom row height. + */ + rowHeight?: number; + + /** + * When you have remote data, pagination is setup by default. If you + * want to disable pagination, specify the pagination prop with a false + * value. + */ + pagination?: boolean; + defaultPageSize?: number; + defaultPage?: number; + + /** + * Number - controlled alternative for defaultPageSize. When pageSize + * changes, onPageSizeChange(pageSize) is called. + */ + pageSize?: number; + + /** + * Number - controlled alternative for defaultPage. When page changes, + * onPageChange(page) is called. + */ + page?: number; + + /** + * Customize the pagination toolbar. + */ + paginationToolbarProps?: PaginationToolbarProps; + + /** + * handle page changes. + */ + onPageChange?: (page: number) => void; + + /** + * handle page size changes. + */ + onPageSizeChange?: (pageSize: number, props: DataGridProps) => void; + } + + interface SortInfo { + name: string; + dir: string; + } + + interface Column { + /** + * String - each column should have a name property. + */ + name: string; + + /** + * String/ReactElement - a title to show in the header. If not + * specified, a humanized version of name will be used. Can be a string + * or anything that React can render, so you can customize it as you + * please. + */ + title?: string | React.ReactElement; + + /** + * Function - if you want custom rendering, specify this property. + * + * The column.render function is called with 3 args: + * value - the default value to be rendered (equals to data[column.name]) + * data - the corresponding data object for the current row + cellProps - an object with props for the current cell + */ + render?: (value: any, data: any, cellProps: CellProps) => any; + + /** + * Object - if you want cells in this column to be have a custom + * style. + */ + style?: __React.CSSProperties; + + /** + * String - one of 'left', 'right', 'center'. + */ + textAlign?: string; + + /** + * String - a className to be applied to all cells in this column + */ + className?: string; + + width?: number; + + minWidth?: number; + + /** + * Columns are flexible via flexbox. Specify a flex property for this. + * Unless a column specifies a flex or a width property, it is assumed + * to have flex: 1. + */ + flex?: number; + + /** + * Specify a column as visible/hidden. + */ + defaultVisible?: boolean; + defaultHidden?: boolean; + + /** + * Boolean - controlled (which means you have to manually set column + * visibility when it changes, by using onColumnVisibilityChange). + */ + visible?: boolean; + } + + interface CellProps { + /** + * the index of the row + */ + rowIndex: number; + + /** + * the index of the column + */ + index: number; + + /** + * a style for the cell + */ + style: React.CSSProperties; + + /** + * a class name for the cell + */ + className: string; + } + + interface RowProps { + /** + * the index of the row + */ + index: number; + + /** + * a class name for the row when the mouse is over it + */ + overClassName: string; + + /** + * a class name for the row when selected + */ + selectedClassName: string; + + /** + * a class name for the row + */ + className: string; + } + + interface PaginationToolbarProps { + /** + * Available page sizes. + */ + pageSizes: number[]; + + /** + * Hide/show page sizes. + */ + showPageSize: boolean; + + /** + * Customize icons. + */ + showRefreshIcon: boolean; + iconSize: number; + iconProps: { + style: React.SVGAttributes, + overStyle: React.SVGAttributes, + disabledStyle: React.SVGAttributes + } + } + + export class DataGrid extends __React.Component { + } +} From d065f93bab68ae7be4625c3b2847e601b2311505 Mon Sep 17 00:00:00 2001 From: stephenjelfs Date: Fri, 11 Dec 2015 17:58:28 +0100 Subject: [PATCH 08/18] Added missing promises --- react-datagrid/react-datagrid.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/react-datagrid/react-datagrid.d.ts b/react-datagrid/react-datagrid.d.ts index aca7d355e..1dc5d8361 100644 --- a/react-datagrid/react-datagrid.d.ts +++ b/react-datagrid/react-datagrid.d.ts @@ -4,6 +4,7 @@ // Definitions: https://github.com/borisyankov/DefinitelyTyped /// +/// declare module "react-datagrid" { import DataGrid = ReactDataGrid.DataGrid; From 55f9ccc901fbb3c42c8afd2d2bcc2ca864054062 Mon Sep 17 00:00:00 2001 From: stephenjelfs Date: Fri, 11 Dec 2015 18:07:34 +0100 Subject: [PATCH 09/18] Renamed tests file. --- .../{react-datagrid-test.tsx => react-datagrid-tests.tsx} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename react-datagrid/{react-datagrid-test.tsx => react-datagrid-tests.tsx} (100%) diff --git a/react-datagrid/react-datagrid-test.tsx b/react-datagrid/react-datagrid-tests.tsx similarity index 100% rename from react-datagrid/react-datagrid-test.tsx rename to react-datagrid/react-datagrid-tests.tsx From fc18b2dfd426eaf96ce4ca0f003d23656b952da6 Mon Sep 17 00:00:00 2001 From: Stefan Geneshky Date: Fri, 11 Dec 2015 10:14:44 -0800 Subject: [PATCH 10/18] Update Mithril definitions --- mithril/mithril.d.ts | 250 +++++++++++++++++++++++++++++-------------- 1 file changed, 167 insertions(+), 83 deletions(-) diff --git a/mithril/mithril.d.ts b/mithril/mithril.d.ts index 3cd0e21e4..c2304e7ec 100644 --- a/mithril/mithril.d.ts +++ b/mithril/mithril.d.ts @@ -5,90 +5,174 @@ //Mithril type definitions for Typescript -interface MithrilStatic { - (selector: string, attributes: Object, children?: any): MithrilVirtualElement; - (selector: string, children?: any): MithrilVirtualElement; - prop(value?: T): (value?: T) => T; - prop(promise: MithrilPromise): MithrilPromiseProperty; - withAttr(property: string, callback: (value: any) => void): (e: Event) => any; - module(rootElement: Node, module: MithrilModule): void; - trust(html: string): String; - render(rootElement: Element, children?: any): void; - render(rootElement: HTMLDocument, children?: any): void; - redraw: MithrilRedraw; - route: MithrilRoute; - request(options: MithrilXHROptions): MithrilPromise; - deferred(): MithrilDeferred; - sync(promises: MithrilPromise[]): MithrilPromise; - startComputation(): void; - endComputation(): void; +declare module _mithril { + interface MithrilStatic { + + (selector: string, attributes: MithrilAttributes, ...children: Array>): MithrilVirtualElement; + (selector: string, ...children: Array>): MithrilVirtualElement; + + prop(promise: MithrilPromise) : MithrilPromiseProperty; + prop(value: T): MithrilProperty; + prop(): MithrilProperty; // might be that this should be Property + + withAttr(property: string, callback: (value: any) => void): (e: MithrilEvent) => any; + + module(rootElement: Node, component: MithrilComponent): T; + module(rootElement: Node): T; + mount(rootElement: Node, component: MithrilComponent): T; + mount(rootElement: Node): T; + + component(component: MithrilComponent, ...args: Array): MithrilComponent + + trust(html: string): string; + + render(rootElement: Element|HTMLDocument): void; + render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement, forceRecreation?: boolean): void; + render(rootElement: Element|HTMLDocument, children: MithrilVirtualElement[], forceRecreation?: boolean): void; + + redraw: { + (force?: boolean): void; + strategy: MithrilProperty; + } + + route: { + (rootElement: HTMLDocument, defaultRoute: string, routes: MithrilRoutes): void; + (rootElement: Element, defaultRoute: string, routes: MithrilRoutes): void; + + (element: Element, isInitialized: boolean, context: Object, vdom: Object): void; + (path: string, params?: any, shouldReplaceHistory?: boolean): void; + (): string; + + param(key: string): string; + mode: string; + buildQueryString(data: Object): String + parseQueryString(data: String): Object + } + + request(options: MithrilXHROptions): MithrilPromise; + + deferred: { + onerror(e: Error): void; + (): MithrilDeferred; + } + + sync(promises: MithrilPromise[]): MithrilPromise; + + startComputation(): void; + endComputation(): void; + + // For test suite + deps: { + (mockWindow: Window): Window; + factory: Object; + } + + } + + export interface MithrilVirtualElement { + key?: number; + tag?: string; + attrs?: MithrilAttributes; + children?: any[]; + } + + // Configuration function for an element + interface MithrilElementConfig { + (element: Element, isInitialized: boolean, context?: any, vdom?: MithrilVirtualElement): void; + } + + // Attributes on a virtual element + interface MithrilAttributes { + title?: string; + className?: string; + class?: string; + config?: MithrilElementConfig; + } + + // Defines the subset of Event that Mithril needs + interface MithrilEvent { + currentTarget: Element; + } + + interface MithrilController { + onunload?(evt: Event): any; + } + + interface MithrilControllerFunction extends MithrilController { + (): any; + } + + interface MithrilView { + (ctrl: T): string|MithrilVirtualElement; + } + + interface MithrilComponent { + controller: MithrilControllerFunction|{ new(): T }; + view: MithrilView; + } + + interface MithrilProperty { + (): T; + (value: T): T; + toJSON(): T; + } + + interface MithrilPromiseProperty extends MithrilPromise { + (): T; + (value: T): T; + toJSON(): T; + } + + interface MithrilRoutes { + [key: string]: MithrilComponent; + } + + + interface MithrilDeferred { + resolve(value?: T): void; + reject(value?: any): void; + promise: MithrilPromise; + } + + interface MithrilSuccessCallback { + (value: T): U; + (value: T): MithrilPromise; + } + + interface MithrilErrorCallback { + (value: Error): U; + (value: string): U; + } + + interface MithrilPromise { + (): T; + (value: T): T; + then(success: (value: T) => U): MithrilPromise; + then(success: (value: T) => MithrilPromise): MithrilPromise; + then(success: (value: T) => U, error: (value: Error) => V): MithrilPromise|MithrilPromise; + then(success: (value: T) => MithrilPromise, error: (value: Error) => V): MithrilPromise|MithrilPromise; + } + interface MithrilXHROptions { + method?: string; + url: string; + user?: string; + password?: string; + data?: any; + background?: boolean; + unwrapSuccess?(data: any): any; + unwrapError?(data: any): any; + serialize?(dataToSerialize: any): string; + deserialize?(dataToDeserialize: string): any; + extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; + type?(data: Object): void; + config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; + dataType?: string; + } } -interface MithrilRoute { - (rootElement: Element, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; - (rootElement: HTMLDocument, defaultRoute: string, routes: { [key: string]: MithrilModule }): void; - (path: string, params?: any, shouldReplaceHistory?: boolean): void; - (element: Element, isInitialized: boolean): void; - (): string; - mode: string; - param: MithrilParam; - buildQueryString(data: Object): string; - parseQueryString(queryString: string): Object; -} +declare var Mithril: _mithril.MithrilStatic; +declare var m: _mithril.MithrilStatic; -interface MithrilParam { - (param: string): string; +declare module "mithril" { + export = m; } - -interface MithrilRedraw { - (): void; - strategy: (value?: string) => string; -} - -interface MithrilVirtualElement { - tag: string; - attrs: Object; - children: any; -} - -interface MithrilModule { - controller: Function; - view: (controller?: any) => MithrilVirtualElement; -} - -interface MithrilDeferred { - resolve(value?: T): void; - reject(value?: any): void; - promise: MithrilPromise; -} - -interface MithrilPromise { - (value?: T): T; - then(successCallback?: (value: T) => R, errorCallback?: (value: any) => any): MithrilPromise; - then(successCallback?: (value: T) => MithrilPromise, errorCallback?: (value: any) => any): MithrilPromise; -} - -interface MithrilPromiseProperty extends MithrilPromise { - (): T; - (value: T): T; - toJSON(): T; -} - -interface MithrilXHROptions { - method: string; - url: string; - user?: string; - password?: string; - data?: any; - background?: boolean; - unwrapSuccess?(data: any): any; - unwrapError?(data: any): any; - serialize?(dataToSerialize: any): string; - deserialize?(dataToDeserialize: string): any; - extract?(xhr: XMLHttpRequest, options: MithrilXHROptions): string; - type?(data: Object): void; - config?(xhr: XMLHttpRequest, options: MithrilXHROptions): XMLHttpRequest; -} - -declare var Mithril: MithrilStatic; -declare var m: MithrilStatic; From 208be8144e834ae82881ab9414c57c6fcd5ef11c Mon Sep 17 00:00:00 2001 From: Dan Marshall Date: Fri, 11 Dec 2015 10:23:13 -0800 Subject: [PATCH 11/18] added optional rendering type --- fullCalendar/fullCalendar.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/fullCalendar/fullCalendar.d.ts b/fullCalendar/fullCalendar.d.ts index 6400dba7e..7415bdd73 100644 --- a/fullCalendar/fullCalendar.d.ts +++ b/fullCalendar/fullCalendar.d.ts @@ -247,6 +247,7 @@ declare module FullCalendar { backgroundColor?: string; borderColor?: string; textColor?: string; + rendering?: string; } export interface ViewObject extends Timespan { From f3eeb32d711a1985cec596acb9424bcd827fe2a0 Mon Sep 17 00:00:00 2001 From: Mark Nadig Date: Fri, 11 Dec 2015 10:55:03 -0700 Subject: [PATCH 12/18] ng-dialog add IDialogOptions.disableAnimation, IDialogOpenOptions.data and upadated test --- ng-dialog/ng-dialog-tests.ts | 2 ++ ng-dialog/ng-dialog.d.ts | 10 ++++++++++ 2 files changed, 12 insertions(+) diff --git a/ng-dialog/ng-dialog-tests.ts b/ng-dialog/ng-dialog-tests.ts index 6d68111a6..27f50f89c 100644 --- a/ng-dialog/ng-dialog-tests.ts +++ b/ng-dialog/ng-dialog-tests.ts @@ -20,6 +20,8 @@ class DialogTestController { template: "login.html", className: "default flat-ui", closeByEscape: false, + data: "string", + disableAnimation: false, name: "login-popup" }); diff --git a/ng-dialog/ng-dialog.d.ts b/ng-dialog/ng-dialog.d.ts index 3ad5c4d09..95f02af63 100644 --- a/ng-dialog/ng-dialog.d.ts +++ b/ng-dialog/ng-dialog.d.ts @@ -61,6 +61,12 @@ declare module angular.dialog { * It will be appended with the "ngdialog" class e.g. className is "default-theme flat-ui" it will be class="ngdialog default-theme flat-ui". */ className?: string; + + /** + * If true then animation for the dialog will be disabled, default false. + */ + disableAnimation?: boolean; + /** * If false it allows to hide overlay div behind the modals, default true. */ @@ -106,5 +112,9 @@ declare module angular.dialog { * Scope object that will be passed to dialog. If you use controller with separate $scope service this object will be passed to $scope.$parent param. */ scope?: ng.IScope; + /** + * Any serializable data that you want to be stored in the controller's dialog scope. + */ + data?: string|Object|any[]; } } From c3dce5b44d8ee3ac1cdc6e074626acc5fb8ce79c Mon Sep 17 00:00:00 2001 From: Kaur Kuut Date: Sat, 12 Dec 2015 15:51:42 +0200 Subject: [PATCH 13/18] Restored jsSHA browser global definition & test. --- jssha/jssha-tests.ts | 7 +++++++ jssha/jssha.d.ts | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/jssha/jssha-tests.ts b/jssha/jssha-tests.ts index f6e0f96b4..e5a83b14a 100644 --- a/jssha/jssha-tests.ts +++ b/jssha/jssha-tests.ts @@ -46,4 +46,11 @@ let hmac5:string = shaObj1.getHMAC("HEX", { outputUpper: true, b64Pad: '=' }); shaObj.setHMACKey("abc", "TEXT"); shaObj.update("This is a test"); let hmac = shaObj.getHMAC("HEX"); +} + +// Browser global test +{ + var shaObj = new jsSHA("SHA-512", "TEXT"); + shaObj.update("This is a test"); + var hash = shaObj.getHash("HEX"); } \ No newline at end of file diff --git a/jssha/jssha.d.ts b/jssha/jssha.d.ts index 6dc4f65d3..f695a6670 100644 --- a/jssha/jssha.d.ts +++ b/jssha/jssha.d.ts @@ -79,7 +79,7 @@ declare module jsSHA { } } +declare var jsSHA: jsSHA.jsSHA; declare module 'jssha' { - var jsSHA: jsSHA.jsSHA; export = jsSHA; -} \ No newline at end of file +} From 5b5bfbec4c121532ac5754e742797ed3eb9fe6da Mon Sep 17 00:00:00 2001 From: abraaoalves Date: Sat, 12 Dec 2015 10:54:06 -0300 Subject: [PATCH 14/18] definitions to steps and hooks --- cucumber/cucumber-tests.ts | 40 ++++++++++++++++++++++++++ cucumber/cucumber.d.ts | 57 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 97 insertions(+) create mode 100644 cucumber/cucumber-tests.ts create mode 100644 cucumber/cucumber.d.ts diff --git a/cucumber/cucumber-tests.ts b/cucumber/cucumber-tests.ts new file mode 100644 index 000000000..ba7ff1f72 --- /dev/null +++ b/cucumber/cucumber-tests.ts @@ -0,0 +1,40 @@ +/// + +function StepSample() { + type Callback = cucumber.CallbackStepDefinition; + var step = this; + var hook = this; + + hook.Before(function(scenario, callback){ + scenario.isFailed() && callback.pending(); + }) + + hook.Around(function(scenario, runScenario) { + scenario.isFailed() && runScenario(null, function(){ + console.log('finish tasks'); + }); + }); + + hook.registerHandler('AfterFeatures', function (event, callback) { + callback(); + }); + + step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback) { + this.visit('https://github.com/cucumber/cucumber-js', callback); + }); + + step.When(/^I go to the README file$/, function(title:string, callback:Callback) { + callback.pending(); + }); + + step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback) { + var pageTitle = this.browser.text('title'); + + if (title === pageTitle) { + callback(); + } else { + callback(new Error("Expected to be on page with title " + title)); + } + }); +} + diff --git a/cucumber/cucumber.d.ts b/cucumber/cucumber.d.ts new file mode 100644 index 000000000..b70fbb6b4 --- /dev/null +++ b/cucumber/cucumber.d.ts @@ -0,0 +1,57 @@ +// Type definitions for cucumber-js +// Project: https://github.com/cucumber/cucumber-js +// Definitions by: Abraão Alves +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// + +declare module cucumber { + + export interface CallbackStepDefinition{ + pending : () => Thenable; + (errror?:any):void; + } + + interface StepDefinitionCode { + (...stepArgs: Array): Thenable | any | void; + } + + interface StepDefinitionOptions{ + timeout?: number; + } + + export interface StepDefinitions { + Given(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + Given(pattern: RegExp | string, code: StepDefinitionCode): void; + When(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + When(pattern: RegExp | string, code: StepDefinitionCode): void; + Then(pattern: RegExp | string, options: StepDefinitionOptions, code: StepDefinitionCode): void; + Then(pattern: RegExp | string, code: StepDefinitionCode): void; + setDefaultTimeout(time:number): void; + } + + interface HookScenario{ + attach(text: string, mimeType?: string, callback?: (err?) => void): void; + isFailed() : boolean; + } + + interface HookCode { + (scenario: HookScenario, callback?: CallbackStepDefinition): void; + } + + interface AroundCode{ + (scenario: HookScenario, runScenario?: (error:string, callback?:Function)=>void): void; + } + + export interface Hooks { + Before(code: HookCode): void; + After(code: HookCode): void; + Around(code: AroundCode):void; + setDefaultTimeout(time:number): void; + registerHandler(handlerOption:string, code:(event, callback:CallbackStepDefinition) =>void): void; + } +} + +declare module 'cucumber'{ + export = cucumber; +} \ No newline at end of file From 0bcb4658eca981568d5cce48fd4b370c8778cbd6 Mon Sep 17 00:00:00 2001 From: abraaoalves Date: Sat, 12 Dec 2015 11:24:19 -0300 Subject: [PATCH 15/18] fix noimplicitAny errors --- cucumber/cucumber-tests.ts | 6 +++--- cucumber/cucumber.d.ts | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/cucumber/cucumber-tests.ts b/cucumber/cucumber-tests.ts index ba7ff1f72..f8b560607 100644 --- a/cucumber/cucumber-tests.ts +++ b/cucumber/cucumber-tests.ts @@ -1,4 +1,4 @@ -/// +/// function StepSample() { type Callback = cucumber.CallbackStepDefinition; @@ -19,7 +19,7 @@ function StepSample() { callback(); }); - step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback) { + step.Given(/^I am on the Cucumber.js GitHub repository$/, function(callback:Callback) { this.visit('https://github.com/cucumber/cucumber-js', callback); }); @@ -27,7 +27,7 @@ function StepSample() { callback.pending(); }); - step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback) { + step.Then(/^I should see "(.*)" as the page title$/, { timeout:60*1000}, function(title:string, callback:Callback) { var pageTitle = this.browser.text('title'); if (title === pageTitle) { diff --git a/cucumber/cucumber.d.ts b/cucumber/cucumber.d.ts index b70fbb6b4..75faeff7a 100644 --- a/cucumber/cucumber.d.ts +++ b/cucumber/cucumber.d.ts @@ -31,7 +31,7 @@ declare module cucumber { } interface HookScenario{ - attach(text: string, mimeType?: string, callback?: (err?) => void): void; + attach(text: string, mimeType?: string, callback?: (err?:any) => void): void; isFailed() : boolean; } @@ -48,7 +48,7 @@ declare module cucumber { After(code: HookCode): void; Around(code: AroundCode):void; setDefaultTimeout(time:number): void; - registerHandler(handlerOption:string, code:(event, callback:CallbackStepDefinition) =>void): void; + registerHandler(handlerOption:string, code:(event:any, callback:CallbackStepDefinition) =>void): void; } } From 0bb3a46b8baea5eb91e50560fc5cfd4b5895e1ba Mon Sep 17 00:00:00 2001 From: phiresky Date: Sat, 12 Dec 2015 15:58:14 +0100 Subject: [PATCH 16/18] wu: fix project link --- wu/wu.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wu/wu.d.ts b/wu/wu.d.ts index 61a0e6e97..cb794ff30 100644 --- a/wu/wu.d.ts +++ b/wu/wu.d.ts @@ -1,5 +1,5 @@ // Type definitions for wu.js v2.1.0 -// Project: http://backbonejs.org/ +// Project: https://fitzgen.github.io/wu.js/ // Definitions by: phiresky // Definitions: https://github.com/borisyankov/DefinitelyTyped From e2309e6ed913f2733eb8f6af1d56d22a93d0a6e3 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 12 Dec 2015 22:32:14 +0500 Subject: [PATCH 17/18] lodash: signatures of _.isFunction have been changed --- lodash/lodash-tests.ts | 39 ++++++++++++++++++++++++++++----------- lodash/lodash.d.ts | 10 +++++++++- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 2d244b16e..9cf772cab 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -5532,17 +5532,34 @@ result = _([]).isFinite(); result = _({}).isFinite(); // _.isFunction -result = _.isFunction(any); -result = _(1).isFunction(); -result = _([]).isFunction(); -result = _({}).isFunction(); -{ - let value: Function|string = "foo"; - if (_.isFunction(value)) { - value(); - } else { - let result: string = value; - } +module TestIsFunction { + { + let value: number|Function; + + if (_.isFunction(value)) { + let result: Function = value; + } + else { + let result: number = value; + } + } + + { + let result: boolean; + + result = _.isFunction(any); + result = _(1).isFunction(); + result = _([]).isFunction(); + result = _({}).isFunction(); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _(1).chain().isFunction(); + result = _([]).chain().isFunction(); + result = _({}).chain().isFunction(); + } } // _.isMatch diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 8425f1d82..81d78b1bc 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -9434,9 +9434,10 @@ declare module _ { interface LoDashStatic { /** * Checks if value is classified as a Function object. + * * @param value The value to check. * @return Returns true if value is correctly classified, else false. - **/ + */ isFunction(value?: any): value is Function; } @@ -9447,6 +9448,13 @@ declare module _ { isFunction(): boolean; } + interface LoDashExplicitWrapperBase { + /** + * @see _.isFunction + */ + isFunction(): LoDashExplicitWrapper; + } + //_.isMatch interface isMatchCustomizer { (value: any, other: any, indexOrKey?: number|string): boolean; From 05e67b229d29cc921dd8fd3c42991c897445f547 Mon Sep 17 00:00:00 2001 From: Panu Horsmalahti Date: Sat, 12 Dec 2015 23:52:03 +0200 Subject: [PATCH 18/18] Add type definitions for cradle. --- cradle/cradle-tests.ts | 185 +++++++++++++++++++++++++++++++++++++++++ cradle/cradle.d.ts | 122 +++++++++++++++++++++++++++ 2 files changed, 307 insertions(+) create mode 100644 cradle/cradle-tests.ts create mode 100644 cradle/cradle.d.ts diff --git a/cradle/cradle-tests.ts b/cradle/cradle-tests.ts new file mode 100644 index 000000000..655e92a87 --- /dev/null +++ b/cradle/cradle-tests.ts @@ -0,0 +1,185 @@ +/// + +import cradle = require("cradle"); + +cradle.setup({ + host: 'living-room.couch', + cache: true, + raw: false, + forceSave: true +}); + +const connection = new cradle.Connection(); +const connection2 = new(cradle.Connection); +const connection3 = new(cradle.Connection)('173.45.66.92'); + +connection.databases(function(error, response) {}); +connection.config(function(error, response) {}); +connection.databases(function(error, response) {}); +connection.info(function(error, response) {}); +connection.stats(function(error, response) {}); +connection.activeTasks(function(error, response) {}); +connection.uuids(function(error, response) {}); +connection.uuids(10, function(error, response) {}); +connection.replicate({ + source: "database", + target: "targetDatabase" +}, function(error, response) {}); + +const db = connection.database('starwars'); + +db.exists(function (error, exists) { + if (error) { + console.log('error', error); + } else if (exists) { + console.log('the force is with you.'); + } else { + console.log('database does not exists.'); + db.create(function(error){ + /* do something if there's an erroror */ + /* populate design documents */ + }); + } +}); + +db.get<{ + name: string; +}>('vader', function (error, doc) { + doc.name; // 'Darth Vader' +}); + +db.get('luke', function (error, doc) { + doc.prop; +}); + + db.get(['luke', 'vader'], function (error, doc) { + // + }); + +db.save('skywalker', { + force: 'light', + name: 'Luke Skywalker' +}, function (error, res) { + if (error) { + // Handle erroror + } else { + // Handle success + } +}); + +db.save({ + force: 'dark', name: 'Darth' + }, function (err, res) { + // Handle response + }); + +db.save('luke', '1-94B6F82', { + force: 'dark', name: 'Luke' +}, function (err, res) { + // Handle response +}); + +db.save([ + { name: 'Yoda' }, + { name: 'Han Solo' }, + { name: 'Leia' } +], function (err, res) { + // Handle response +}); + +db.merge('luke', {jedi: true}, function (err, res) { + // Luke is now a jedi, + // but remains on the dark side of the force. +}); + +db.view('characters/all', function (err, res) { + res.forEach(function (row: any) { + console.log("%s is on the %s side of the force.", row.name, row.force); + }); +}); + +db.view('characters/all', {group: true, reduce: true} , function (err, res) { + res.forEach(function (row: any) { + console.log("%s is on the %s side of the force.", row.name, row.force); + }); + }); + + db.temporaryView({ + map: function (doc: any) { + // + } + }, function (err, res) { + if (err) console.log(err); + console.log(res); + }); + +db.remove('luke', '1-94B6F82', function (err, res) { + // Handle response +}); + +db.update('my_designdoc/update_handler_name', 'luke', undefined, { my_param: false }, function (err, res) { + // Handle the response, specified by the update handler +}); + +db.changes(function (err, list) { + list.forEach(function (change) { console.log(change) }); +}); + +db.changes({ since: 42 }, function (err, list) { + // +}); + +const feed = db.changes({ since: 42 }); + +feed.on('change', function (change: any) { + console.log(change); +}); + +const idAndRevData = { + id: 'luke', + rev: 'my-rev' +}; + +const attachmentData = { + name: 'fooAttachment.txt', + 'Content-Type': 'text/plain', + body: 'Foo document text' +}; + +db.saveAttachment(idAndRevData, attachmentData, function (err, reply) { + if (err) { + console.dir(err) + return + } + console.dir(reply) +}); + + +db.getAttachment('luke', 'foo.txt', function (err, reply) { + if (err) { + console.dir(err); + return; + } + console.dir(reply); +}); + +db.removeAttachment('luke', 'foo.txt', function (err, reply) { + if (err) { + console.dir(err); + return; + } + console.dir(reply); +}); + +db.info(function(error, response) {}); +db.all(function(error, response) {}); +db.all({ + body: { + keys: ['key1', 'key2'] + } +}, function(error, response) {}); +db.compact(function(error, response) {}); +db.compact('design', function(error, response) {}); +db.viewCleanup(function(error, response) {}); +db.replicate('database', function(error, response) {}); +db.replicate('database', {}, function(error, response) {}); diff --git a/cradle/cradle.d.ts b/cradle/cradle.d.ts new file mode 100644 index 000000000..6434af26c --- /dev/null +++ b/cradle/cradle.d.ts @@ -0,0 +1,122 @@ +// Type definitions for cradle +// Project: https://github.com/flatiron/cradle +// Definitions by: Panu Horsmalahti +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +declare module "cradle" { + interface Options { + host?: string; + hostname?: string; + cache?: boolean; + raw?: boolean; + forceSave?: boolean; + auth?: string | { + username: string; + password: string; + } + ca?: string; + secure?: boolean; + retries?: number; + retryTimeout?: number; + maxSockets?: number; + } + + interface Callback { + (error: any, response: any): void; + } + + interface ErrorCallback { + (error: any): void; + } + + export class Connection { + constructor(uri?: string, port?: number, options?: Options); + database(name: string): Database; + databases(Callback: Callback): void; + config(callback: Callback): void; + info(callback: Callback): void; + stats(callback: Callback): void; + activeTasks(callback: Callback): void; + uuids(callback: Callback): void; + uuids(count: number, callback: Callback): void; + replicate(options: { + source: string | { + url: string; + }; + target: string | { + url: string; + }; + cancel?: boolean; + continuous?: boolean; + create_target?: boolean; + doc_ids?: string[]; + filter?: string; + proxy?: string; + query_params?: any; + }, callback: Callback): void; + } + + export interface ChangesOptions { + since: number; + } + + export class Database { + name: string; + get(id: string, callback: (error: any, document: any) => void): void; + get(id: string, callback: (error: any, document: T) => void): void; + get(id: string, rev: string, callback: (error: any, document: any) => void): void; + get(id: string, rev: string, callback: (error: any, document: T) => void): void; + get(ids: string[], callback: Callback): void; + save(document: any, callback: Callback): void; + save(id: string, document: any, callback: Callback): void; + save(id: string, revision: string, document: any, + callback: Callback): void; + save(document: T, callback: Callback): void; + save(id: string, document: T, callback: Callback): void; + save(id: string, revision: string, document: T, + callback: Callback): void; + save(documents: any[], callback: Callback): void; + merge(id: string, document: any, callback: Callback): void; + merge(id: string, document: T, callback: Callback): void; + remove(id: string, revision: string, callback: Callback): void; + update(name: string, id: string, queryObject: any, documentBody: any, + callback: Callback): void; + view(name: string, callback: Callback): void; + view(name: string, options: { + group?: boolean; + reduce?: boolean; + key?: string; + startkey?: any; + endkey?: any; + include_docs?: boolean; + limit?: number; + descending?: boolean; + }, callback: Callback): void; + temporaryView(view: any, callback: Callback): void; + create(callback: ErrorCallback): void; + exists(callback: (error: any, exists: boolean) => void): void; + destroy(callback: ErrorCallback): void; + changes(options: ChangesOptions): any; + changes(callback: (error: any, list: any[]) => void): void; + changes(options: ChangesOptions, callback: (error: any, + list: any[]) => void): void; + saveAttachment(idAndRevData: { + id: string; + rev: string; + }, attachmentData: any, callback: Callback): void; + getAttachment(id: string, attachmentName: string, + callback: Callback): void; + removeAttachment(id: string, attachmentName: string, + callback: Callback): void; + info(callback: Callback): void; + all(callback: Callback): void; + all(options: any, callback: Callback): void; + compact(callback: Callback): void; + compact(design: string, callback: Callback): void; + viewCleanup(callback: Callback): void; + replicate(target: string, callback: Callback): void; + replicate(target: string, options: any, callback: Callback): void; + } + + export function setup(options: Options): void; +}