3 [![NPM Version][npm-image]][npm-url]
4 [![NPM Downloads][downloads-image]][downloads-url]
5 [![Node.js Version][node-version-image]][node-version-url]
6 [![Build Status][travis-image]][travis-url]
7 [![Test Coverage][coveralls-image]][coveralls-url]
20 var etag = require('etag')
23 ### etag(entity, [options])
25 Generate a strong ETag for the given entity. This should be the complete
26 body of the entity. Strings, `Buffer`s, and `fs.Stats` are accepted. By
27 default, a strong ETag is generated except for `fs.Stats`, which will
28 generate a weak ETag (this can be overwritten by `options.weak`).
31 res.setHeader('ETag', etag(body))
36 `etag` accepts these properties in the options object.
40 Specifies if a "strong" or a "weak" ETag will be generated. The ETag can only
41 really be a strong as the given input.
52 $ npm run-script bench
54 > etag@1.5.1 bench nodejs-etag
55 > node benchmark/index.js
57 > node benchmark/body0-100b.js
66 buffer - strong x 425,007 ops/sec ±1.47% (184 runs sampled)
67 * buffer - weak x 1,009,859 ops/sec ±0.18% (197 runs sampled)
68 string - strong x 442,096 ops/sec ±1.20% (181 runs sampled)
69 string - weak x 325,063 ops/sec ±0.31% (192 runs sampled)
71 > node benchmark/body1-1kb.js
80 buffer - strong x 263,069 ops/sec ±1.60% (190 runs sampled)
81 * buffer - weak x 295,732 ops/sec ±0.43% (199 runs sampled)
82 string - strong x 274,822 ops/sec ±1.15% (191 runs sampled)
83 string - weak x 169,473 ops/sec ±1.59% (194 runs sampled)
85 > node benchmark/body2-5kb.js
94 buffer - strong x 104,299 ops/sec ±0.60% (193 runs sampled)
95 * buffer - weak x 108,126 ops/sec ±0.65% (196 runs sampled)
96 string - strong x 101,736 ops/sec ±0.78% (194 runs sampled)
97 string - weak x 101,266 ops/sec ±0.85% (192 runs sampled)
99 > node benchmark/body3-10kb.js
108 buffer - strong x 59,007 ops/sec ±0.29% (198 runs sampled)
109 * buffer - weak x 60,968 ops/sec ±0.48% (197 runs sampled)
110 string - strong x 51,873 ops/sec ±1.78% (178 runs sampled)
111 string - weak x 52,307 ops/sec ±2.63% (193 runs sampled)
113 > node benchmark/body4-100kb.js
122 buffer - strong x 6,712 ops/sec ±0.11% (198 runs sampled)
123 * buffer - weak x 6,716 ops/sec ±0.50% (196 runs sampled)
124 string - strong x 6,397 ops/sec ±0.36% (196 runs sampled)
125 string - weak x 6,635 ops/sec ±0.15% (198 runs sampled)
132 [npm-image]: https://img.shields.io/npm/v/etag.svg?style=flat
133 [npm-url]: https://npmjs.org/package/etag
134 [node-version-image]: https://img.shields.io/node/v/etag.svg?style=flat
135 [node-version-url]: http://nodejs.org/download/
136 [travis-image]: https://img.shields.io/travis/jshttp/etag.svg?style=flat
137 [travis-url]: https://travis-ci.org/jshttp/etag
138 [coveralls-image]: https://img.shields.io/coveralls/jshttp/etag.svg?style=flat
139 [coveralls-url]: https://coveralls.io/r/jshttp/etag?branch=master
140 [downloads-image]: https://img.shields.io/npm/dm/etag.svg?style=flat
141 [downloads-url]: https://npmjs.org/package/etag