[Pkg-javascript-commits] [node-response-time] 01/06: Imported Upstream version 2.2.0

Leo Iannacone l3on-guest at moszumanska.debian.org
Sat Oct 11 17:02:26 UTC 2014


This is an automated email from the git hooks/post-receive script.

l3on-guest pushed a commit to branch master
in repository node-response-time.

commit 8d6422b9ca31df88e6e12da0def43a033bc14ada
Author: Leo Iannacone <l3on at ubuntu.com>
Date:   Sat Oct 11 18:54:38 2014 +0200

    Imported Upstream version 2.2.0
---
 .npmignore   |  2 --
 .travis.yml  |  1 +
 HISTORY.md   | 17 ++++++++++++
 LICENSE      | 23 ++++++++++++++++
 README.md    | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++----------
 index.js     | 45 ++++++++++++++++++++++++-------
 package.json | 47 ++++++++++++++++-----------------
 test/test.js | 71 +++++++++++++++++++++++++++++++++++++++++++++++--
 8 files changed, 241 insertions(+), 51 deletions(-)

diff --git a/.npmignore b/.npmignore
deleted file mode 100644
index ac0bfb9..0000000
--- a/.npmignore
+++ /dev/null
@@ -1,2 +0,0 @@
-test/
-.travis.yml
diff --git a/.travis.yml b/.travis.yml
index bb47c1b..bdd4e73 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,3 +8,4 @@ matrix:
     - node_js: "0.11"
   fast_finish: true
 script: "npm run-script test-travis"
+after_script: "test $TRAVIS_NODE_VERSION = '0.10' && npm install coveralls at 2.11.1 && cat ./coverage/lcov.info | coveralls"
diff --git a/HISTORY.md b/HISTORY.md
index 80ff2dd..5b0c04e 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -1,3 +1,20 @@
+2.2.0 / 2014-09-22
+==================
+
+  * Add `suffix` option
+  * deps: depd@~1.0.0
+
+2.1.0 / 2014-09-16
+==================
+
+  * Add `header` option for custom header name
+  * Change `digits` argument to an `options` argument
+
+2.0.1 / 2014-08-10
+==================
+
+  * deps: on-headers@~1.0.0
+
 2.0.0 / 2014-05-31
 ==================
 
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..53e49a3
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,23 @@
+(The MIT License)
+
+Copyright (c) 2014 Jonathan Ong <me at jongleberry.com>
+Copyright (c) 2014 Douglas Christopher Wilson <doug at 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.
diff --git a/README.md b/README.md
index 02a7cbb..4382a42 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,12 @@
 # response-time
 
-[![NPM version](https://badge.fury.io/js/response-time.svg)](https://badge.fury.io/js/response-time)
-[![Build Status](https://travis-ci.org/expressjs/response-time.svg?branch=master)](https://travis-ci.org/expressjs/response-time)
+[![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]
 
-Response time middleware extracted from connect.
+Response time header for node.js
 
 ## Installation
 
@@ -15,25 +18,80 @@ $ npm install response-time
 
 ```js
 var responseTime = require('response-time')
-
-// time starts ticking from the moment req goes through the middleware
-app.use(responseTime(5))
 ```
 
-### responseTime(digits)
+### responseTime(options)
 
 Returns middleware that adds a `X-Response-Time` header to responses.
 
-- `digits` - the fixed number of digits to include. (default: `3`)
+#### Options
 
-## License
+`responseTime` accepts these properties in the options object.
+
+##### digits
+
+The fixed number of digits to include in the output, which is always in
+milliseconds, defaults to `3` (ex: `2.300ms`).
+
+##### header
+
+The name of the header to set, defaults to `X-Response-Time`.
 
-The MIT License (MIT)
+##### suffix
+
+Boolean to indicate if units of measurement suffix should be added to
+the output, defaults to `true` (ex: `2.300ms` vs `2.300`).
+
+## Examples
+
+### express/connect
+
+```js
+var express = require('express')
+var responseTime = require('response-time')
 
-Copyright (c) 2014 Jonathan Ong me at jongleberry.com
+var app = express()
 
-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:
+app.use(responseTime())
 
-The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+app.get('/', function (req, res) {
+  res.send('hello, world!')
+})
+```
+
+### vanilla http server
+
+```js
+var finalhandler = require('finalhandler')
+var http = require('http')
+var responseTime = require('response-time')
+
+// create "middleware"
+var _responseTime = responseTime()
+
+http.createServer(function (req, res) {
+  var done = finalhandler(req, res)
+  _responseTime(req, res, function (err) {
+    if (err) return done(err)
+
+    // respond to request
+    res.setHeader('content-type', 'text/plain')
+    res.end('hello, world!')
+  })
+})
+```
+
+## License
 
-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.
\ No newline at end of file
+[MIT](LICENSE)
+
+[npm-image]: https://img.shields.io/npm/v/response-time.svg?style=flat
+[npm-url]: https://npmjs.org/package/response-time
+[travis-image]: https://img.shields.io/travis/expressjs/response-time.svg?style=flat
+[travis-url]: https://travis-ci.org/expressjs/response-time
+[coveralls-image]: https://img.shields.io/coveralls/expressjs/response-time.svg?style=flat
+[coveralls-url]: https://coveralls.io/r/expressjs/response-time?branch=master
+[downloads-image]: https://img.shields.io/npm/dm/response-time.svg?style=flat
+[downloads-url]: https://npmjs.org/package/response-time
+[gratipay-image]: https://img.shields.io/gratipay/dougwilson.svg?style=flat
+[gratipay-url]: https://www.gratipay.com/dougwilson/
diff --git a/index.js b/index.js
index 7d743fc..6df74a8 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,8 @@
-
 /*!
- * Connect - responseTime
+ * response-time
  * Copyright(c) 2011 TJ Holowaychuk
+ * Copyright(c) 2014 Jonathan Ong
+ * Copyright(c) 2014 Douglas Christopher Wilson
  * MIT Licensed
  */
 
@@ -9,6 +10,7 @@
  * Module dependencies
  */
 
+var deprecate = require('depd')('response-time')
 var onHeaders = require('on-headers')
 
 /**
@@ -17,26 +19,51 @@ var onHeaders = require('on-headers')
  * Adds the `X-Response-Time` header displaying the response
  * duration in milliseconds.
  *
- * @param {number} [digits=3]
+ * @param {object} [options]
+ * @param {number} [options.digits=3]
  * @return {function}
  * @api public
  */
 
-module.exports = function responseTime(digits) {
-  digits = digits === undefined
-    ? 3
-    : digits
+module.exports = function responseTime(options) {
+  if (typeof options === 'number') {
+    // back-compat single number argument
+    deprecate('number argument: use {digits: ' + JSON.stringify(options) + '} instead')
+    options = { digits: options }
+  }
+
+  options = options || {}
+
+  // response time digits
+  var digits = options.digits !== undefined
+    ? options.digits
+    : 3
+
+  // header name
+  var header = options.header || 'X-Response-Time'
+
+  // display suffix
+  var suffix = options.suffix !== undefined
+    ? Boolean(options.suffix)
+    : true
 
   return function responseTime(req, res, next) {
     var startAt = process.hrtime()
 
     onHeaders(res, function () {
-      if (this.getHeader('X-Response-Time')) return;
+      if (this.getHeader(header)) {
+        return
+      }
 
       var diff = process.hrtime(startAt)
       var ms = diff[0] * 1e3 + diff[1] * 1e-6
+      var val = ms.toFixed(digits)
+
+      if (suffix) {
+        val += 'ms'
+      }
 
-      this.setHeader('X-Response-Time', ms.toFixed(digits) + 'ms')
+      this.setHeader(header, val)
     })
 
     next()
diff --git a/package.json b/package.json
index b19085a..d3f54fc 100644
--- a/package.json
+++ b/package.json
@@ -1,40 +1,39 @@
 {
   "name": "response-time",
-  "description": "X-Response-Time header for node.js",
-  "version": "2.0.0",
-  "author": {
-    "name": "Jonathan Ong",
-    "email": "me at jongleberry.com",
-    "url": "http://jongleberry.com",
-    "twitter": "https://twitter.com/jongleberry"
-  },
+  "description": "Response time header for node.js",
+  "version": "2.2.0",
+  "author": "Jonathan Ong <me at jongleberry.com> (http://jongleberry.com)",
   "contributors": [
-    {
-      "name": "Douglas Christopher Wilson",
-      "email": "doug at somethingdoug.com"
-    }
+    "Douglas Christopher Wilson <doug at somethingdoug.com>"
   ],
   "license": "MIT",
-  "repository": {
-    "type": "git",
-    "url": "https://github.com/expressjs/response-time.git"
-  },
-  "bugs": {
-    "mail": "me at jongleberry.com",
-    "url": "https://github.com/expressjs/response-time/issues"
-  },
+  "keywords": [
+    "http",
+    "res",
+    "response time",
+    "x-response-time"
+  ],
+  "repository": "expressjs/response-time",
   "dependencies": {
-    "on-headers": "0.0.0"
+    "depd": "~1.0.0",
+    "on-headers": "~1.0.0"
   },
   "devDependencies": {
-    "mocha": "~1.20.0",
+    "istanbul": "0.3.2",
+    "mocha": "~1.21.4",
     "supertest": "~0.13.0"
   },
+  "files": [
+    "LICENSE",
+    "HISTORY.md",
+    "index.js"
+  ],
   "engines": {
     "node": ">= 0.8.0"
   },
   "scripts": {
-    "test": "mocha --reporter dot",
-    "test-travis": "mocha --reporter spec"
+    "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/"
   }
 }
diff --git a/test/test.js b/test/test.js
index 977614e..ec08355 100644
--- a/test/test.js
+++ b/test/test.js
@@ -1,3 +1,6 @@
+
+process.env.NO_DEPRECATION = 'response-time'
+
 var http = require('http');
 var request = require('supertest');
 var responseTime = require('..')
@@ -28,6 +31,13 @@ describe('responseTime()', function () {
       .expect('X-Response-Time', /^[0-9]+\.[0-9]{3}ms$/, done)
     })
 
+    it('should allow custom digits', function (done) {
+      var server = createServer(5)
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9]+\.[0-9]{5}ms$/, done)
+    })
+
     it('should allow no digits', function (done) {
       var server = createServer(0)
       request(server)
@@ -37,8 +47,65 @@ describe('responseTime()', function () {
   })
 })
 
-function createServer(digits, fn) {
-  var _responseTime = responseTime(digits)
+describe('responseTime(options)', function () {
+  describe('with "digits" option', function () {
+    it('should default to 3', function (done) {
+      var server = createServer()
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9]+\.[0-9]{3}ms$/, done)
+    })
+
+    it('should allow custom digits', function (done) {
+      var server = createServer({ digits: 5 })
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9]+\.[0-9]{5}ms$/, done)
+    })
+
+    it('should allow no digits', function (done) {
+      var server = createServer({ digits: 0 })
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9]+ms$/, done)
+    })
+  })
+
+  describe('with "header" option', function () {
+    it('should default to X-Response-Time', function (done) {
+      var server = createServer()
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9\.]+ms$/, done)
+    })
+
+    it('should allow custom header name', function (done) {
+      var server = createServer({ header: 'X-Time-Taken' })
+      request(server)
+      .get('/')
+      .expect('X-Time-Taken', /^[0-9\.]+ms$/, done)
+    })
+  })
+
+  describe('with "suffix" option', function () {
+    it('should default to true', function (done) {
+      var server = createServer()
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9\.]+ms$/, done)
+    })
+
+    it('should allow disabling suffix', function (done) {
+      var server = createServer({ suffix: false })
+      request(server)
+      .get('/')
+      .expect('X-Response-Time', /^[0-9\.]+$/, done)
+    })
+  })
+})
+
+function createServer(opts, fn) {
+  var _responseTime = responseTime(opts)
   return http.createServer(function (req, res) {
     _responseTime(req, res, function (err) {
       setTimeout(function () {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-response-time.git



More information about the Pkg-javascript-commits mailing list