mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-12 02:42:48 +00:00
Added all files
This commit is contained in:
118
node_modules/morgan/HISTORY.md
generated
vendored
Normal file
118
node_modules/morgan/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,118 @@
|
||||
1.5.3 / 2015-05-10
|
||||
==================
|
||||
|
||||
* deps: basic-auth@~1.0.1
|
||||
* deps: debug@~2.2.0
|
||||
- deps: ms@0.7.1
|
||||
* deps: depd@~1.0.1
|
||||
* deps: on-finished@~2.2.1
|
||||
- Fix `isFinished(req)` when data buffered
|
||||
|
||||
1.5.2 / 2015-03-15
|
||||
==================
|
||||
|
||||
* deps: debug@~2.1.3
|
||||
- Fix high intensity foreground color for bold
|
||||
- deps: ms@0.7.0
|
||||
|
||||
1.5.1 / 2014-12-31
|
||||
==================
|
||||
|
||||
* deps: debug@~2.1.1
|
||||
* deps: on-finished@~2.2.0
|
||||
|
||||
1.5.0 / 2014-11-06
|
||||
==================
|
||||
|
||||
* Add multiple date formats
|
||||
- `clf` for the common log format
|
||||
- `iso` for the common ISO 8601 date time format
|
||||
- `web` for the common RFC 1123 date time format
|
||||
* Deprecate `buffer` option
|
||||
* Fix date format in `common` and `combined` formats
|
||||
* Fix token arguments to accept values with `"`
|
||||
|
||||
1.4.1 / 2014-10-22
|
||||
==================
|
||||
|
||||
* deps: on-finished@~2.1.1
|
||||
- Fix handling of pipelined requests
|
||||
|
||||
1.4.0 / 2014-10-16
|
||||
==================
|
||||
|
||||
* Add `debug` messages
|
||||
* deps: depd@~1.0.0
|
||||
|
||||
1.3.2 / 2014-09-27
|
||||
==================
|
||||
|
||||
* Fix `req.ip` integration when `immediate: false`
|
||||
|
||||
1.3.1 / 2014-09-14
|
||||
==================
|
||||
|
||||
* Remove un-used `bytes` dependency
|
||||
* deps: depd@0.4.5
|
||||
|
||||
1.3.0 / 2014-09-01
|
||||
==================
|
||||
|
||||
* Assert if `format` is not a function or string
|
||||
|
||||
1.2.3 / 2014-08-16
|
||||
==================
|
||||
|
||||
* deps: on-finished@2.1.0
|
||||
|
||||
1.2.2 / 2014-07-27
|
||||
==================
|
||||
|
||||
* deps: depd@0.4.4
|
||||
- Work-around v8 generating empty stack traces
|
||||
|
||||
1.2.1 / 2014-07-26
|
||||
==================
|
||||
|
||||
* deps: depd@0.4.3
|
||||
- Fix exception when global `Error.stackTraceLimit` is too low
|
||||
|
||||
1.2.0 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Add `:remote-user` token
|
||||
* Add `combined` log format
|
||||
* Add `common` log format
|
||||
* Add `morgan(format, options)` function signature
|
||||
* Deprecate `default` format -- use `combined` format instead
|
||||
* Deprecate not providing a format
|
||||
* Remove non-standard grey color from `dev` format
|
||||
|
||||
1.1.1 / 2014-05-20
|
||||
==================
|
||||
|
||||
* simplify method to get remote address
|
||||
|
||||
1.1.0 / 2014-05-18
|
||||
==================
|
||||
|
||||
* "dev" format will use same tokens as other formats
|
||||
* `:response-time` token is now empty when immediate used
|
||||
* `:response-time` token is now monotonic
|
||||
* `:response-time` token has precision to 1 μs
|
||||
* fix `:status` + immediate output in node.js 0.8
|
||||
* improve `buffer` option to prevent indefinite event loop holding
|
||||
* deps: bytes@1.0.0
|
||||
- add negative support
|
||||
|
||||
1.0.1 / 2014-05-04
|
||||
==================
|
||||
|
||||
* Make buffer unique per morgan instance
|
||||
* deps: bytes@0.3.0
|
||||
* added terabyte support
|
||||
|
||||
1.0.0 / 2014-02-08
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
23
node_modules/morgan/LICENSE
generated
vendored
Normal file
23
node_modules/morgan/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
|
||||
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
304
node_modules/morgan/README.md
generated
vendored
Normal file
304
node_modules/morgan/README.md
generated
vendored
Normal file
@@ -0,0 +1,304 @@
|
||||
# morgan
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
[![Gratipay][gratipay-image]][gratipay-url]
|
||||
|
||||
HTTP request logger middleware for node.js
|
||||
|
||||
> Named after [Dexter](http://en.wikipedia.org/wiki/Dexter_Morgan), a show you should not watch until completion.
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var morgan = require('morgan')
|
||||
```
|
||||
|
||||
### morgan(format, options)
|
||||
|
||||
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.
|
||||
|
||||
#### Options
|
||||
|
||||
Morgan accepts these properties in the options object.
|
||||
|
||||
#### immediate
|
||||
|
||||
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 (like the
|
||||
response code, content length, etc.) cannot be logged_.
|
||||
|
||||
##### skip
|
||||
|
||||
Function to determine if logging is skipped, defaults to `false`. This function
|
||||
will be called as `skip(req, res)`.
|
||||
|
||||
```js
|
||||
// EXAMPLE: only log error responses
|
||||
morgan('combined', {
|
||||
skip: function (req, res) { return res.statusCode < 400 }
|
||||
})
|
||||
```
|
||||
|
||||
##### stream
|
||||
|
||||
Output stream for writing log lines, defaults to `process.stdout`.
|
||||
|
||||
#### Predefined Formats
|
||||
|
||||
There are various pre-defined formats provided:
|
||||
|
||||
##### combined
|
||||
|
||||
Standard Apache combined log output.
|
||||
|
||||
```
|
||||
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"
|
||||
```
|
||||
|
||||
##### common
|
||||
|
||||
Standard Apache common log output.
|
||||
|
||||
```
|
||||
:remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length]
|
||||
```
|
||||
|
||||
##### dev
|
||||
|
||||
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]
|
||||
```
|
||||
|
||||
##### short
|
||||
|
||||
Shorter than default, also including response time.
|
||||
|
||||
```
|
||||
:remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms
|
||||
```
|
||||
|
||||
##### tiny
|
||||
|
||||
The minimal output.
|
||||
|
||||
```
|
||||
:method :url :status :res[content-length] - :response-time ms
|
||||
```
|
||||
|
||||
#### Tokens
|
||||
|
||||
##### Creating new tokens
|
||||
|
||||
To define a token, simply invoke `morgan.token()` with the name and a callback function. This callback function is expected to return a string value. The value returned is then available as ":type" in this case:
|
||||
```js
|
||||
morgan.token('type', function(req, res){ return req.headers['content-type']; })
|
||||
```
|
||||
|
||||
Calling `morgan.token()` using the same name as an existing token will overwrite that token definition.
|
||||
|
||||
##### :date[format]
|
||||
|
||||
The current date and time in UTC. The available formats are:
|
||||
|
||||
- `clf` for the common log format (`"10/Oct/2000:13:55:36 +0000"`)
|
||||
- `iso` for the common ISO 8601 date time format (`2000-10-10T13:55:36.000Z`)
|
||||
- `web` for the common RFC 1123 date time format (`Tue, 10 Oct 2000 13:55:36 GMT`)
|
||||
|
||||
If no format is given, then the default is `web`.
|
||||
|
||||
##### :http-version
|
||||
|
||||
The HTTP version of the request.
|
||||
|
||||
##### :method
|
||||
|
||||
The HTTP version of the request.
|
||||
|
||||
##### :referrer
|
||||
|
||||
The Referrer header of the request. This will use the standard mis-spelled Referer header if exists, otherwise Referrer.
|
||||
|
||||
##### :remote-addr
|
||||
|
||||
The remote address of the request. This will use `req.ip`, otherwise the standard `req.connection.remoteAddress` value (socket address).
|
||||
|
||||
##### :remote-user
|
||||
|
||||
The user authenticated as part of Basic auth for the request.
|
||||
|
||||
##### :req[header]
|
||||
|
||||
The given `header` of the request.
|
||||
|
||||
##### :res[header]
|
||||
|
||||
The given `header` of the response.
|
||||
|
||||
##### :response-time
|
||||
|
||||
The time between the request coming into `morgan` and when the response headers are written, in milliseconds.
|
||||
|
||||
##### :status
|
||||
|
||||
The status code of the response.
|
||||
|
||||
##### :url
|
||||
|
||||
The URL of the request. This will use `req.originalUrl` if exists, otherwise `req.url`.
|
||||
|
||||
##### :user-agent
|
||||
|
||||
The contents of the User-Agent header of the request.
|
||||
|
||||
## Examples
|
||||
|
||||
### express/connect
|
||||
|
||||
Simple app that will log all request in the Apache combined format to STDOUT
|
||||
|
||||
```js
|
||||
var express = require('express')
|
||||
var morgan = require('morgan')
|
||||
|
||||
var app = express()
|
||||
|
||||
app.use(morgan('combined'))
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.send('hello, world!')
|
||||
})
|
||||
```
|
||||
|
||||
### vanilla http server
|
||||
|
||||
Simple app that will log all request in the Apache combined format to STDOUT
|
||||
|
||||
```js
|
||||
var finalhandler = require('finalhandler')
|
||||
var http = require('http')
|
||||
var morgan = require('morgan')
|
||||
|
||||
// create "middleware"
|
||||
var logger = morgan('combined')
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
var done = finalhandler(req, res)
|
||||
logger(req, res, function (err) {
|
||||
if (err) return done(err)
|
||||
|
||||
// respond to request
|
||||
res.setHeader('content-type', 'text/plain')
|
||||
res.end('hello, world!')
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
### write logs to a file
|
||||
|
||||
#### single file
|
||||
|
||||
Simple app that will log all requests in the Apache combined format to the file
|
||||
`access.log`.
|
||||
|
||||
```js
|
||||
var express = require('express')
|
||||
var fs = require('fs')
|
||||
var morgan = require('morgan')
|
||||
|
||||
var app = express()
|
||||
|
||||
// create a write stream (in append mode)
|
||||
var accessLogStream = fs.createWriteStream(__dirname + '/access.log', {flags: 'a'})
|
||||
|
||||
// setup the logger
|
||||
app.use(morgan('combined', {stream: accessLogStream}))
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.send('hello, world!')
|
||||
})
|
||||
```
|
||||
|
||||
#### log file rotation
|
||||
|
||||
Simple app that will log all requests in the Apache combined format to one log
|
||||
file per date in the `log/` directory using the
|
||||
[file-stream-rotator module](https://www.npmjs.com/package/file-stream-rotator).
|
||||
|
||||
```js
|
||||
var FileStreamRotator = require('file-stream-rotator')
|
||||
var express = require('express')
|
||||
var fs = require('fs')
|
||||
var morgan = require('morgan')
|
||||
|
||||
var app = express()
|
||||
var logDirectory = __dirname + '/log'
|
||||
|
||||
// ensure log directory exists
|
||||
fs.existsSync(logDirectory) || fs.mkdirSync(logDirectory)
|
||||
|
||||
// create a rotating write stream
|
||||
var accessLogStream = FileStreamRotator.getStream({
|
||||
filename: logDirectory + '/access-%DATE%.log',
|
||||
frequency: 'daily',
|
||||
verbose: false
|
||||
})
|
||||
|
||||
// setup the logger
|
||||
app.use(morgan('combined', {stream: accessLogStream}))
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.send('hello, world!')
|
||||
})
|
||||
```
|
||||
|
||||
### use custom token formats
|
||||
|
||||
Sample app that will use custom token formats. This adds an ID to all requests and displays it using the `:id` token.
|
||||
|
||||
```js
|
||||
var express = require('express')
|
||||
var morgan = require('morgan')
|
||||
var uuid = require('node-uuid')
|
||||
|
||||
morgan.token('id', function getId(req) {
|
||||
return req.id
|
||||
})
|
||||
|
||||
var app = express()
|
||||
|
||||
app.use(assignId)
|
||||
app.use(morgan(':id :method :url :response-time'))
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
res.send('hello, world!')
|
||||
})
|
||||
|
||||
function assignId(req, res, next) {
|
||||
req.id = uuid.v4()
|
||||
next()
|
||||
}
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/morgan.svg
|
||||
[npm-url]: https://npmjs.org/package/morgan
|
||||
[travis-image]: https://img.shields.io/travis/expressjs/morgan/master.svg
|
||||
[travis-url]: https://travis-ci.org/expressjs/morgan
|
||||
[coveralls-image]: https://img.shields.io/coveralls/expressjs/morgan/master.svg
|
||||
[coveralls-url]: https://coveralls.io/r/expressjs/morgan?branch=master
|
||||
[downloads-image]: https://img.shields.io/npm/dm/morgan.svg
|
||||
[downloads-url]: https://npmjs.org/package/morgan
|
||||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
|
||||
[gratipay-url]: https://www.gratipay.com/dougwilson/
|
||||
403
node_modules/morgan/index.js
generated
vendored
Normal file
403
node_modules/morgan/index.js
generated
vendored
Normal file
@@ -0,0 +1,403 @@
|
||||
/*!
|
||||
* morgan
|
||||
* Copyright(c) 2010 Sencha Inc.
|
||||
* Copyright(c) 2011 TJ Holowaychuk
|
||||
* Copyright(c) 2014 Jonathan Ong
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var auth = require('basic-auth')
|
||||
var debug = require('debug')('morgan')
|
||||
var deprecate = require('depd')('morgan')
|
||||
var onFinished = require('on-finished')
|
||||
|
||||
/**
|
||||
* Array of CLF month names.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var clfmonth = [
|
||||
'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
|
||||
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'
|
||||
]
|
||||
|
||||
/**
|
||||
* Default log buffer duration.
|
||||
* @private
|
||||
*/
|
||||
|
||||
var defaultBufferDuration = 1000;
|
||||
|
||||
/**
|
||||
* Create a logger middleware.
|
||||
*
|
||||
* @public
|
||||
* @param {String|Function} format
|
||||
* @param {Object} [options]
|
||||
* @return {Function} middleware
|
||||
*/
|
||||
|
||||
exports = module.exports = function morgan(format, options) {
|
||||
if (typeof format === 'object') {
|
||||
options = format
|
||||
format = options.format || 'default'
|
||||
|
||||
// smart deprecation message
|
||||
deprecate('morgan(options): use morgan(' + (typeof format === 'string' ? JSON.stringify(format) : 'format') + ', options) instead')
|
||||
}
|
||||
|
||||
if (format === undefined) {
|
||||
deprecate('undefined format: specify a format')
|
||||
}
|
||||
|
||||
options = options || {}
|
||||
|
||||
// output on request instead of response
|
||||
var immediate = options.immediate;
|
||||
|
||||
// check if log entry should be skipped
|
||||
var skip = options.skip || function () { return false; };
|
||||
|
||||
// format function
|
||||
var fmt = compile(exports[format] || format || exports.default)
|
||||
|
||||
// steam
|
||||
var buffer = options.buffer
|
||||
var stream = options.stream || process.stdout
|
||||
|
||||
// buffering support
|
||||
if (buffer) {
|
||||
deprecate('buffer option')
|
||||
|
||||
var realStream = stream
|
||||
var buf = []
|
||||
var timer = null
|
||||
var interval = 'number' == typeof buffer
|
||||
? buffer
|
||||
: defaultBufferDuration
|
||||
|
||||
// flush function
|
||||
var flush = function(){
|
||||
timer = null
|
||||
|
||||
if (buf.length) {
|
||||
realStream.write(buf.join(''));
|
||||
buf.length = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// swap the stream
|
||||
stream = {
|
||||
write: function(str){
|
||||
if (timer === null) {
|
||||
timer = setTimeout(flush, interval)
|
||||
}
|
||||
|
||||
buf.push(str);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return function logger(req, res, next) {
|
||||
req._startAt = process.hrtime();
|
||||
req._startTime = new Date;
|
||||
req._remoteAddress = getip(req);
|
||||
|
||||
function logRequest(){
|
||||
if (skip(req, res)) {
|
||||
debug('skip request')
|
||||
return
|
||||
}
|
||||
|
||||
var line = fmt(exports, req, res)
|
||||
|
||||
if (null == line) {
|
||||
debug('skip line')
|
||||
return
|
||||
}
|
||||
|
||||
debug('log request')
|
||||
stream.write(line + '\n')
|
||||
};
|
||||
|
||||
// immediate
|
||||
if (immediate) {
|
||||
logRequest();
|
||||
} else {
|
||||
onFinished(res, logRequest)
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Compile `format` into a function.
|
||||
*
|
||||
* @private
|
||||
* @param {Function|String} format
|
||||
* @return {Function}
|
||||
*/
|
||||
|
||||
function compile(format) {
|
||||
if (typeof format === 'function') {
|
||||
// already compiled
|
||||
return format
|
||||
}
|
||||
|
||||
if (typeof format !== 'string') {
|
||||
throw new TypeError('argument format must be a function or string')
|
||||
}
|
||||
|
||||
var fmt = format.replace(/"/g, '\\"')
|
||||
var js = ' return "' + fmt.replace(/:([-\w]{2,})(?:\[([^\]]+)\])?/g, function(_, name, arg){
|
||||
return '"\n + (tokens["' + name + '"](req, res, ' + String(JSON.stringify(arg)) + ') || "-") + "';
|
||||
}) + '";'
|
||||
|
||||
return new Function('tokens, req, res', js);
|
||||
};
|
||||
|
||||
/**
|
||||
* Define a token function with the given `name`,
|
||||
* and callback `fn(req, res)`.
|
||||
*
|
||||
* @public
|
||||
* @param {String} name
|
||||
* @param {Function} fn
|
||||
* @return {Object} exports for chaining
|
||||
*/
|
||||
|
||||
exports.token = function(name, fn) {
|
||||
exports[name] = fn;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Define a `fmt` with the given `name`.
|
||||
*
|
||||
* @public
|
||||
* @param {String} name
|
||||
* @param {String|Function} fmt
|
||||
* @return {Object} exports for chaining
|
||||
*/
|
||||
|
||||
exports.format = function(name, fmt){
|
||||
exports[name] = fmt;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Apache combined log format.
|
||||
*/
|
||||
|
||||
exports.format('combined', ':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"')
|
||||
|
||||
/**
|
||||
* Apache common log format.
|
||||
*/
|
||||
|
||||
exports.format('common', ':remote-addr - :remote-user [:date[clf]] ":method :url HTTP/:http-version" :status :res[content-length]')
|
||||
|
||||
/**
|
||||
* Default format.
|
||||
*/
|
||||
|
||||
exports.format('default', ':remote-addr - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"');
|
||||
deprecate.property(exports, 'default', 'default format: use combined format')
|
||||
|
||||
/**
|
||||
* Short format.
|
||||
*/
|
||||
|
||||
exports.format('short', ':remote-addr :remote-user :method :url HTTP/:http-version :status :res[content-length] - :response-time ms');
|
||||
|
||||
/**
|
||||
* Tiny format.
|
||||
*/
|
||||
|
||||
exports.format('tiny', ':method :url :status :res[content-length] - :response-time ms');
|
||||
|
||||
/**
|
||||
* dev (colored)
|
||||
*/
|
||||
|
||||
exports.format('dev', function(tokens, req, res){
|
||||
var color = 32; // green
|
||||
var status = res.statusCode;
|
||||
|
||||
if (status >= 500) color = 31; // red
|
||||
else if (status >= 400) color = 33; // yellow
|
||||
else if (status >= 300) color = 36; // cyan
|
||||
|
||||
var fn = compile('\x1b[0m:method :url \x1b[' + color + 'm:status \x1b[0m:response-time ms - :res[content-length]\x1b[0m');
|
||||
|
||||
return fn(tokens, req, res);
|
||||
});
|
||||
|
||||
/**
|
||||
* request url
|
||||
*/
|
||||
|
||||
exports.token('url', function(req){
|
||||
return req.originalUrl || req.url;
|
||||
});
|
||||
|
||||
/**
|
||||
* request method
|
||||
*/
|
||||
|
||||
exports.token('method', function(req){
|
||||
return req.method;
|
||||
});
|
||||
|
||||
/**
|
||||
* response time in milliseconds
|
||||
*/
|
||||
|
||||
exports.token('response-time', function(req, res){
|
||||
if (!res._header || !req._startAt) return '';
|
||||
var diff = process.hrtime(req._startAt);
|
||||
var ms = diff[0] * 1e3 + diff[1] * 1e-6;
|
||||
return ms.toFixed(3);
|
||||
});
|
||||
|
||||
/**
|
||||
* current date
|
||||
*/
|
||||
|
||||
exports.token('date', function(req, res, format){
|
||||
format = format || 'web'
|
||||
|
||||
var date = new Date()
|
||||
|
||||
switch (format) {
|
||||
case 'clf':
|
||||
return clfdate(date)
|
||||
case 'iso':
|
||||
return date.toISOString()
|
||||
case 'web':
|
||||
return date.toUTCString()
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* response status code
|
||||
*/
|
||||
|
||||
exports.token('status', function(req, res){
|
||||
return res._header ? res.statusCode : null;
|
||||
});
|
||||
|
||||
/**
|
||||
* normalized referrer
|
||||
*/
|
||||
|
||||
exports.token('referrer', function(req){
|
||||
return req.headers['referer'] || req.headers['referrer'];
|
||||
});
|
||||
|
||||
/**
|
||||
* remote address
|
||||
*/
|
||||
|
||||
exports.token('remote-addr', getip);
|
||||
|
||||
/**
|
||||
* remote user
|
||||
*/
|
||||
|
||||
exports.token('remote-user', function (req) {
|
||||
var creds = auth(req)
|
||||
var user = (creds && creds.name) || '-'
|
||||
return user;
|
||||
})
|
||||
|
||||
/**
|
||||
* HTTP version
|
||||
*/
|
||||
|
||||
exports.token('http-version', function(req){
|
||||
return req.httpVersionMajor + '.' + req.httpVersionMinor;
|
||||
});
|
||||
|
||||
/**
|
||||
* UA string
|
||||
*/
|
||||
|
||||
exports.token('user-agent', function(req){
|
||||
return req.headers['user-agent'];
|
||||
});
|
||||
|
||||
/**
|
||||
* request header
|
||||
*/
|
||||
|
||||
exports.token('req', function(req, res, field){
|
||||
return req.headers[field.toLowerCase()];
|
||||
});
|
||||
|
||||
/**
|
||||
* response header
|
||||
*/
|
||||
|
||||
exports.token('res', function(req, res, field){
|
||||
return (res._headers || {})[field.toLowerCase()];
|
||||
});
|
||||
|
||||
/**
|
||||
* Format a Date in the common log format.
|
||||
*
|
||||
* @private
|
||||
* @param {Date} dateTime
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
function clfdate(dateTime) {
|
||||
var date = dateTime.getUTCDate()
|
||||
var hour = dateTime.getUTCHours()
|
||||
var mins = dateTime.getUTCMinutes()
|
||||
var secs = dateTime.getUTCSeconds()
|
||||
var year = dateTime.getUTCFullYear()
|
||||
|
||||
var month = clfmonth[dateTime.getUTCMonth()]
|
||||
|
||||
return pad2(date) + '/' + month + '/' + year
|
||||
+ ':' + pad2(hour) + ':' + pad2(mins) + ':' + pad2(secs)
|
||||
+ ' +0000'
|
||||
}
|
||||
|
||||
/**
|
||||
* Get request IP address.
|
||||
*
|
||||
* @private
|
||||
* @param {IncomingMessage} req
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
function getip(req) {
|
||||
return req.ip
|
||||
|| req._remoteAddress
|
||||
|| (req.connection && req.connection.remoteAddress)
|
||||
|| undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pad number to two digits.
|
||||
*
|
||||
* @private
|
||||
* @param {number} num
|
||||
* @return {string}
|
||||
*/
|
||||
|
||||
function pad2(num) {
|
||||
var str = String(num)
|
||||
|
||||
return (str.length === 1 ? '0' : '')
|
||||
+ str
|
||||
}
|
||||
24
node_modules/morgan/node_modules/basic-auth/HISTORY.md
generated
vendored
Normal file
24
node_modules/morgan/node_modules/basic-auth/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
1.0.2 / 2015-06-12
|
||||
==================
|
||||
|
||||
* Improve error message when `req` argument missing
|
||||
* perf: enable strict mode
|
||||
* perf: hoist regular expression
|
||||
* perf: parse with regular expressions
|
||||
* perf: remove argument reassignment
|
||||
|
||||
1.0.1 / 2015-05-04
|
||||
==================
|
||||
|
||||
* Update readme
|
||||
|
||||
1.0.0 / 2014-07-01
|
||||
==================
|
||||
|
||||
* Support empty password
|
||||
* Support empty username
|
||||
|
||||
0.0.1 / 2013-11-30
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
24
node_modules/morgan/node_modules/basic-auth/LICENSE
generated
vendored
Normal file
24
node_modules/morgan/node_modules/basic-auth/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013 TJ Holowaychuk
|
||||
Copyright (c) 2014 Jonathan Ong <me@jongleberry.com>
|
||||
Copyright (c) 2015 Douglas Christopher Wilson <doug@somethingdoug.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
78
node_modules/morgan/node_modules/basic-auth/README.md
generated
vendored
Normal file
78
node_modules/morgan/node_modules/basic-auth/README.md
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
# basic-auth
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Node.js Version][node-version-image]][node-version-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
|
||||
Generic basic auth Authorization header field parser for whatever.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ npm install basic-auth
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var auth = require('basic-auth')
|
||||
```
|
||||
|
||||
### auth(req)
|
||||
|
||||
Get the basic auth credentials from the given request. The `Authorization`
|
||||
header is parsed and if the header is invalid, `undefined` is returned,
|
||||
otherwise an object with `name` and `pass` properties.
|
||||
|
||||
## Example
|
||||
|
||||
Pass a node request or koa Context object to the module exported. If
|
||||
parsing fails `undefined` is returned, otherwise an object with
|
||||
`.name` and `.pass`.
|
||||
|
||||
```js
|
||||
var auth = require('basic-auth');
|
||||
var user = auth(req);
|
||||
// => { name: 'something', pass: 'whatever' }
|
||||
|
||||
```
|
||||
|
||||
### With vanilla node.js http server
|
||||
|
||||
```js
|
||||
var http = require('http')
|
||||
var auth = require('basic-auth')
|
||||
|
||||
// Create server
|
||||
var server = http.createServer(function (req, res) {
|
||||
var credentials = auth(req)
|
||||
|
||||
if (!credentials || credentials.name !== 'john' || credentials.pass !== 'secret') {
|
||||
res.statusCode = 401
|
||||
res.setHeader('WWW-Authenticate', 'Basic realm="example"')
|
||||
res.end('Access denied')
|
||||
} else {
|
||||
res.end('Access granted')
|
||||
}
|
||||
})
|
||||
|
||||
// Listen
|
||||
server.listen(3000)
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/basic-auth.svg
|
||||
[npm-url]: https://npmjs.org/package/basic-auth
|
||||
[node-version-image]: https://img.shields.io/node/v/basic-auth.svg
|
||||
[node-version-url]: http://nodejs.org/download/
|
||||
[travis-image]: https://img.shields.io/travis/jshttp/basic-auth/master.svg
|
||||
[travis-url]: https://travis-ci.org/jshttp/basic-auth
|
||||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/basic-auth/master.svg
|
||||
[coveralls-url]: https://coveralls.io/r/jshttp/basic-auth?branch=master
|
||||
[downloads-image]: https://img.shields.io/npm/dm/basic-auth.svg
|
||||
[downloads-url]: https://npmjs.org/package/basic-auth
|
||||
92
node_modules/morgan/node_modules/basic-auth/index.js
generated
vendored
Normal file
92
node_modules/morgan/node_modules/basic-auth/index.js
generated
vendored
Normal file
@@ -0,0 +1,92 @@
|
||||
/*!
|
||||
* morgan
|
||||
* Copyright(c) 2013 TJ Holowaychuk
|
||||
* Copyright(c) 2014 Jonathan Ong
|
||||
* Copyright(c) 2015 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
'use strict'
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
* @public
|
||||
*/
|
||||
|
||||
module.exports = auth
|
||||
|
||||
/**
|
||||
* RegExp for basic auth credentials
|
||||
*
|
||||
* credentials = auth-scheme 1*SP token68
|
||||
* auth-scheme = "Basic" ; case insensitive
|
||||
* token68 = 1*( ALPHA / DIGIT / "-" / "." / "_" / "~" / "+" / "/" ) *"="
|
||||
* @private
|
||||
*/
|
||||
|
||||
var credentialsRegExp = /^ *(?:[Bb][Aa][Ss][Ii][Cc]) +([A-Za-z0-9\-\._~\+\/]+=*) *$/
|
||||
|
||||
/**
|
||||
* RegExp for basic auth user/pass
|
||||
*
|
||||
* user-pass = userid ":" password
|
||||
* userid = *<TEXT excluding ":">
|
||||
* password = *TEXT
|
||||
* @private
|
||||
*/
|
||||
|
||||
var userPassRegExp = /^([^:]*):(.*)$/
|
||||
|
||||
/**
|
||||
* Parse the Authorization header field of a request.
|
||||
*
|
||||
* @param {object} req
|
||||
* @return {object} with .name and .pass
|
||||
* @public
|
||||
*/
|
||||
|
||||
function auth(req) {
|
||||
if (!req) {
|
||||
throw new TypeError('argument req is required')
|
||||
}
|
||||
|
||||
// get header
|
||||
var header = (req.req || req).headers.authorization
|
||||
|
||||
// parse header
|
||||
var header = req.headers.authorization
|
||||
var match = credentialsRegExp.exec(header || '')
|
||||
|
||||
if (!match) {
|
||||
return
|
||||
}
|
||||
|
||||
// decode user pass
|
||||
var userPass = userPassRegExp.exec(decodeBase64(match[1]))
|
||||
|
||||
if (!userPass) {
|
||||
return
|
||||
}
|
||||
|
||||
// return credentials object
|
||||
return new Credentials(userPass[1], userPass[2])
|
||||
}
|
||||
|
||||
/**
|
||||
* Decode base64 string.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function decodeBase64(str) {
|
||||
return new Buffer(str, 'base64').toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Object to represent user credentials.
|
||||
* @private
|
||||
*/
|
||||
|
||||
function Credentials(name, pass) {
|
||||
this.name = name
|
||||
this.pass = pass
|
||||
}
|
||||
71
node_modules/morgan/node_modules/basic-auth/package.json
generated
vendored
Normal file
71
node_modules/morgan/node_modules/basic-auth/package.json
generated
vendored
Normal file
@@ -0,0 +1,71 @@
|
||||
{
|
||||
"name": "basic-auth",
|
||||
"description": "node.js basic auth parser",
|
||||
"version": "1.0.2",
|
||||
"license": "MIT",
|
||||
"keywords": [
|
||||
"basic",
|
||||
"auth",
|
||||
"authorization",
|
||||
"basicauth"
|
||||
],
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jshttp/basic-auth.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.15",
|
||||
"mocha": "1.21.5"
|
||||
},
|
||||
"files": [
|
||||
"HISTORY.md",
|
||||
"LICENSE",
|
||||
"index.js"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "mocha --check-leaks --reporter spec --bail",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|
||||
},
|
||||
"gitHead": "5e2d7ef5bad393e17ed0035f4926846137559260",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jshttp/basic-auth/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jshttp/basic-auth",
|
||||
"_id": "basic-auth@1.0.2",
|
||||
"_shasum": "42900137fb0c91462d14b3739c14bf2bb624171d",
|
||||
"_from": "basic-auth@>=1.0.1 <1.1.0",
|
||||
"_npmVersion": "1.4.28",
|
||||
"_npmUser": {
|
||||
"name": "dougwilson",
|
||||
"email": "doug@somethingdoug.com"
|
||||
},
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "tjholowaychuk",
|
||||
"email": "tj@vision-media.ca"
|
||||
},
|
||||
{
|
||||
"name": "jonathanong",
|
||||
"email": "jonathanrichardong@gmail.com"
|
||||
},
|
||||
{
|
||||
"name": "dougwilson",
|
||||
"email": "doug@somethingdoug.com"
|
||||
},
|
||||
{
|
||||
"name": "jongleberry",
|
||||
"email": "jonathanrichardong@gmail.com"
|
||||
}
|
||||
],
|
||||
"dist": {
|
||||
"shasum": "42900137fb0c91462d14b3739c14bf2bb624171d",
|
||||
"tarball": "http://registry.npmjs.org/basic-auth/-/basic-auth-1.0.2.tgz"
|
||||
},
|
||||
"directories": {},
|
||||
"_resolved": "https://registry.npmjs.org/basic-auth/-/basic-auth-1.0.2.tgz",
|
||||
"readme": "ERROR: No README data found!"
|
||||
}
|
||||
75
node_modules/morgan/node_modules/depd/History.md
generated
vendored
Normal file
75
node_modules/morgan/node_modules/depd/History.md
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
1.0.1 / 2015-04-07
|
||||
==================
|
||||
|
||||
* Fix `TypeError`s when under `'use strict'` code
|
||||
* Fix useless type name on auto-generated messages
|
||||
* Support io.js 1.x
|
||||
* Support Node.js 0.12
|
||||
|
||||
1.0.0 / 2014-09-17
|
||||
==================
|
||||
|
||||
* No changes
|
||||
|
||||
0.4.5 / 2014-09-09
|
||||
==================
|
||||
|
||||
* Improve call speed to functions using the function wrapper
|
||||
* Support Node.js 0.6
|
||||
|
||||
0.4.4 / 2014-07-27
|
||||
==================
|
||||
|
||||
* Work-around v8 generating empty stack traces
|
||||
|
||||
0.4.3 / 2014-07-26
|
||||
==================
|
||||
|
||||
* Fix exception when global `Error.stackTraceLimit` is too low
|
||||
|
||||
0.4.2 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Correct call site for wrapped functions and properties
|
||||
|
||||
0.4.1 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Improve automatic message generation for function properties
|
||||
|
||||
0.4.0 / 2014-07-19
|
||||
==================
|
||||
|
||||
* Add `TRACE_DEPRECATION` environment variable
|
||||
* Remove non-standard grey color from color output
|
||||
* Support `--no-deprecation` argument
|
||||
* Support `--trace-deprecation` argument
|
||||
* Support `deprecate.property(fn, prop, message)`
|
||||
|
||||
0.3.0 / 2014-06-16
|
||||
==================
|
||||
|
||||
* Add `NO_DEPRECATION` environment variable
|
||||
|
||||
0.2.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Add `deprecate.property(obj, prop, message)`
|
||||
* Remove `supports-color` dependency for node.js 0.8
|
||||
|
||||
0.1.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Add `deprecate.function(fn, message)`
|
||||
* Add `process.on('deprecation', fn)` emitter
|
||||
* Automatically generate message when omitted from `deprecate()`
|
||||
|
||||
0.0.1 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Fix warning for dynamic calls at singe call site
|
||||
|
||||
0.0.0 / 2014-06-15
|
||||
==================
|
||||
|
||||
* Initial implementation
|
||||
22
node_modules/morgan/node_modules/depd/LICENSE
generated
vendored
Normal file
22
node_modules/morgan/node_modules/depd/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2014 Douglas Christopher Wilson
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
274
node_modules/morgan/node_modules/depd/Readme.md
generated
vendored
Normal file
274
node_modules/morgan/node_modules/depd/Readme.md
generated
vendored
Normal file
@@ -0,0 +1,274 @@
|
||||
# depd
|
||||
|
||||
[![NPM Version][npm-version-image]][npm-url]
|
||||
[![NPM Downloads][npm-downloads-image]][npm-url]
|
||||
[![Node.js Version][node-image]][node-url]
|
||||
[![Linux Build][travis-image]][travis-url]
|
||||
[![Windows Build][appveyor-image]][appveyor-url]
|
||||
[![Coverage Status][coveralls-image]][coveralls-url]
|
||||
[![Gratipay][gratipay-image]][gratipay-url]
|
||||
|
||||
Deprecate all the things
|
||||
|
||||
> With great modules comes great responsibility; mark things deprecated!
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install depd
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var deprecate = require('depd')('my-module')
|
||||
```
|
||||
|
||||
This library allows you to display deprecation messages to your users.
|
||||
This library goes above and beyond with deprecation warnings by
|
||||
introspection of the call stack (but only the bits that it is interested
|
||||
in).
|
||||
|
||||
Instead of just warning on the first invocation of a deprecated
|
||||
function and never again, this module will warn on the first invocation
|
||||
of a deprecated function per unique call site, making it ideal to alert
|
||||
users of all deprecated uses across the code base, rather than just
|
||||
whatever happens to execute first.
|
||||
|
||||
The deprecation warnings from this module also include the file and line
|
||||
information for the call into the module that the deprecated function was
|
||||
in.
|
||||
|
||||
**NOTE** this library has a similar interface to the `debug` module, and
|
||||
this module uses the calling file to get the boundary for the call stacks,
|
||||
so you should always create a new `deprecate` object in each file and not
|
||||
within some central file.
|
||||
|
||||
### depd(namespace)
|
||||
|
||||
Create a new deprecate function that uses the given namespace name in the
|
||||
messages and will display the call site prior to the stack entering the
|
||||
file this function was called from. It is highly suggested you use the
|
||||
name of your module as the namespace.
|
||||
|
||||
### deprecate(message)
|
||||
|
||||
Call this function from deprecated code to display a deprecation message.
|
||||
This message will appear once per unique caller site. Caller site is the
|
||||
first call site in the stack in a different file from the caller of this
|
||||
function.
|
||||
|
||||
If the message is omitted, a message is generated for you based on the site
|
||||
of the `deprecate()` call and will display the name of the function called,
|
||||
similar to the name displayed in a stack trace.
|
||||
|
||||
### deprecate.function(fn, message)
|
||||
|
||||
Call this function to wrap a given function in a deprecation message on any
|
||||
call to the function. An optional message can be supplied to provide a custom
|
||||
message.
|
||||
|
||||
### deprecate.property(obj, prop, message)
|
||||
|
||||
Call this function to wrap a given property on object in a deprecation message
|
||||
on any accessing or setting of the property. An optional message can be supplied
|
||||
to provide a custom message.
|
||||
|
||||
The method must be called on the object where the property belongs (not
|
||||
inherited from the prototype).
|
||||
|
||||
If the property is a data descriptor, it will be converted to an accessor
|
||||
descriptor in order to display the deprecation message.
|
||||
|
||||
### process.on('deprecation', fn)
|
||||
|
||||
This module will allow easy capturing of deprecation errors by emitting the
|
||||
errors as the type "deprecation" on the global `process`. If there are no
|
||||
listeners for this type, the errors are written to STDERR as normal, but if
|
||||
there are any listeners, nothing will be written to STDERR and instead only
|
||||
emitted. From there, you can write the errors in a different format or to a
|
||||
logging source.
|
||||
|
||||
The error represents the deprecation and is emitted only once with the same
|
||||
rules as writing to STDERR. The error has the following properties:
|
||||
|
||||
- `message` - This is the message given by the library
|
||||
- `name` - This is always `'DeprecationError'`
|
||||
- `namespace` - This is the namespace the deprecation came from
|
||||
- `stack` - This is the stack of the call to the deprecated thing
|
||||
|
||||
Example `error.stack` output:
|
||||
|
||||
```
|
||||
DeprecationError: my-cool-module deprecated oldfunction
|
||||
at Object.<anonymous> ([eval]-wrapper:6:22)
|
||||
at Module._compile (module.js:456:26)
|
||||
at evalScript (node.js:532:25)
|
||||
at startup (node.js:80:7)
|
||||
at node.js:902:3
|
||||
```
|
||||
|
||||
### process.env.NO_DEPRECATION
|
||||
|
||||
As a user of modules that are deprecated, the environment variable `NO_DEPRECATION`
|
||||
is provided as a quick solution to silencing deprecation warnings from being
|
||||
output. The format of this is similar to that of `DEBUG`:
|
||||
|
||||
```sh
|
||||
$ NO_DEPRECATION=my-module,othermod node app.js
|
||||
```
|
||||
|
||||
This will suppress deprecations from being output for "my-module" and "othermod".
|
||||
The value is a list of comma-separated namespaces. To suppress every warning
|
||||
across all namespaces, use the value `*` for a namespace.
|
||||
|
||||
Providing the argument `--no-deprecation` to the `node` executable will suppress
|
||||
all deprecations (only available in Node.js 0.8 or higher).
|
||||
|
||||
**NOTE** This will not suppress the deperecations given to any "deprecation"
|
||||
event listeners, just the output to STDERR.
|
||||
|
||||
### process.env.TRACE_DEPRECATION
|
||||
|
||||
As a user of modules that are deprecated, the environment variable `TRACE_DEPRECATION`
|
||||
is provided as a solution to getting more detailed location information in deprecation
|
||||
warnings by including the entire stack trace. The format of this is the same as
|
||||
`NO_DEPRECATION`:
|
||||
|
||||
```sh
|
||||
$ TRACE_DEPRECATION=my-module,othermod node app.js
|
||||
```
|
||||
|
||||
This will include stack traces for deprecations being output for "my-module" and
|
||||
"othermod". The value is a list of comma-separated namespaces. To trace every
|
||||
warning across all namespaces, use the value `*` for a namespace.
|
||||
|
||||
Providing the argument `--trace-deprecation` to the `node` executable will trace
|
||||
all deprecations (only available in Node.js 0.8 or higher).
|
||||
|
||||
**NOTE** This will not trace the deperecations silenced by `NO_DEPRECATION`.
|
||||
|
||||
## Display
|
||||
|
||||

|
||||
|
||||
When a user calls a function in your library that you mark deprecated, they
|
||||
will see the following written to STDERR (in the given colors, similar colors
|
||||
and layout to the `debug` module):
|
||||
|
||||
```
|
||||
bright cyan bright yellow
|
||||
| | reset cyan
|
||||
| | | |
|
||||
▼ ▼ ▼ ▼
|
||||
my-cool-module deprecated oldfunction [eval]-wrapper:6:22
|
||||
▲ ▲ ▲ ▲
|
||||
| | | |
|
||||
namespace | | location of mycoolmod.oldfunction() call
|
||||
| deprecation message
|
||||
the word "deprecated"
|
||||
```
|
||||
|
||||
If the user redirects their STDERR to a file or somewhere that does not support
|
||||
colors, they see (similar layout to the `debug` module):
|
||||
|
||||
```
|
||||
Sun, 15 Jun 2014 05:21:37 GMT my-cool-module deprecated oldfunction at [eval]-wrapper:6:22
|
||||
▲ ▲ ▲ ▲ ▲
|
||||
| | | | |
|
||||
timestamp of message namespace | | location of mycoolmod.oldfunction() call
|
||||
| deprecation message
|
||||
the word "deprecated"
|
||||
```
|
||||
|
||||
## Examples
|
||||
|
||||
### Deprecating all calls to a function
|
||||
|
||||
This will display a deprecated message about "oldfunction" being deprecated
|
||||
from "my-module" on STDERR.
|
||||
|
||||
```js
|
||||
var deprecate = require('depd')('my-cool-module')
|
||||
|
||||
// message automatically derived from function name
|
||||
// Object.oldfunction
|
||||
exports.oldfunction = deprecate.function(function oldfunction() {
|
||||
// all calls to function are deprecated
|
||||
})
|
||||
|
||||
// specific message
|
||||
exports.oldfunction = deprecate.function(function () {
|
||||
// all calls to function are deprecated
|
||||
}, 'oldfunction')
|
||||
```
|
||||
|
||||
### Conditionally deprecating a function call
|
||||
|
||||
This will display a deprecated message about "weirdfunction" being deprecated
|
||||
from "my-module" on STDERR when called with less than 2 arguments.
|
||||
|
||||
```js
|
||||
var deprecate = require('depd')('my-cool-module')
|
||||
|
||||
exports.weirdfunction = function () {
|
||||
if (arguments.length < 2) {
|
||||
// calls with 0 or 1 args are deprecated
|
||||
deprecate('weirdfunction args < 2')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
When calling `deprecate` as a function, the warning is counted per call site
|
||||
within your own module, so you can display different deprecations depending
|
||||
on different situations and the users will still get all the warnings:
|
||||
|
||||
```js
|
||||
var deprecate = require('depd')('my-cool-module')
|
||||
|
||||
exports.weirdfunction = function () {
|
||||
if (arguments.length < 2) {
|
||||
// calls with 0 or 1 args are deprecated
|
||||
deprecate('weirdfunction args < 2')
|
||||
} else if (typeof arguments[0] !== 'string') {
|
||||
// calls with non-string first argument are deprecated
|
||||
deprecate('weirdfunction non-string first arg')
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Deprecating property access
|
||||
|
||||
This will display a deprecated message about "oldprop" being deprecated
|
||||
from "my-module" on STDERR when accessed. A deprecation will be displayed
|
||||
when setting the value and when getting the value.
|
||||
|
||||
```js
|
||||
var deprecate = require('depd')('my-cool-module')
|
||||
|
||||
exports.oldprop = 'something'
|
||||
|
||||
// message automatically derives from property name
|
||||
deprecate.property(exports, 'oldprop')
|
||||
|
||||
// explicit message
|
||||
deprecate.property(exports, 'oldprop', 'oldprop >= 0.10')
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[npm-version-image]: https://img.shields.io/npm/v/depd.svg
|
||||
[npm-downloads-image]: https://img.shields.io/npm/dm/depd.svg
|
||||
[npm-url]: https://npmjs.org/package/depd
|
||||
[travis-image]: https://img.shields.io/travis/dougwilson/nodejs-depd/master.svg?label=linux
|
||||
[travis-url]: https://travis-ci.org/dougwilson/nodejs-depd
|
||||
[appveyor-image]: https://img.shields.io/appveyor/ci/dougwilson/nodejs-depd/master.svg?label=windows
|
||||
[appveyor-url]: https://ci.appveyor.com/project/dougwilson/nodejs-depd
|
||||
[coveralls-image]: https://img.shields.io/coveralls/dougwilson/nodejs-depd/master.svg
|
||||
[coveralls-url]: https://coveralls.io/r/dougwilson/nodejs-depd?branch=master
|
||||
[node-image]: https://img.shields.io/node/v/depd.svg
|
||||
[node-url]: http://nodejs.org/download/
|
||||
[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg
|
||||
[gratipay-url]: https://www.gratipay.com/dougwilson/
|
||||
529
node_modules/morgan/node_modules/depd/index.js
generated
vendored
Normal file
529
node_modules/morgan/node_modules/depd/index.js
generated
vendored
Normal file
@@ -0,0 +1,529 @@
|
||||
/*!
|
||||
* depd
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var callSiteToString = require('./lib/compat').callSiteToString
|
||||
var EventEmitter = require('events').EventEmitter
|
||||
var relative = require('path').relative
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = depd
|
||||
|
||||
/**
|
||||
* Get the path to base files on.
|
||||
*/
|
||||
|
||||
var basePath = process.cwd()
|
||||
|
||||
/**
|
||||
* Get listener count on event emitter.
|
||||
*/
|
||||
|
||||
/*istanbul ignore next*/
|
||||
var eventListenerCount = EventEmitter.listenerCount
|
||||
|| function (emitter, type) { return emitter.listeners(type).length }
|
||||
|
||||
/**
|
||||
* Determine if namespace is contained in the string.
|
||||
*/
|
||||
|
||||
function containsNamespace(str, namespace) {
|
||||
var val = str.split(/[ ,]+/)
|
||||
|
||||
namespace = String(namespace).toLowerCase()
|
||||
|
||||
for (var i = 0 ; i < val.length; i++) {
|
||||
if (!(str = val[i])) continue;
|
||||
|
||||
// namespace contained
|
||||
if (str === '*' || str.toLowerCase() === namespace) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a data descriptor to accessor descriptor.
|
||||
*/
|
||||
|
||||
function convertDataDescriptorToAccessor(obj, prop, message) {
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
|
||||
var value = descriptor.value
|
||||
|
||||
descriptor.get = function getter() { return value }
|
||||
|
||||
if (descriptor.writable) {
|
||||
descriptor.set = function setter(val) { return value = val }
|
||||
}
|
||||
|
||||
delete descriptor.value
|
||||
delete descriptor.writable
|
||||
|
||||
Object.defineProperty(obj, prop, descriptor)
|
||||
|
||||
return descriptor
|
||||
}
|
||||
|
||||
/**
|
||||
* Create arguments string to keep arity.
|
||||
*/
|
||||
|
||||
function createArgumentsString(arity) {
|
||||
var str = ''
|
||||
|
||||
for (var i = 0; i < arity; i++) {
|
||||
str += ', arg' + i
|
||||
}
|
||||
|
||||
return str.substr(2)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create stack string from stack.
|
||||
*/
|
||||
|
||||
function createStackString(stack) {
|
||||
var str = this.name + ': ' + this.namespace
|
||||
|
||||
if (this.message) {
|
||||
str += ' deprecated ' + this.message
|
||||
}
|
||||
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
str += '\n at ' + callSiteToString(stack[i])
|
||||
}
|
||||
|
||||
return str
|
||||
}
|
||||
|
||||
/**
|
||||
* Create deprecate for namespace in caller.
|
||||
*/
|
||||
|
||||
function depd(namespace) {
|
||||
if (!namespace) {
|
||||
throw new TypeError('argument namespace is required')
|
||||
}
|
||||
|
||||
var stack = getStack()
|
||||
var site = callSiteLocation(stack[1])
|
||||
var file = site[0]
|
||||
|
||||
function deprecate(message) {
|
||||
// call to self as log
|
||||
log.call(deprecate, message)
|
||||
}
|
||||
|
||||
deprecate._file = file
|
||||
deprecate._ignored = isignored(namespace)
|
||||
deprecate._namespace = namespace
|
||||
deprecate._traced = istraced(namespace)
|
||||
deprecate._warned = Object.create(null)
|
||||
|
||||
deprecate.function = wrapfunction
|
||||
deprecate.property = wrapproperty
|
||||
|
||||
return deprecate
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if namespace is ignored.
|
||||
*/
|
||||
|
||||
function isignored(namespace) {
|
||||
/* istanbul ignore next: tested in a child processs */
|
||||
if (process.noDeprecation) {
|
||||
// --no-deprecation support
|
||||
return true
|
||||
}
|
||||
|
||||
var str = process.env.NO_DEPRECATION || ''
|
||||
|
||||
// namespace ignored
|
||||
return containsNamespace(str, namespace)
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if namespace is traced.
|
||||
*/
|
||||
|
||||
function istraced(namespace) {
|
||||
/* istanbul ignore next: tested in a child processs */
|
||||
if (process.traceDeprecation) {
|
||||
// --trace-deprecation support
|
||||
return true
|
||||
}
|
||||
|
||||
var str = process.env.TRACE_DEPRECATION || ''
|
||||
|
||||
// namespace traced
|
||||
return containsNamespace(str, namespace)
|
||||
}
|
||||
|
||||
/**
|
||||
* Display deprecation message.
|
||||
*/
|
||||
|
||||
function log(message, site) {
|
||||
var haslisteners = eventListenerCount(process, 'deprecation') !== 0
|
||||
|
||||
// abort early if no destination
|
||||
if (!haslisteners && this._ignored) {
|
||||
return
|
||||
}
|
||||
|
||||
var caller
|
||||
var callFile
|
||||
var callSite
|
||||
var i = 0
|
||||
var seen = false
|
||||
var stack = getStack()
|
||||
var file = this._file
|
||||
|
||||
if (site) {
|
||||
// provided site
|
||||
callSite = callSiteLocation(stack[1])
|
||||
callSite.name = site.name
|
||||
file = callSite[0]
|
||||
} else {
|
||||
// get call site
|
||||
i = 2
|
||||
site = callSiteLocation(stack[i])
|
||||
callSite = site
|
||||
}
|
||||
|
||||
// get caller of deprecated thing in relation to file
|
||||
for (; i < stack.length; i++) {
|
||||
caller = callSiteLocation(stack[i])
|
||||
callFile = caller[0]
|
||||
|
||||
if (callFile === file) {
|
||||
seen = true
|
||||
} else if (callFile === this._file) {
|
||||
file = this._file
|
||||
} else if (seen) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
var key = caller
|
||||
? site.join(':') + '__' + caller.join(':')
|
||||
: undefined
|
||||
|
||||
if (key !== undefined && key in this._warned) {
|
||||
// already warned
|
||||
return
|
||||
}
|
||||
|
||||
this._warned[key] = true
|
||||
|
||||
// generate automatic message from call site
|
||||
if (!message) {
|
||||
message = callSite === site || !callSite.name
|
||||
? defaultMessage(site)
|
||||
: defaultMessage(callSite)
|
||||
}
|
||||
|
||||
// emit deprecation if listeners exist
|
||||
if (haslisteners) {
|
||||
var err = DeprecationError(this._namespace, message, stack.slice(i))
|
||||
process.emit('deprecation', err)
|
||||
return
|
||||
}
|
||||
|
||||
// format and write message
|
||||
var format = process.stderr.isTTY
|
||||
? formatColor
|
||||
: formatPlain
|
||||
var msg = format.call(this, message, caller, stack.slice(i))
|
||||
process.stderr.write(msg + '\n', 'utf8')
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/**
|
||||
* Get call site location as array.
|
||||
*/
|
||||
|
||||
function callSiteLocation(callSite) {
|
||||
var file = callSite.getFileName() || '<anonymous>'
|
||||
var line = callSite.getLineNumber()
|
||||
var colm = callSite.getColumnNumber()
|
||||
|
||||
if (callSite.isEval()) {
|
||||
file = callSite.getEvalOrigin() + ', ' + file
|
||||
}
|
||||
|
||||
var site = [file, line, colm]
|
||||
|
||||
site.callSite = callSite
|
||||
site.name = callSite.getFunctionName()
|
||||
|
||||
return site
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a default message from the site.
|
||||
*/
|
||||
|
||||
function defaultMessage(site) {
|
||||
var callSite = site.callSite
|
||||
var funcName = site.name
|
||||
|
||||
// make useful anonymous name
|
||||
if (!funcName) {
|
||||
funcName = '<anonymous@' + formatLocation(site) + '>'
|
||||
}
|
||||
|
||||
var context = callSite.getThis()
|
||||
var typeName = context && callSite.getTypeName()
|
||||
|
||||
// ignore useless type name
|
||||
if (typeName === 'Object') {
|
||||
typeName = undefined
|
||||
}
|
||||
|
||||
// make useful type name
|
||||
if (typeName === 'Function') {
|
||||
typeName = context.name || typeName
|
||||
}
|
||||
|
||||
return typeName && callSite.getMethodName()
|
||||
? typeName + '.' + funcName
|
||||
: funcName
|
||||
}
|
||||
|
||||
/**
|
||||
* Format deprecation message without color.
|
||||
*/
|
||||
|
||||
function formatPlain(msg, caller, stack) {
|
||||
var timestamp = new Date().toUTCString()
|
||||
|
||||
var formatted = timestamp
|
||||
+ ' ' + this._namespace
|
||||
+ ' deprecated ' + msg
|
||||
|
||||
// add stack trace
|
||||
if (this._traced) {
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
formatted += '\n at ' + callSiteToString(stack[i])
|
||||
}
|
||||
|
||||
return formatted
|
||||
}
|
||||
|
||||
if (caller) {
|
||||
formatted += ' at ' + formatLocation(caller)
|
||||
}
|
||||
|
||||
return formatted
|
||||
}
|
||||
|
||||
/**
|
||||
* Format deprecation message with color.
|
||||
*/
|
||||
|
||||
function formatColor(msg, caller, stack) {
|
||||
var formatted = '\x1b[36;1m' + this._namespace + '\x1b[22;39m' // bold cyan
|
||||
+ ' \x1b[33;1mdeprecated\x1b[22;39m' // bold yellow
|
||||
+ ' \x1b[0m' + msg + '\x1b[39m' // reset
|
||||
|
||||
// add stack trace
|
||||
if (this._traced) {
|
||||
for (var i = 0; i < stack.length; i++) {
|
||||
formatted += '\n \x1b[36mat ' + callSiteToString(stack[i]) + '\x1b[39m' // cyan
|
||||
}
|
||||
|
||||
return formatted
|
||||
}
|
||||
|
||||
if (caller) {
|
||||
formatted += ' \x1b[36m' + formatLocation(caller) + '\x1b[39m' // cyan
|
||||
}
|
||||
|
||||
return formatted
|
||||
}
|
||||
|
||||
/**
|
||||
* Format call site location.
|
||||
*/
|
||||
|
||||
function formatLocation(callSite) {
|
||||
return relative(basePath, callSite[0])
|
||||
+ ':' + callSite[1]
|
||||
+ ':' + callSite[2]
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the stack as array of call sites.
|
||||
*/
|
||||
|
||||
function getStack() {
|
||||
var limit = Error.stackTraceLimit
|
||||
var obj = {}
|
||||
var prep = Error.prepareStackTrace
|
||||
|
||||
Error.prepareStackTrace = prepareObjectStackTrace
|
||||
Error.stackTraceLimit = Math.max(10, limit)
|
||||
|
||||
// capture the stack
|
||||
Error.captureStackTrace(obj)
|
||||
|
||||
// slice this function off the top
|
||||
var stack = obj.stack.slice(1)
|
||||
|
||||
Error.prepareStackTrace = prep
|
||||
Error.stackTraceLimit = limit
|
||||
|
||||
return stack
|
||||
}
|
||||
|
||||
/**
|
||||
* Capture call site stack from v8.
|
||||
*/
|
||||
|
||||
function prepareObjectStackTrace(obj, stack) {
|
||||
return stack
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a wrapped function in a deprecation message.
|
||||
*/
|
||||
|
||||
function wrapfunction(fn, message) {
|
||||
if (typeof fn !== 'function') {
|
||||
throw new TypeError('argument fn must be a function')
|
||||
}
|
||||
|
||||
var args = createArgumentsString(fn.length)
|
||||
var deprecate = this
|
||||
var stack = getStack()
|
||||
var site = callSiteLocation(stack[1])
|
||||
|
||||
site.name = fn.name
|
||||
|
||||
var deprecatedfn = eval('(function (' + args + ') {\n'
|
||||
+ '"use strict"\n'
|
||||
+ 'log.call(deprecate, message, site)\n'
|
||||
+ 'return fn.apply(this, arguments)\n'
|
||||
+ '})')
|
||||
|
||||
return deprecatedfn
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap property in a deprecation message.
|
||||
*/
|
||||
|
||||
function wrapproperty(obj, prop, message) {
|
||||
if (!obj || (typeof obj !== 'object' && typeof obj !== 'function')) {
|
||||
throw new TypeError('argument obj must be object')
|
||||
}
|
||||
|
||||
var descriptor = Object.getOwnPropertyDescriptor(obj, prop)
|
||||
|
||||
if (!descriptor) {
|
||||
throw new TypeError('must call property on owner object')
|
||||
}
|
||||
|
||||
if (!descriptor.configurable) {
|
||||
throw new TypeError('property must be configurable')
|
||||
}
|
||||
|
||||
var deprecate = this
|
||||
var stack = getStack()
|
||||
var site = callSiteLocation(stack[1])
|
||||
|
||||
// set site name
|
||||
site.name = prop
|
||||
|
||||
// convert data descriptor
|
||||
if ('value' in descriptor) {
|
||||
descriptor = convertDataDescriptorToAccessor(obj, prop, message)
|
||||
}
|
||||
|
||||
var get = descriptor.get
|
||||
var set = descriptor.set
|
||||
|
||||
// wrap getter
|
||||
if (typeof get === 'function') {
|
||||
descriptor.get = function getter() {
|
||||
log.call(deprecate, message, site)
|
||||
return get.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
// wrap setter
|
||||
if (typeof set === 'function') {
|
||||
descriptor.set = function setter() {
|
||||
log.call(deprecate, message, site)
|
||||
return set.apply(this, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
Object.defineProperty(obj, prop, descriptor)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create DeprecationError for deprecation
|
||||
*/
|
||||
|
||||
function DeprecationError(namespace, message, stack) {
|
||||
var error = new Error()
|
||||
var stackString
|
||||
|
||||
Object.defineProperty(error, 'constructor', {
|
||||
value: DeprecationError
|
||||
})
|
||||
|
||||
Object.defineProperty(error, 'message', {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: message,
|
||||
writable: true
|
||||
})
|
||||
|
||||
Object.defineProperty(error, 'name', {
|
||||
enumerable: false,
|
||||
configurable: true,
|
||||
value: 'DeprecationError',
|
||||
writable: true
|
||||
})
|
||||
|
||||
Object.defineProperty(error, 'namespace', {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
value: namespace,
|
||||
writable: true
|
||||
})
|
||||
|
||||
Object.defineProperty(error, 'stack', {
|
||||
configurable: true,
|
||||
enumerable: false,
|
||||
get: function () {
|
||||
if (stackString !== undefined) {
|
||||
return stackString
|
||||
}
|
||||
|
||||
// prepare stack trace
|
||||
return stackString = createStackString.call(this, stack)
|
||||
},
|
||||
set: function setter(val) {
|
||||
stackString = val
|
||||
}
|
||||
})
|
||||
|
||||
return error
|
||||
}
|
||||
33
node_modules/morgan/node_modules/depd/lib/compat/buffer-concat.js
generated
vendored
Normal file
33
node_modules/morgan/node_modules/depd/lib/compat/buffer-concat.js
generated
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
/*!
|
||||
* depd
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = bufferConcat
|
||||
|
||||
/**
|
||||
* Concatenate an array of Buffers.
|
||||
*/
|
||||
|
||||
function bufferConcat(bufs) {
|
||||
var length = 0
|
||||
|
||||
for (var i = 0, len = bufs.length; i < len; i++) {
|
||||
length += bufs[i].length
|
||||
}
|
||||
|
||||
var buf = new Buffer(length)
|
||||
var pos = 0
|
||||
|
||||
for (var i = 0, len = bufs.length; i < len; i++) {
|
||||
bufs[i].copy(buf, pos)
|
||||
pos += bufs[i].length
|
||||
}
|
||||
|
||||
return buf
|
||||
}
|
||||
101
node_modules/morgan/node_modules/depd/lib/compat/callsite-tostring.js
generated
vendored
Normal file
101
node_modules/morgan/node_modules/depd/lib/compat/callsite-tostring.js
generated
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/*!
|
||||
* depd
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = callSiteToString
|
||||
|
||||
/**
|
||||
* Format a CallSite file location to a string.
|
||||
*/
|
||||
|
||||
function callSiteFileLocation(callSite) {
|
||||
var fileName
|
||||
var fileLocation = ''
|
||||
|
||||
if (callSite.isNative()) {
|
||||
fileLocation = 'native'
|
||||
} else if (callSite.isEval()) {
|
||||
fileName = callSite.getScriptNameOrSourceURL()
|
||||
if (!fileName) {
|
||||
fileLocation = callSite.getEvalOrigin()
|
||||
}
|
||||
} else {
|
||||
fileName = callSite.getFileName()
|
||||
}
|
||||
|
||||
if (fileName) {
|
||||
fileLocation += fileName
|
||||
|
||||
var lineNumber = callSite.getLineNumber()
|
||||
if (lineNumber != null) {
|
||||
fileLocation += ':' + lineNumber
|
||||
|
||||
var columnNumber = callSite.getColumnNumber()
|
||||
if (columnNumber) {
|
||||
fileLocation += ':' + columnNumber
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return fileLocation || 'unknown source'
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a CallSite to a string.
|
||||
*/
|
||||
|
||||
function callSiteToString(callSite) {
|
||||
var addSuffix = true
|
||||
var fileLocation = callSiteFileLocation(callSite)
|
||||
var functionName = callSite.getFunctionName()
|
||||
var isConstructor = callSite.isConstructor()
|
||||
var isMethodCall = !(callSite.isToplevel() || isConstructor)
|
||||
var line = ''
|
||||
|
||||
if (isMethodCall) {
|
||||
var methodName = callSite.getMethodName()
|
||||
var typeName = getConstructorName(callSite)
|
||||
|
||||
if (functionName) {
|
||||
if (typeName && functionName.indexOf(typeName) !== 0) {
|
||||
line += typeName + '.'
|
||||
}
|
||||
|
||||
line += functionName
|
||||
|
||||
if (methodName && functionName.lastIndexOf('.' + methodName) !== functionName.length - methodName.length - 1) {
|
||||
line += ' [as ' + methodName + ']'
|
||||
}
|
||||
} else {
|
||||
line += typeName + '.' + (methodName || '<anonymous>')
|
||||
}
|
||||
} else if (isConstructor) {
|
||||
line += 'new ' + (functionName || '<anonymous>')
|
||||
} else if (functionName) {
|
||||
line += functionName
|
||||
} else {
|
||||
addSuffix = false
|
||||
line += fileLocation
|
||||
}
|
||||
|
||||
if (addSuffix) {
|
||||
line += ' (' + fileLocation + ')'
|
||||
}
|
||||
|
||||
return line
|
||||
}
|
||||
|
||||
/**
|
||||
* Get constructor name of reviver.
|
||||
*/
|
||||
|
||||
function getConstructorName(obj) {
|
||||
var receiver = obj.receiver
|
||||
return (receiver.constructor && receiver.constructor.name) || null
|
||||
}
|
||||
69
node_modules/morgan/node_modules/depd/lib/compat/index.js
generated
vendored
Normal file
69
node_modules/morgan/node_modules/depd/lib/compat/index.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/*!
|
||||
* depd
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
lazyProperty(module.exports, 'bufferConcat', function bufferConcat() {
|
||||
return Buffer.concat || require('./buffer-concat')
|
||||
})
|
||||
|
||||
lazyProperty(module.exports, 'callSiteToString', function callSiteToString() {
|
||||
var limit = Error.stackTraceLimit
|
||||
var obj = {}
|
||||
var prep = Error.prepareStackTrace
|
||||
|
||||
function prepareObjectStackTrace(obj, stack) {
|
||||
return stack
|
||||
}
|
||||
|
||||
Error.prepareStackTrace = prepareObjectStackTrace
|
||||
Error.stackTraceLimit = 2
|
||||
|
||||
// capture the stack
|
||||
Error.captureStackTrace(obj)
|
||||
|
||||
// slice the stack
|
||||
var stack = obj.stack.slice()
|
||||
|
||||
Error.prepareStackTrace = prep
|
||||
Error.stackTraceLimit = limit
|
||||
|
||||
return stack[0].toString ? toString : require('./callsite-tostring')
|
||||
})
|
||||
|
||||
/**
|
||||
* Define a lazy property.
|
||||
*/
|
||||
|
||||
function lazyProperty(obj, prop, getter) {
|
||||
function get() {
|
||||
var val = getter()
|
||||
|
||||
Object.defineProperty(obj, prop, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
value: val
|
||||
})
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
Object.defineProperty(obj, prop, {
|
||||
configurable: true,
|
||||
enumerable: true,
|
||||
get: get
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Call toString() on the obj
|
||||
*/
|
||||
|
||||
function toString(obj) {
|
||||
return obj.toString()
|
||||
}
|
||||
50
node_modules/morgan/node_modules/depd/package.json
generated
vendored
Normal file
50
node_modules/morgan/node_modules/depd/package.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
81
node_modules/morgan/node_modules/on-finished/HISTORY.md
generated
vendored
Normal file
81
node_modules/morgan/node_modules/on-finished/HISTORY.md
generated
vendored
Normal file
@@ -0,0 +1,81 @@
|
||||
2.2.1 / 2015-04-22
|
||||
==================
|
||||
|
||||
* Fix `isFinished(req)` when data buffered
|
||||
|
||||
2.2.0 / 2014-12-22
|
||||
==================
|
||||
|
||||
* Add message object to callback arguments
|
||||
|
||||
2.1.1 / 2014-10-22
|
||||
==================
|
||||
|
||||
* Fix handling of pipelined requests
|
||||
|
||||
2.1.0 / 2014-08-16
|
||||
==================
|
||||
|
||||
* Check if `socket` is detached
|
||||
* Return `undefined` for `isFinished` if state unknown
|
||||
|
||||
2.0.0 / 2014-08-16
|
||||
==================
|
||||
|
||||
* Add `isFinished` function
|
||||
* Move to `jshttp` organization
|
||||
* Remove support for plain socket argument
|
||||
* Rename to `on-finished`
|
||||
* Support both `req` and `res` as arguments
|
||||
* deps: ee-first@1.0.5
|
||||
|
||||
1.2.2 / 2014-06-10
|
||||
==================
|
||||
|
||||
* Reduce listeners added to emitters
|
||||
- avoids "event emitter leak" warnings when used multiple times on same request
|
||||
|
||||
1.2.1 / 2014-06-08
|
||||
==================
|
||||
|
||||
* Fix returned value when already finished
|
||||
|
||||
1.2.0 / 2014-06-05
|
||||
==================
|
||||
|
||||
* Call callback when called on already-finished socket
|
||||
|
||||
1.1.4 / 2014-05-27
|
||||
==================
|
||||
|
||||
* Support node.js 0.8
|
||||
|
||||
1.1.3 / 2014-04-30
|
||||
==================
|
||||
|
||||
* Make sure errors passed as instanceof `Error`
|
||||
|
||||
1.1.2 / 2014-04-18
|
||||
==================
|
||||
|
||||
* Default the `socket` to passed-in object
|
||||
|
||||
1.1.1 / 2014-01-16
|
||||
==================
|
||||
|
||||
* Rename module to `finished`
|
||||
|
||||
1.1.0 / 2013-12-25
|
||||
==================
|
||||
|
||||
* Call callback when called on already-errored socket
|
||||
|
||||
1.0.1 / 2013-12-20
|
||||
==================
|
||||
|
||||
* Actually pass the error to the callback
|
||||
|
||||
1.0.0 / 2013-12-20
|
||||
==================
|
||||
|
||||
* Initial release
|
||||
23
node_modules/morgan/node_modules/on-finished/LICENSE
generated
vendored
Normal file
23
node_modules/morgan/node_modules/on-finished/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2013 Jonathan Ong <me@jongleberry.com>
|
||||
Copyright (c) 2014 Douglas Christopher Wilson <doug@somethingdoug.com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
'Software'), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
109
node_modules/morgan/node_modules/on-finished/README.md
generated
vendored
Normal file
109
node_modules/morgan/node_modules/on-finished/README.md
generated
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
# on-finished
|
||||
|
||||
[![NPM Version][npm-image]][npm-url]
|
||||
[![NPM Downloads][downloads-image]][downloads-url]
|
||||
[![Node.js Version][node-version-image]][node-version-url]
|
||||
[![Build Status][travis-image]][travis-url]
|
||||
[![Test Coverage][coveralls-image]][coveralls-url]
|
||||
|
||||
Execute a callback when a request closes, finishes, or errors.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install on-finished
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var onFinished = require('on-finished')
|
||||
```
|
||||
|
||||
### onFinished(res, listener)
|
||||
|
||||
Attach a listener to listen for the response to finish. The listener will
|
||||
be invoked only once when the response finished. If the response finished
|
||||
to to an error, the first argument will contain the error. If the response
|
||||
has already finished, the listener will be invoked.
|
||||
|
||||
Listening to the end of a response would be used to close things associated
|
||||
with the response, like open files.
|
||||
|
||||
Listener is invoked as `listener(err, res)`.
|
||||
|
||||
```js
|
||||
onFinished(res, function (err, res) {
|
||||
// clean up open fds, etc.
|
||||
// err contains the error is request error'd
|
||||
})
|
||||
```
|
||||
|
||||
### onFinished(req, listener)
|
||||
|
||||
Attach a listener to listen for the request to finish. The listener will
|
||||
be invoked only once when the request finished. If the request finished
|
||||
to to an error, the first argument will contain the error. If the request
|
||||
has already finished, the listener will be invoked.
|
||||
|
||||
Listening to the end of a request would be used to know when to continue
|
||||
after reading the data.
|
||||
|
||||
Listener is invoked as `listener(err, req)`.
|
||||
|
||||
```js
|
||||
var data = ''
|
||||
|
||||
req.setEncoding('utf8')
|
||||
res.on('data', function (str) {
|
||||
data += str
|
||||
})
|
||||
|
||||
onFinished(req, function (err, req) {
|
||||
// data is read unless there is err
|
||||
})
|
||||
```
|
||||
|
||||
### onFinished.isFinished(res)
|
||||
|
||||
Determine if `res` is already finished. This would be useful to check and
|
||||
not even start certain operations if the response has already finished.
|
||||
|
||||
### onFinished.isFinished(req)
|
||||
|
||||
Determine if `req` is already finished. This would be useful to check and
|
||||
not even start certain operations if the request has already finished.
|
||||
|
||||
### Example
|
||||
|
||||
The following code ensures that file descriptors are always closed
|
||||
once the response finishes.
|
||||
|
||||
```js
|
||||
var destroy = require('destroy')
|
||||
var http = require('http')
|
||||
var onFinished = require('on-finished')
|
||||
|
||||
http.createServer(function onRequest(req, res) {
|
||||
var stream = fs.createReadStream('package.json')
|
||||
stream.pipe(res)
|
||||
onFinished(res, function (err) {
|
||||
destroy(stream)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE)
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/on-finished.svg
|
||||
[npm-url]: https://npmjs.org/package/on-finished
|
||||
[node-version-image]: https://img.shields.io/node/v/on-finished.svg
|
||||
[node-version-url]: http://nodejs.org/download/
|
||||
[travis-image]: https://img.shields.io/travis/jshttp/on-finished/master.svg
|
||||
[travis-url]: https://travis-ci.org/jshttp/on-finished
|
||||
[coveralls-image]: https://img.shields.io/coveralls/jshttp/on-finished/master.svg
|
||||
[coveralls-url]: https://coveralls.io/r/jshttp/on-finished?branch=master
|
||||
[downloads-image]: https://img.shields.io/npm/dm/on-finished.svg
|
||||
[downloads-url]: https://npmjs.org/package/on-finished
|
||||
191
node_modules/morgan/node_modules/on-finished/index.js
generated
vendored
Normal file
191
node_modules/morgan/node_modules/on-finished/index.js
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
/*!
|
||||
* on-finished
|
||||
* Copyright(c) 2013 Jonathan Ong
|
||||
* Copyright(c) 2014 Douglas Christopher Wilson
|
||||
* MIT Licensed
|
||||
*/
|
||||
|
||||
/**
|
||||
* Module exports.
|
||||
*/
|
||||
|
||||
module.exports = onFinished;
|
||||
module.exports.isFinished = isFinished;
|
||||
|
||||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
|
||||
var first = require('ee-first')
|
||||
|
||||
/**
|
||||
* Variables.
|
||||
*/
|
||||
|
||||
/* istanbul ignore next */
|
||||
var defer = typeof setImmediate === 'function'
|
||||
? setImmediate
|
||||
: function(fn){ process.nextTick(fn.bind.apply(fn, arguments)) }
|
||||
|
||||
/**
|
||||
* Invoke callback when the response has finished, useful for
|
||||
* cleaning up resources afterwards.
|
||||
*
|
||||
* @param {object} msg
|
||||
* @param {function} listener
|
||||
* @return {object}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function onFinished(msg, listener) {
|
||||
if (isFinished(msg) !== false) {
|
||||
defer(listener, null, msg)
|
||||
return msg
|
||||
}
|
||||
|
||||
// attach the listener to the message
|
||||
attachListener(msg, listener)
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if message is already finished.
|
||||
*
|
||||
* @param {object} msg
|
||||
* @return {boolean}
|
||||
* @api public
|
||||
*/
|
||||
|
||||
function isFinished(msg) {
|
||||
var socket = msg.socket
|
||||
|
||||
if (typeof msg.finished === 'boolean') {
|
||||
// OutgoingMessage
|
||||
return Boolean(msg.finished || (socket && !socket.writable))
|
||||
}
|
||||
|
||||
if (typeof msg.complete === 'boolean') {
|
||||
// IncomingMessage
|
||||
return Boolean(!socket || !socket.readable || (msg.complete && !msg.readable))
|
||||
}
|
||||
|
||||
// don't know
|
||||
return undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach a finished listener to the message.
|
||||
*
|
||||
* @param {object} msg
|
||||
* @param {function} callback
|
||||
* @private
|
||||
*/
|
||||
|
||||
function attachFinishedListener(msg, callback) {
|
||||
var eeMsg
|
||||
var eeSocket
|
||||
var finished = false
|
||||
|
||||
function onFinish(error) {
|
||||
eeMsg.cancel()
|
||||
eeSocket.cancel()
|
||||
|
||||
finished = true
|
||||
callback(error)
|
||||
}
|
||||
|
||||
// finished on first message event
|
||||
eeMsg = eeSocket = first([[msg, 'end', 'finish']], onFinish)
|
||||
|
||||
function onSocket(socket) {
|
||||
// remove listener
|
||||
msg.removeListener('socket', onSocket)
|
||||
|
||||
if (finished) return
|
||||
if (eeMsg !== eeSocket) return
|
||||
|
||||
// finished on first socket event
|
||||
eeSocket = first([[socket, 'error', 'close']], onFinish)
|
||||
}
|
||||
|
||||
if (msg.socket) {
|
||||
// socket already assigned
|
||||
onSocket(msg.socket)
|
||||
return
|
||||
}
|
||||
|
||||
// wait for socket to be assigned
|
||||
msg.on('socket', onSocket)
|
||||
|
||||
if (msg.socket === undefined) {
|
||||
// node.js 0.8 patch
|
||||
patchAssignSocket(msg, onSocket)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attach the listener to the message.
|
||||
*
|
||||
* @param {object} msg
|
||||
* @return {function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function attachListener(msg, listener) {
|
||||
var attached = msg.__onFinished
|
||||
|
||||
// create a private single listener with queue
|
||||
if (!attached || !attached.queue) {
|
||||
attached = msg.__onFinished = createListener(msg)
|
||||
attachFinishedListener(msg, attached)
|
||||
}
|
||||
|
||||
attached.queue.push(listener)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create listener on message.
|
||||
*
|
||||
* @param {object} msg
|
||||
* @return {function}
|
||||
* @api private
|
||||
*/
|
||||
|
||||
function createListener(msg) {
|
||||
function listener(err) {
|
||||
if (msg.__onFinished === listener) msg.__onFinished = null
|
||||
if (!listener.queue) return
|
||||
|
||||
var queue = listener.queue
|
||||
listener.queue = null
|
||||
|
||||
for (var i = 0; i < queue.length; i++) {
|
||||
queue[i](err, msg)
|
||||
}
|
||||
}
|
||||
|
||||
listener.queue = []
|
||||
|
||||
return listener
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch ServerResponse.prototype.assignSocket for node.js 0.8.
|
||||
*
|
||||
* @param {ServerResponse} res
|
||||
* @param {function} callback
|
||||
* @private
|
||||
*/
|
||||
|
||||
function patchAssignSocket(res, callback) {
|
||||
var assignSocket = res.assignSocket
|
||||
|
||||
if (typeof assignSocket !== 'function') return
|
||||
|
||||
// res.on('socket', callback) is broken in 0.8
|
||||
res.assignSocket = function _assignSocket(socket) {
|
||||
assignSocket.call(this, socket)
|
||||
callback(socket)
|
||||
}
|
||||
}
|
||||
22
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/LICENSE
generated
vendored
Normal file
22
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
80
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/README.md
generated
vendored
Normal file
80
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/README.md
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
# EE First
|
||||
|
||||
[![NPM version][npm-image]][npm-url]
|
||||
[![Build status][travis-image]][travis-url]
|
||||
[![Test coverage][coveralls-image]][coveralls-url]
|
||||
[![License][license-image]][license-url]
|
||||
[![Downloads][downloads-image]][downloads-url]
|
||||
[![Gittip][gittip-image]][gittip-url]
|
||||
|
||||
Get the first event in a set of event emitters and event pairs,
|
||||
then clean up after itself.
|
||||
|
||||
## Install
|
||||
|
||||
```sh
|
||||
$ npm install ee-first
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```js
|
||||
var first = require('ee-first')
|
||||
```
|
||||
|
||||
### first(arr, listener)
|
||||
|
||||
Invoke `listener` on the first event from the list specified in `arr`. `arr` is
|
||||
an array of arrays, with each array in the format `[ee, ...event]`. `listener`
|
||||
will be called only once, the first time any of the given events are emitted. If
|
||||
`error` is one of the listened events, then if that fires first, the `listener`
|
||||
will be given the `err` argument.
|
||||
|
||||
The `listener` is invoked as `listener(err, ee, event, args)`, where `err` is the
|
||||
first argument emitted from an `error` event, if applicable; `ee` is the event
|
||||
emitter that fired; `event` is the string event name that fired; and `args` is an
|
||||
array of the arguments that were emitted on the event.
|
||||
|
||||
```js
|
||||
var ee1 = new EventEmitter()
|
||||
var ee2 = new EventEmitter()
|
||||
|
||||
first([
|
||||
[ee1, 'close', 'end', 'error'],
|
||||
[ee2, 'error']
|
||||
], function (err, ee, event, args) {
|
||||
// listener invoked
|
||||
})
|
||||
```
|
||||
|
||||
#### .cancel()
|
||||
|
||||
The group of listeners can be cancelled before being invoked and have all the event
|
||||
listeners removed from the underlying event emitters.
|
||||
|
||||
```js
|
||||
var thunk = first([
|
||||
[ee1, 'close', 'end', 'error'],
|
||||
[ee2, 'error']
|
||||
], function (err, ee, event, args) {
|
||||
// listener invoked
|
||||
})
|
||||
|
||||
// cancel and clean up
|
||||
thunk.cancel()
|
||||
```
|
||||
|
||||
[npm-image]: https://img.shields.io/npm/v/ee-first.svg?style=flat-square
|
||||
[npm-url]: https://npmjs.org/package/ee-first
|
||||
[github-tag]: http://img.shields.io/github/tag/jonathanong/ee-first.svg?style=flat-square
|
||||
[github-url]: https://github.com/jonathanong/ee-first/tags
|
||||
[travis-image]: https://img.shields.io/travis/jonathanong/ee-first.svg?style=flat-square
|
||||
[travis-url]: https://travis-ci.org/jonathanong/ee-first
|
||||
[coveralls-image]: https://img.shields.io/coveralls/jonathanong/ee-first.svg?style=flat-square
|
||||
[coveralls-url]: https://coveralls.io/r/jonathanong/ee-first?branch=master
|
||||
[license-image]: http://img.shields.io/npm/l/ee-first.svg?style=flat-square
|
||||
[license-url]: LICENSE.md
|
||||
[downloads-image]: http://img.shields.io/npm/dm/ee-first.svg?style=flat-square
|
||||
[downloads-url]: https://npmjs.org/package/ee-first
|
||||
[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square
|
||||
[gittip-url]: https://www.gittip.com/jonathanong/
|
||||
68
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/index.js
generated
vendored
Normal file
68
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/index.js
generated
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
|
||||
module.exports = function first(stuff, done) {
|
||||
if (!Array.isArray(stuff))
|
||||
throw new TypeError('arg must be an array of [ee, events...] arrays')
|
||||
|
||||
var cleanups = []
|
||||
|
||||
for (var i = 0; i < stuff.length; i++) {
|
||||
var arr = stuff[i]
|
||||
|
||||
if (!Array.isArray(arr) || arr.length < 2)
|
||||
throw new TypeError('each array member must be [ee, events...]')
|
||||
|
||||
var ee = arr[0]
|
||||
|
||||
for (var j = 1; j < arr.length; j++) {
|
||||
var event = arr[j]
|
||||
var fn = listener(event, callback)
|
||||
|
||||
// listen to the event
|
||||
ee.on(event, fn)
|
||||
// push this listener to the list of cleanups
|
||||
cleanups.push({
|
||||
ee: ee,
|
||||
event: event,
|
||||
fn: fn,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function callback() {
|
||||
cleanup()
|
||||
done.apply(null, arguments)
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
var x
|
||||
for (var i = 0; i < cleanups.length; i++) {
|
||||
x = cleanups[i]
|
||||
x.ee.removeListener(x.event, x.fn)
|
||||
}
|
||||
}
|
||||
|
||||
function thunk(fn) {
|
||||
done = fn
|
||||
}
|
||||
|
||||
thunk.cancel = cleanup
|
||||
|
||||
return thunk
|
||||
}
|
||||
|
||||
function listener(event, done) {
|
||||
return function onevent(arg1) {
|
||||
var args = new Array(arguments.length)
|
||||
var ee = this
|
||||
var err = event === 'error'
|
||||
? arg1
|
||||
: null
|
||||
|
||||
// copy args to prevent arguments escaping scope
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
args[i] = arguments[i]
|
||||
}
|
||||
|
||||
done(err, ee, event, args)
|
||||
}
|
||||
}
|
||||
44
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/package.json
generated
vendored
Normal file
44
node_modules/morgan/node_modules/on-finished/node_modules/ee-first/package.json
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"name": "ee-first",
|
||||
"description": "return the first event in a set of ee/event pairs",
|
||||
"version": "1.1.0",
|
||||
"author": {
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
},
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Douglas Christopher Wilson",
|
||||
"email": "doug@somethingdoug.com"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jonathanong/ee-first.git"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.2",
|
||||
"mocha": "1"
|
||||
},
|
||||
"files": [
|
||||
"index.js",
|
||||
"LICENSE"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec --bail --check-leaks test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|
||||
},
|
||||
"readme": "# EE First\r\n\r\n[![NPM version][npm-image]][npm-url]\r\n[![Build status][travis-image]][travis-url]\r\n[![Test coverage][coveralls-image]][coveralls-url]\r\n[![License][license-image]][license-url]\r\n[![Downloads][downloads-image]][downloads-url]\r\n[![Gittip][gittip-image]][gittip-url]\r\n\r\nGet the first event in a set of event emitters and event pairs,\r\nthen clean up after itself.\r\n\r\n## Install\r\n\r\n```sh\r\n$ npm install ee-first\r\n```\r\n\r\n## API\r\n\r\n```js\r\nvar first = require('ee-first')\r\n```\r\n\r\n### first(arr, listener)\r\n\r\nInvoke `listener` on the first event from the list specified in `arr`. `arr` is\r\nan array of arrays, with each array in the format `[ee, ...event]`. `listener`\r\nwill be called only once, the first time any of the given events are emitted. If\r\n`error` is one of the listened events, then if that fires first, the `listener`\r\nwill be given the `err` argument.\r\n\r\nThe `listener` is invoked as `listener(err, ee, event, args)`, where `err` is the\r\nfirst argument emitted from an `error` event, if applicable; `ee` is the event\r\nemitter that fired; `event` is the string event name that fired; and `args` is an\r\narray of the arguments that were emitted on the event.\r\n\r\n```js\r\nvar ee1 = new EventEmitter()\r\nvar ee2 = new EventEmitter()\r\n\r\nfirst([\r\n [ee1, 'close', 'end', 'error'],\r\n [ee2, 'error']\r\n], function (err, ee, event, args) {\r\n // listener invoked\r\n})\r\n```\r\n\r\n#### .cancel()\r\n\r\nThe group of listeners can be cancelled before being invoked and have all the event\r\nlisteners removed from the underlying event emitters.\r\n\r\n```js\r\nvar thunk = first([\r\n [ee1, 'close', 'end', 'error'],\r\n [ee2, 'error']\r\n], function (err, ee, event, args) {\r\n // listener invoked\r\n})\r\n\r\n// cancel and clean up\r\nthunk.cancel()\r\n```\r\n\r\n[npm-image]: https://img.shields.io/npm/v/ee-first.svg?style=flat-square\r\n[npm-url]: https://npmjs.org/package/ee-first\r\n[github-tag]: http://img.shields.io/github/tag/jonathanong/ee-first.svg?style=flat-square\r\n[github-url]: https://github.com/jonathanong/ee-first/tags\r\n[travis-image]: https://img.shields.io/travis/jonathanong/ee-first.svg?style=flat-square\r\n[travis-url]: https://travis-ci.org/jonathanong/ee-first\r\n[coveralls-image]: https://img.shields.io/coveralls/jonathanong/ee-first.svg?style=flat-square\r\n[coveralls-url]: https://coveralls.io/r/jonathanong/ee-first?branch=master\r\n[license-image]: http://img.shields.io/npm/l/ee-first.svg?style=flat-square\r\n[license-url]: LICENSE.md\r\n[downloads-image]: http://img.shields.io/npm/dm/ee-first.svg?style=flat-square\r\n[downloads-url]: https://npmjs.org/package/ee-first\r\n[gittip-image]: https://img.shields.io/gittip/jonathanong.svg?style=flat-square\r\n[gittip-url]: https://www.gittip.com/jonathanong/\r\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jonathanong/ee-first/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jonathanong/ee-first#readme",
|
||||
"_id": "ee-first@1.1.0",
|
||||
"_shasum": "6a0d7c6221e490feefd92ec3f441c9ce8cd097f4",
|
||||
"_resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.0.tgz",
|
||||
"_from": "ee-first@1.1.0"
|
||||
}
|
||||
51
node_modules/morgan/node_modules/on-finished/package.json
generated
vendored
Normal file
51
node_modules/morgan/node_modules/on-finished/package.json
generated
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
{
|
||||
"name": "on-finished",
|
||||
"description": "Execute a callback when a request closes, finishes, or errors",
|
||||
"version": "2.2.1",
|
||||
"contributors": [
|
||||
{
|
||||
"name": "Douglas Christopher Wilson",
|
||||
"email": "doug@somethingdoug.com"
|
||||
},
|
||||
{
|
||||
"name": "Jonathan Ong",
|
||||
"email": "me@jongleberry.com",
|
||||
"url": "http://jongleberry.com"
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/jshttp/on-finished.git"
|
||||
},
|
||||
"dependencies": {
|
||||
"ee-first": "1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"istanbul": "0.3.9",
|
||||
"mocha": "~2.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.8"
|
||||
},
|
||||
"files": [
|
||||
"HISTORY.md",
|
||||
"LICENSE",
|
||||
"index.js"
|
||||
],
|
||||
"scripts": {
|
||||
"test": "mocha --reporter spec --bail --check-leaks test/",
|
||||
"test-cov": "istanbul cover node_modules/mocha/bin/_mocha -- --reporter dot --check-leaks test/",
|
||||
"test-travis": "istanbul cover node_modules/mocha/bin/_mocha --report lcovonly -- --reporter spec --check-leaks test/"
|
||||
},
|
||||
"readme": "# on-finished\n\n[![NPM Version][npm-image]][npm-url]\n[![NPM Downloads][downloads-image]][downloads-url]\n[![Node.js Version][node-version-image]][node-version-url]\n[![Build Status][travis-image]][travis-url]\n[![Test Coverage][coveralls-image]][coveralls-url]\n\nExecute a callback when a request closes, finishes, or errors.\n\n## Install\n\n```sh\n$ npm install on-finished\n```\n\n## API\n\n```js\nvar onFinished = require('on-finished')\n```\n\n### onFinished(res, listener)\n\nAttach a listener to listen for the response to finish. The listener will\nbe invoked only once when the response finished. If the response finished\nto to an error, the first argument will contain the error. If the response\nhas already finished, the listener will be invoked.\n\nListening to the end of a response would be used to close things associated\nwith the response, like open files.\n\nListener is invoked as `listener(err, res)`.\n\n```js\nonFinished(res, function (err, res) {\n // clean up open fds, etc.\n // err contains the error is request error'd\n})\n```\n\n### onFinished(req, listener)\n\nAttach a listener to listen for the request to finish. The listener will\nbe invoked only once when the request finished. If the request finished\nto to an error, the first argument will contain the error. If the request\nhas already finished, the listener will be invoked.\n\nListening to the end of a request would be used to know when to continue\nafter reading the data.\n\nListener is invoked as `listener(err, req)`.\n\n```js\nvar data = ''\n\nreq.setEncoding('utf8')\nres.on('data', function (str) {\n data += str\n})\n\nonFinished(req, function (err, req) {\n // data is read unless there is err\n})\n```\n\n### onFinished.isFinished(res)\n\nDetermine if `res` is already finished. This would be useful to check and\nnot even start certain operations if the response has already finished.\n\n### onFinished.isFinished(req)\n\nDetermine if `req` is already finished. This would be useful to check and\nnot even start certain operations if the request has already finished.\n\n### Example\n\nThe following code ensures that file descriptors are always closed\nonce the response finishes.\n\n```js\nvar destroy = require('destroy')\nvar http = require('http')\nvar onFinished = require('on-finished')\n\nhttp.createServer(function onRequest(req, res) {\n var stream = fs.createReadStream('package.json')\n stream.pipe(res)\n onFinished(res, function (err) {\n destroy(stream)\n })\n})\n```\n\n## License\n\n[MIT](LICENSE)\n\n[npm-image]: https://img.shields.io/npm/v/on-finished.svg\n[npm-url]: https://npmjs.org/package/on-finished\n[node-version-image]: https://img.shields.io/node/v/on-finished.svg\n[node-version-url]: http://nodejs.org/download/\n[travis-image]: https://img.shields.io/travis/jshttp/on-finished/master.svg\n[travis-url]: https://travis-ci.org/jshttp/on-finished\n[coveralls-image]: https://img.shields.io/coveralls/jshttp/on-finished/master.svg\n[coveralls-url]: https://coveralls.io/r/jshttp/on-finished?branch=master\n[downloads-image]: https://img.shields.io/npm/dm/on-finished.svg\n[downloads-url]: https://npmjs.org/package/on-finished\n",
|
||||
"readmeFilename": "README.md",
|
||||
"bugs": {
|
||||
"url": "https://github.com/jshttp/on-finished/issues"
|
||||
},
|
||||
"homepage": "https://github.com/jshttp/on-finished#readme",
|
||||
"_id": "on-finished@2.2.1",
|
||||
"_shasum": "5c85c1cc36299f78029653f667f27b6b99ebc029",
|
||||
"_resolved": "https://registry.npmjs.org/on-finished/-/on-finished-2.2.1.tgz",
|
||||
"_from": "on-finished@>=2.2.1 <2.3.0"
|
||||
}
|
||||
56
node_modules/morgan/package.json
generated
vendored
Normal file
56
node_modules/morgan/package.json
generated
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user