From 49a92ea8370ec58396e1197d225b5c8cb453f861 Mon Sep 17 00:00:00 2001 From: Frank Ebersoll Date: Wed, 7 Oct 2015 16:55:39 +0200 Subject: [PATCH 1/4] Node.js: Added child_process.spawnSync --- node/node-tests.ts | 10 +++++++++- node/node.d.ts | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/node/node-tests.ts b/node/node-tests.ts index a73a35e223..9662258742 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -13,6 +13,7 @@ import * as dgram from "dgram"; import * as querystring from "querystring"; import * as path from "path"; import * as readline from "readline"; +import * as childProcess from "child_process"; assert(1 + 1 - 2 === 0, "The universe isn't how it should."); @@ -34,7 +35,7 @@ assert.doesNotThrow(() => { fs.writeFile("thebible.txt", "Do unto others as you would have them do unto you.", assert.ifError); - + fs.write(1234, "test"); fs.writeFile("Harry Potter", @@ -382,3 +383,10 @@ rl.prompt(true); rl.question("do you like typescript?", function(answer: string) { rl.close(); }); + +////////////////////////////////////////////////////////////////////// +/// Child Process tests: https://nodejs.org/api/child_process.html /// +////////////////////////////////////////////////////////////////////// + +childProcess.exec("echo test"); +childProcess.spawnSync("echo test"); diff --git a/node/node.d.ts b/node/node.d.ts index e90a4a1461..e8a6ebec31 100644 --- a/node/node.d.ts +++ b/node/node.d.ts @@ -868,6 +868,26 @@ declare module "child_process" { env?: any; encoding?: string; }): ChildProcess; + export function spawnSync(command: string, args?: string[], options?: { + cwd?: string; + input?: string | Buffer; + stdio?: any; + env?: any; + uid?: number; + gid?: number; + timeout?: number; + maxBuffer?: number; + killSignal?: string; + encoding?: string; + }): { + pid: number; + output: string[]; + stdout: string | Buffer; + stderr: string | Buffer; + status: number; + signal: string; + error: Error; + }; export function execSync(command: string, options?: { cwd?: string; input?: string|Buffer; From ece21f9b5b1fb8477987cea706e915aa5373440c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Thu, 8 Oct 2015 10:01:50 +0200 Subject: [PATCH 2/4] Add pngjs2 definition file --- pngjs2/pngjs2-tests.ts | 26 +++++++++++++++++ pngjs2/pngjs2.d.ts | 66 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) create mode 100644 pngjs2/pngjs2-tests.ts create mode 100644 pngjs2/pngjs2.d.ts diff --git a/pngjs2/pngjs2-tests.ts b/pngjs2/pngjs2-tests.ts new file mode 100644 index 0000000000..ae2d73e7b3 --- /dev/null +++ b/pngjs2/pngjs2-tests.ts @@ -0,0 +1,26 @@ +/// + +import * as fs from "fs"; +import { PNG } from "pngjs2"; + +let png = new PNG({ filterType: 4 }); + +fs.createReadStream("in.png") + .pipe(png) + .on("parsed", () => { + for (let y = 0; y < png.height; y++) { + for (let x = 0; x < png.width; x++) { + let idx = (png.width * y + x) << 2; + + // invert color + png.data[idx] = 255 - png.data[idx]; + png.data[idx+1] = 255 - png.data[idx+1]; + png.data[idx+2] = 255 - png.data[idx+2]; + + // and reduce opacity + png.data[idx+3] = png.data[idx+3] >> 1; + } + } + + png.pack().pipe(fs.createWriteStream('out.png')); + }); diff --git a/pngjs2/pngjs2.d.ts b/pngjs2/pngjs2.d.ts new file mode 100644 index 0000000000..bc2e061ccc --- /dev/null +++ b/pngjs2/pngjs2.d.ts @@ -0,0 +1,66 @@ +// Type definitions for pngjs2 1.2.0 +// Project: https://www.npmjs.com/package/pngjs2 +// Definitions by: Elisée Maurer +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// + +declare module "pngjs2" { + import fs = require("fs"); + import events = require("events"); + import stream = require("stream"); + + interface PNGOptions { + width?: number; + height?: number; + checkCRC?: boolean; + deflateChunkSize?: number; + deflateLevel?: number; + deflateStrategy?: number; + deflateFactory?: any; + filterType?: number|number[]; + colorType?: number; + inputHasAlpha?: boolean; + } + + interface PNGMetadata { + width: number; + height: number; + palette: boolean; + color: boolean; + alpha: boolean; + interlace: boolean; + } + + export class PNG extends stream.Writable { + constructor(options?: PNGOptions); + + width: number; + height: number; + data: Buffer; + gamma: number; + + on(event: string, callback: Function): PNG; + on(event: "metadata", callback: (metadata: PNGMetadata) => void): PNG; + on(event: "parsed", callback: (data: Buffer) => void): PNG; + on(event: "error", callback: (err: Error) => void): PNG; + + parse(data: string|Buffer, callback?: (err: Error, data: Buffer) => void): PNG; + pack(): PNG; + pipe(destination: fs.WriteStream): PNG; + + static bitblt(src: PNG, dst: PNG, srcX: number, srcY: number, + width: number, height: number, deltaX: number, deltaY: number): void; + + // This method's signature is wrong in 1.2.0, see https://github.com/lukeapage/pngjs2/pull/29 + // Use the static version in the meantime + /*bitblt(dst: PNG, srcX: number, srcY: number, + width: number, height: number, deltaX: number, deltaY: number): void;*/ + } + + export namespace PNG { + namespace sync { + function read(buffer: string|Buffer, options?: PNGOptions): PNG; + } + } +} From a6be18ec5dabbb85703077a5e86ca35d02dd0688 Mon Sep 17 00:00:00 2001 From: Keepertje Date: Thu, 8 Oct 2015 16:11:56 +0200 Subject: [PATCH 3/4] Use regexp in use --- express/express.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/express/express.d.ts b/express/express.d.ts index e2f6d5df21..523f8f7c6f 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -108,6 +108,8 @@ declare module "express" { use(path: string, handler: ErrorRequestHandler): T; use(path: string[], ...handler: RequestHandler[]): T; use(path: string[], handler: ErrorRequestHandler): T; + use(path: RegExp, ...handler: RequestHandler[]): T; + use(path: RegExp, handler: ErrorRequestHandler): T; } export function Router(options?: any): Router; From b62c244440a528298460bcd25d96dfde38e39f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elis=C3=A9e=20Maurer?= Date: Thu, 8 Oct 2015 22:32:44 +0200 Subject: [PATCH 4/4] Update pngjs2 definition to 2.0.0 --- pngjs2/pngjs2.d.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/pngjs2/pngjs2.d.ts b/pngjs2/pngjs2.d.ts index bc2e061ccc..e44dbfdd69 100644 --- a/pngjs2/pngjs2.d.ts +++ b/pngjs2/pngjs2.d.ts @@ -1,4 +1,4 @@ -// Type definitions for pngjs2 1.2.0 +// Type definitions for pngjs2 2.0.0 // Project: https://www.npmjs.com/package/pngjs2 // Definitions by: Elisée Maurer // Definitions: https://github.com/borisyankov/DefinitelyTyped @@ -50,12 +50,10 @@ declare module "pngjs2" { pipe(destination: fs.WriteStream): PNG; static bitblt(src: PNG, dst: PNG, srcX: number, srcY: number, - width: number, height: number, deltaX: number, deltaY: number): void; + width: number, height: number, deltaX: number, deltaY: number): void; - // This method's signature is wrong in 1.2.0, see https://github.com/lukeapage/pngjs2/pull/29 - // Use the static version in the meantime - /*bitblt(dst: PNG, srcX: number, srcY: number, - width: number, height: number, deltaX: number, deltaY: number): void;*/ + bitblt(dst: PNG, srcX: number, srcY: number, + width: number, height: number, deltaX: number, deltaY: number): PNG; } export namespace PNG {