From 64795f2f0f0b96d7bf95d1d485e11dbc6d6703d1 Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Sun, 3 Aug 2014 04:47:28 +0800 Subject: [PATCH 1/7] Added morgan definitions --- morgan/morgan-tests.ts | 29 +++++++++++++ morgan/morgan.d.ts | 93 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+) create mode 100644 morgan/morgan-tests.ts create mode 100644 morgan/morgan.d.ts diff --git a/morgan/morgan-tests.ts b/morgan/morgan-tests.ts new file mode 100644 index 000000000..00e67f875 --- /dev/null +++ b/morgan/morgan-tests.ts @@ -0,0 +1,29 @@ +/// +/** + * Created by staticfunction on 8/3/14. + */ + +import morgan = require('morgan'); + +// a pre-defined name +morgan('combined') +morgan('common') +morgan('short') +morgan('tiny') + +// a format string +morgan(':remote-addr :method :url') + +// a custom function +morgan(function (req, res) { + return req.method + ' ' + req.url +}) + +morgan('combined', { + buffer: true, + immediate: true, + skip: function (req, res) { return res.statusCode < 400 }, + stream: (str: string) => { + console.log(str); + } +}); diff --git a/morgan/morgan.d.ts b/morgan/morgan.d.ts new file mode 100644 index 000000000..b889bc7be --- /dev/null +++ b/morgan/morgan.d.ts @@ -0,0 +1,93 @@ +// Type definitions for morgan 1.2.2 +// Project: https://github.com/expressjs/morgan +// Definitions by: James Roland Cabresos +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +declare module "morgan" { + + import express = require('express'); + + module morgan { + + export function token(name: string, callback: (req: express.Request, res: express.Response) => T): express.RequestHandler; + + /*** + * Morgan accepts these properties in the options object. + */ + export interface Options { + + /*** + * Buffer duration before writing logs to the stream, defaults to false. When set to true, defaults to 1000 ms. + */ + buffer?: boolean; + + /*** + * Write log line on request instead of response. This means that a requests will be logged even if the server crashes, but data from the response cannot be logged (like the response code). + */ + immediate?: boolean; + + /*** + * Function to determine if logging is skipped, defaults to false. This function will be called as skip(req, res). + */ + skip?: (req: express.Request, res: express.Response) => boolean; + + /*** + * Output stream for writing log lines, defaults to process.stdout. + * @param str + */ + stream?: (str: string) => void; + } + } + + /*** + * Create a new morgan logger middleware function using the given format and options. The format argument may be a string of a predefined name (see below for the names), a string of a format string, or a function that will produce a log entry. + * @param format + * @param options + */ + function morgan(format: string, options?: morgan.Options): express.RequestHandler; + + /*** + * Standard Apache combined log output. + * :remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent" + * @param format + * @param options + */ + function morgan(format: 'combined', options?: morgan.Options): express.RequestHandler; + + /*** + * Standard Apache common log output. + * :remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] + * @param format + * @param options + */ + function morgan(format: 'common', options?: morgan.Options): express.RequestHandler; + + /*** + * Concise output colored by response status for development use. The :status token will be colored red for server error codes, yellow for client error codes, cyan for redirection codes, and uncolored for all other codes. + * :method :url :status :response-time ms - :res[content-length] + * @param format + * @param options + */ + function morgan(format: 'dev', options?: morgan.Options): express.RequestHandler; + + /*** + * Shorter than default, also including response time. + * :remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms + * @param format + * @param options + */ + function morgan(format: 'short', options?: morgan.Options): express.RequestHandler; + + /*** + * The minimal output. + * :method :url :status :res[content-length] - :response-time ms + * @param format + * @param options + */ + function morgan(format: 'tiny', options?: morgan.Options): express.RequestHandler; + + function morgan(custom: (req: express.Request, res: express.Response) => string): express.RequestHandler + + export = morgan; +} \ No newline at end of file From df1080e63a50158f3a315b9e9d938e27f45e2fb3 Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Mon, 4 Aug 2014 20:54:42 +0800 Subject: [PATCH 2/7] Added htmlparser2 definitions --- htmlparser2/htmlparser2.d.ts | 89 +++++++++++++++++++++++++++++++++ htmlparser2/htmlparser2tests.ts | 24 +++++++++ 2 files changed, 113 insertions(+) create mode 100644 htmlparser2/htmlparser2.d.ts create mode 100644 htmlparser2/htmlparser2tests.ts diff --git a/htmlparser2/htmlparser2.d.ts b/htmlparser2/htmlparser2.d.ts new file mode 100644 index 000000000..77fb0b983 --- /dev/null +++ b/htmlparser2/htmlparser2.d.ts @@ -0,0 +1,89 @@ +// Type definitions for htmlparser2 v3.7.x +// Project: https://github.com/fb55/htmlparser2/ +// Definitions by: James Roland Cabresos +// Definitions: https://github.com/borisyankov/DefinitelyTyped + + +declare module "htmlparser2" { + + export interface Handler { + onopentag?:(name:string, attribs:{[type:string]: string}) => void; + onopentagname?:(name:string) => void; + onattribute?:(name:string, value:string) => void; + ontext?:(text:string) => void; + onclosetag?: (text:string) => void; + onprocessinginstruction?:(name:string, data:string) => void; + oncomment?:(data:string) => void; + oncommentend?:() => void; + oncdatastart?:() => void; + oncdataend?:() => void; + onerror?:(error:Error) => void; + onreset?:() => void; + onend?:() => void; + } + + export interface Options { + + /*** + * Indicates whether special tags ("); +parser.end(); \ No newline at end of file From afc1fc3ed4679698884fae628d1b5214af683963 Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Mon, 4 Aug 2014 20:59:50 +0800 Subject: [PATCH 3/7] Added htmlparser2, morgan, and passport-facebook contributor --- CONTRIBUTORS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index af326634b..216b74568 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -124,6 +124,7 @@ All definitions files include a header with the author and editors, so at some p * [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee)) * [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov)) * [Html2Canvas.js](https://github.com/niklasvh/html2canvas/) (by [Richard Hepburn](https://github.com/rwhepburn)) +* [htmlparser2](https://github.com/fb55/htmlparser2/) (by [James Roland Cabresos](https://github.com/staticfunction)) * [Humane.js](http://wavded.github.com/humane-js/) (by [John Vrbanac](https://github.com/jmvrbanac)) * [i18next](http://i18next.com/) (by [Maarten Docter](https://github.com/mdocter)) * [iCheck](http://damirfoy.com/iCheck/) (by [Dániel Tar](https://github.com/qcz)) @@ -244,6 +245,7 @@ All definitions files include a header with the author and editors, so at some p * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield)) * [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee)) * [mongoose](http://mongoosejs.com/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) +* [morgan](hhttps://github.com/expressjs/morgan) (by [James Roland Cabresos](https://github.com/staticfunction/)) * [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz)) * [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov)) @@ -267,6 +269,7 @@ All definitions files include a header with the author and editors, so at some p * [OpenLayers](https://github.com/openlayers/openlayers) (by [Ilya Bolkhovsky](https://github.com/bolhovsky/)) * [Optimist](https://github.com/substack/node-optimist) (by [Carlos Ballesteros Velasco](https://github.com/soywiz)) * [Passport](http://passportjs.org/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) +* [passport-facebook](https://github.com/jaredhanson/passport-facebook) (by [James Roland Cabresos](https://github.com/staticfunction/)) * [passport-strategy](https://github.com/jaredhanson/passport-strategy) (by [Lior Mualem](https://github.com/liorm)) * [pathwatcher](http://atom.github.io/node-pathwatcher/) (by [vvakame](https://github.com/vvakame)) * [Parallel.js](https://github.com/adambom/parallel.js) (by [Josh Baldwin](https://github.com/jbaldwin)) From 9a0a71177653bda672905ba6605aa319877dcf8e Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Mon, 4 Aug 2014 21:02:17 +0800 Subject: [PATCH 4/7] fix a typo --- CONTRIBUTORS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 216b74568..8098540ed 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -245,7 +245,7 @@ All definitions files include a header with the author and editors, so at some p * [Moment.js](https://github.com/timrwood/moment) (by [Michael Lakerveld](https://github.com/Lakerfield)) * [MongoDB](http://mongodb.github.io/node-mongodb-native/) (from TypeScript samples, updated by [Niklas Mollenhauer](https://github.com/nikeee)) * [mongoose](http://mongoosejs.com/) (by [Hiroki Horiuchi](https://github.com/horiuchi/)) -* [morgan](hhttps://github.com/expressjs/morgan) (by [James Roland Cabresos](https://github.com/staticfunction/)) +* [morgan](https://github.com/expressjs/morgan/) (by [James Roland Cabresos](https://github.com/staticfunction/)) * [Mousetrap](http://craig.is/killing/mice) (by [Dániel Tar](https://github.com/qcz)) * [msgpack.js](https://github.com/uupaa/msgpack.js) (by [Shinya Mochizuki](https://github.com/enrapt-mochizuki)) * [Mustache.js](https://github.com/janl/mustache.js) (by [Boris Yankov](https://github.com/borisyankov)) From 8badcfa1b3483d78cffe8740ddf974677a94b7e4 Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Wed, 6 Aug 2014 21:33:04 +0800 Subject: [PATCH 5/7] merge new contributors --- CONTRIBUTORS.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 330bda381..1b2eda33d 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -125,11 +125,8 @@ All definitions files include a header with the author and editors, so at some p * [highlight.js](https://github.com/isagalaev/highlight.js) (by [Niklas Mollenhauer](https://github.com/nikeee)) * [History.js](https://github.com/browserstate/history.js) (by [Boris Yankov](https://github.com/borisyankov)) * [Html2Canvas.js](https://github.com/niklasvh/html2canvas/) (by [Richard Hepburn](https://github.com/rwhepburn)) -<<<<<<< HEAD * [htmlparser2](https://github.com/fb55/htmlparser2/) (by [James Roland Cabresos](https://github.com/staticfunction)) -======= * [http-string-parser](https://github.com/apiaryio/http-string-parser) (by [MIZUNE Pine](https://github.com/pine613)) ->>>>>>> upstream/master * [Humane.js](http://wavded.github.com/humane-js/) (by [John Vrbanac](https://github.com/jmvrbanac)) * [i18next](http://i18next.com/) (by [Maarten Docter](https://github.com/mdocter)) * [iCheck](http://damirfoy.com/iCheck/) (by [Dániel Tar](https://github.com/qcz)) From 5f62479f18b6b2d80e8e213d5afca562a64d735f Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Thu, 7 Aug 2014 21:10:37 +0800 Subject: [PATCH 6/7] Rename htmlparser2tests.ts to htmlparser2-tests.ts --- htmlparser2/{htmlparser2tests.ts => htmlparser2-tests.ts} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename htmlparser2/{htmlparser2tests.ts => htmlparser2-tests.ts} (97%) diff --git a/htmlparser2/htmlparser2tests.ts b/htmlparser2/htmlparser2-tests.ts similarity index 97% rename from htmlparser2/htmlparser2tests.ts rename to htmlparser2/htmlparser2-tests.ts index 7ff887e65..c002da0e2 100644 --- a/htmlparser2/htmlparser2tests.ts +++ b/htmlparser2/htmlparser2-tests.ts @@ -21,4 +21,4 @@ var parser = new htmlparser.Parser({ }); parser.write("Xyz "); -parser.end(); \ No newline at end of file +parser.end(); From cc05933bbc0b8a7994ff743a33805218226ed5bc Mon Sep 17 00:00:00 2001 From: James Roland Cabresos Date: Fri, 8 Aug 2014 10:22:24 +0800 Subject: [PATCH 7/7] fix htmlparser tests --- htmlparser2/htmlparser2-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htmlparser2/htmlparser2-tests.ts b/htmlparser2/htmlparser2-tests.ts index c002da0e2..53f6ee2aa 100644 --- a/htmlparser2/htmlparser2-tests.ts +++ b/htmlparser2/htmlparser2-tests.ts @@ -6,7 +6,7 @@ import htmlparser = require("htmlparser2"); var parser = new htmlparser.Parser({ onopentag: (name:string, attribs:{[s:string]:string}) => { - if(name === "script" && attribs.type === "text/javascript"){ + if(name === "script" && attribs['type'] === "text/javascript"){ console.log("JS! Hooray!"); } },