Package detail

tiny-etag

avoidwork192BSD-3-Clause4.0.5

ETag middleware for express.js API compatible routers

etag, middleware, http, rest

readme

tiny-etag

ETag middleware for express.js API compatible routers.

Using the factory

import {etag} from "tiny-etag";
const etags = etag({cacheSize: 500});
const router = SomeRouter(); /* express.js compatible router */

router.use(etags.middleware);

router.get("/", (req, res) => {
    const body = "Hello World!";

    res.writeHead(200, {"content-type": "text/plain", "etag": etags.create(body)});
    res.end(body);
});

Testing

Tiny ETag has 100% code coverage with its tests.

---------------|---------|----------|---------|---------|---------------------
File           | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
---------------|---------|----------|---------|---------|---------------------
All files      |     100 |    78.57 |     100 |     100 |                    
 tiny-etag.cjs |     100 |    78.57 |     100 |     100 | 45-49,59,91-109,115
---------------|---------|----------|---------|---------|---------------------

API

etag({cacheSize: 1000, cacheTTL: 0, seed: random, mimetype: "text/plain"})

Returns an tiny-etag instance. Cache TTL concerns do not spread with a notification.

create(arg = ""[, mimetype = "text/plain"])

Creates a strong ETag value from arg; a composite String is recommended. It's ideal to

hash(arg = ""[, mimetype="text/plain"])

Creates a hash of arg, uses create()

keep(arg)

Returns a boolean if arg should be kept on the cached Object

middleware(req, res, next)

Middleware to be used by an http framework

parse(arg)

Parses arg as a URL if it's a String, or constructs one if it is a socket

register(url, state)

Adds url to the cache

valid(headers)

Returns a Boolean indicating if caching is valid based on cache-control

License

Copyright (c) 2023 Jason Mulligan Licensed under the BSD-3 license

changelog

Changelog

All notable changes to this project will be documented in this file. Dates are displayed in UTC.

Generated by auto-changelog.

4.0.5

4.0.5

10 October 2023

  • Fixing middleware() such that it doesn't use extra parameters for res.send() d6069f8
  • Revert "Decoupling the middleware from a custom decorated method" fda1fc2
  • Generated CHANGELOG.md 4a0c531

4.0.4

10 October 2023

  • Caching content-type header for 304 responses d870760
  • Generating CHANGELOG.md f30b332

4.0.3

10 October 2023

  • Decoupling the middleware from a custom decorated method 688f45e
  • Generated CHANGELOG.md 801ddc4

4.0.2

10 October 2023

  • Bump woodland from 18.0.6 to 18.0.11 #15
  • Bump tiny-lru from 11.2.2 to 11.2.3 #14
  • Bump eslint from 8.50.0 to 8.51.0 #13
  • Bump rollup from 4.0.0 to 4.0.2 #12
  • Bump tiny-httptest from 4.0.5 to 4.0.6 #11
  • Bump woodland from 17.0.2 to 18.0.6 #10
  • Setting extension of main to .cjs for deprecated tooling da21e4e
  • Generating CHANGELOG.md 8a8684d

4.0.1

6 October 2023

  • Bump rollup from 3.29.4 to 4.0.0 #9
  • Fixing a regression of hash() such that the mimetype parameter wasn't used in latest iteration, updating README.md, reformatting imports ab8f7cf

4.0.0

5 October 2023

  • Updating dependencies, adding .github directory e9a003e
  • Updating dependencies, adding .github directory, WIP 82e27d2
  • Updating tests for 100% coverage, updating README.md, adding constants, removing utils and moving functions into ETag class, setting engines.node: ">= 17.0.0" in package.json 7c9bb7e

3.0.3

24 February 2023

  • Fixing regression in README.md example from 3.0.0 release, updating LICENSE, version bump to release 1e51d09
  • Generating new CHANGELOG.md 41342be

3.0.2

27 October 2022

3.0.1

24 September 2022

3.0.0

21 September 2022

  • Refactoring to an ES module #8
  • Initial changes to an es module d15afaf
  • Implementing esmodule syntax 0417eb6
  • Updating tests, fixing assignment of mmh3() 8d8c6d2

2.1.1

30 December 2020

  • Updating CHANGELOG.md d2064a5
  • Updating router dev dependency 2b61e06
  • Removing cache-control header on 304 responses dfbfa4a

2.1.0

27 December 2020

  • Swapping fifo for lru cache, removing grunt tool chain, updating dependencies 02f3f05
  • Adding auto-changelog dependency & generating CHANGELOG.md 38b4785

2.0.16

17 November 2019

  • Updating tiny-fifo dependency, updating dev dependencies b3b253d

2.0.15

26 January 2019

2.0.14

14 January 2019

  • Swapping LRU cache for FIFO cache bd6e3e7

2.0.13

13 January 2019

2.0.12

13 January 2019

2.0.11

13 January 2019

2.0.10

13 January 2019

  • Updating LRU cache & updating unregister() to call cache.delete(), refactoring valid() to use String.includes() c217b4d

2.0.9

4 January 2019

2.0.8

4 January 2019

  • Fixing registration from finish event d0e3401

2.0.7

4 January 2019

  • Fixing a regression in valid() 60e2732
  • Fixing middleware() & valid() dc0254f

2.0.6

4 January 2019

  • Fixing a regression in valid() ae3314d

2.0.5

3 January 2019

2.0.4

19 December 2018

2.0.3

12 December 2018

2.0.2

12 December 2018

2.0.1

12 December 2018

2.0.0

9 December 2018

  • Updating LRU cache, removing notification functionality (wrong place to attempt this) 4339089

1.5.16

8 December 2018

1.5.15

7 December 2018

1.5.14

5 December 2018

1.5.11

5 December 2018

1.5.10

5 December 2018

  • Updating LRU cache to get a breaking API change c03873b

1.5.9

5 December 2018

1.5.8

30 November 2018

1.5.7

27 November 2018

  • Updating LRU cache & router for testing 2b81ec6

1.5.6

26 November 2018

1.5.5

24 November 2018

1.5.4

24 November 2018

1.5.3

20 November 2018

1.5.2

20 November 2018

1.5.1

20 November 2018

1.5.0

28 October 2018

  • Creating new mimetype argument with a default value of text/plain, fixes #3 #3

1.4.9

29 July 2018

1.4.8

10 July 2018

  • Cleaning up everything 6ac2eee
  • Linting more files & fixing errors e20df70

1.4.7

8 July 2018

  • Binding the middleware function for JIT optimization, updating dependencies, updating copyright year 4002194

1.4.6

24 May 2018

  • Upgrading tiny-lru & woodland, updating travis-ci.org testing d2f6eb1

1.4.5

23 May 2018

1.4.4

23 May 2018

  • Updating LRU cache & setting expire property instead of ttl 1025bc1

1.4.3

23 April 2018

  • Updating retsu & tiny-parse dependencies 0d0dd23
  • Updating travis-ci.org configuration 4efa184

1.4.2

28 March 2018

1.4.1

25 March 2018

1.4.0

28 December 2017

  • Updating tiny-lru, adding cacheTTL config option, rewriting middleware() as a call() of etag(), updating eslint rules, refactoring middleware to rely on res.send() for http1/http2 interop via woodland (or other modules that attempt this) 05e48b8

1.3.13

3 December 2017

  • Updating retsu & tiny-parse c0c754c

1.3.12

13 November 2017

  • Changing middleware() & register() to minimize ops dc70fcc
  • Updating LRU cache b941161
  • Updating travis-ci.org configuration 40b2136

1.3.11

6 November 2017

  • Reverting Reflect.ownKeys() to Object.keys() because it doesn't need symbols in the enumeration bc5ac15

1.3.10

2 October 2017

1.3.9

1 October 2017

  • Not coercing while parsing the URL 860b3db

1.3.8

1 October 2017

  • Updating tiny-parse dependency 9db0c87

1.3.7

30 July 2017

  • Removing private from nonCachable regex because it's not for the destination (just intermediate caches) 1232936

1.3.6

26 July 2017

  • Removing must-revalidate from nonCachable 7e84136

1.3.5

26 July 2017

  • Fixing things for node.js 6.x 62e3228

1.3.4

26 July 2017

  • Misc tweaks to ensure ideal state for middleware 18ca202

1.3.3

13 May 2017

1.3.2

12 April 2017

  • Changing test frameworks, updating LRU cache 9f4fa1a
  • Version bump for release 84dfe6b

1.3.1

10 February 2017

1.3.0

6 February 2017

  • Creating this.valid() middleware for external testing of responses 1e0e95e

1.2.8

6 February 2017

  • Blocking generating an ETag for responses that can't be cached & adding tests, updating dependencies 09b0996

1.2.7

23 January 2017

1.2.6

6 January 2017

  • Changing Object.keys() to Reflect.ownKeys(), changing Array.forEach() to retsu.each(), updating travis-ci.org config, updating copyright year e2bb2af

1.2.5

5 January 2017

1.2.4

2 January 2017

1.2.3

21 December 2016

  • Updating tiny-parse to get better Authorization parsing 1dfd32e

1.2.2

20 November 2016

1.2.1

19 November 2016

1.2.0

19 November 2016

  • Upgrading tiny-lru to gain cache notifications 47f46db
  • Updating eslint rules fe40039

1.1.4

14 November 2016

  • Moving onchange() out of the prototype & into the instance 6409728

1.1.3

14 November 2016

1.1.2

14 November 2016

1.1.1

14 November 2016

1.1.0

14 November 2016

  • Creating onchange() which is called from register() & unregister() such that changes can propagate between caches (load balancing, etc.) 732c2a7

1.0.11

6 July 2016

  • Fixing what triggers a cache update such that the middleware might miss the first time, fixing cached timestamp over the lifespan of the cache item 49fc4c7

1.0.10

5 July 2016

  • Fixing cache life cycle, adding tests e8e024f

1.0.9

4 July 2016

  • Adding support for Buffer to hash() 44d6cdf

1.0.8

4 July 2016

1.0.7

4 July 2016

1.0.6

4 July 2016

  • Constructing headers because they might not be in Object form when finish fires de9cb5f

1.0.5

4 July 2016

1.0.4

4 July 2016

  • Removing ETag header from no-content, partial, error & redirect responses 6e8b2d4

1.0.3

4 July 2016

1.0.2

4 July 2016

  • Removing an unneeded development dependency 2ce73b3

1.0.1

4 July 2016

  • Removing unneeded dependencies 3e5efee

1.0.0

4 July 2016