Merge pull request #2610 from staticfunction/master

Morgan definitions
This commit is contained in:
Masahiro Wakame
2014-08-09 10:30:58 +09:00
5 changed files with 238 additions and 0 deletions
+3
View File
@@ -125,6 +125,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))
* [http-string-parser](https://github.com/apiaryio/http-string-parser) (by [MIZUNE Pine](https://github.com/pine613))
* [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))
@@ -247,6 +248,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](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))
@@ -272,6 +274,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))
+24
View File
@@ -0,0 +1,24 @@
/// <reference path="htmlparser2.d.ts"/>
/**
* Created by staticfunction on 8/4/14.
*/
import htmlparser = require("htmlparser2");
var parser = new htmlparser.Parser({
onopentag: (name:string, attribs:{[s:string]:string}) => {
if(name === "script" && attribs['type'] === "text/javascript"){
console.log("JS! Hooray!");
}
},
ontext: (text: string) => {
console.log("-->", text);
},
onclosetag: (tagname:string) => {
if(tagname === "script"){
console.log("That's it?!");
}
}
});
parser.write("Xyz <script type='text/javascript'>var foo = '<<bar>>';</script>");
parser.end();
+89
View File
@@ -0,0 +1,89 @@
// Type definitions for htmlparser2 v3.7.x
// Project: https://github.com/fb55/htmlparser2/
// Definitions by: James Roland Cabresos <https://github.com/staticfunction/>
// 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 (<script> and <style>) should get special treatment
* and if "empty" tags (eg. <br>) can have children. If false, the content of special tags
* will be text only. For feeds and other XML content (documents that don't consist of HTML),
* set this to true. Default: false.
*/
xmlMode?:boolean;
/***
* If set to true, entities within the document will be decoded. Defaults to false.
*/
decodeEntities?:boolean;
/***
* If set to true, all tags will be lowercased. If xmlMode is disabled, this defaults to true.
*/
lowerCaseTags?:boolean;
/***
* If set to true, all attribute names will be lowercased. This has noticeable impact on speed, so it defaults to false.
*/
lowerCaseAttributeNames?:boolean;
/***
* If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
* NOTE: If xmlMode is set to true then CDATA sections will always be recognized as text.
*/
recognizeCDATA?:boolean;
/***
* If set to true, self-closing tags will trigger the onclosetag event even if xmlMode is not set to true.
* NOTE: If xmlMode is set to true then self-closing tags will always be recognized.
*/
recognizeSelfClosing?:boolean;
}
export class Parser {
constructor(handler: Handler);
/***
* Parses a chunk of data and calls the corresponding callbacks.
* @param input
*/
write(input:string):void;
/***
* Parses the end of the buffer and clears the stack, calls onend.
*/
end():void;
/***
* Resets the parser, parses the data & calls end.
* @param input
*/
parseComplete(input:string):void;
/***
* Resets buffer & stack, calls onreset.
*/
reset():void;
}
}
+29
View File
@@ -0,0 +1,29 @@
/// <reference path="morgan.d.ts"/>
/**
* 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);
}
});
+93
View File
@@ -0,0 +1,93 @@
// Type definitions for morgan 1.2.2
// Project: https://github.com/expressjs/morgan
// Definitions by: James Roland Cabresos <https://github.com/staticfunction>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../express/express.d.ts" />
declare module "morgan" {
import express = require('express');
module morgan {
export function token<T>(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;
}