# tiny-etag

> ETag middleware for express.js API compatible routers

Latest version **4.0.5** (published 2023-10-11) · BSD-3-Clause license · 0 weekly downloads

## Install

```sh
npm install tiny-etag
pnpm add tiny-etag
yarn add tiny-etag
bun add tiny-etag
```

## Health

**Score 45/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.5 |
| Published | 2023-10-11 |
| First published | 2016-07-04 |
| Weekly downloads | 0 |
| License | BSD-3-Clause |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=17.0.0 |
| Dependencies | 1 |
| Unpacked size | 12.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Jason Mulligan |
| Maintainers | avoidwork |
| Keywords | etag, middleware, http, rest, api |

## Links

- npm: https://www.npmjs.com/package/tiny-etag
- Repository: https://github.com/avoidwork/tiny-etag
- Homepage: http://avoidwork.github.io/tiny-etag/
- Issues: https://github.com/avoidwork/tiny-etag/issues
- npm.io page: https://npm.io/package/tiny-etag

## Dependencies (1)

- [tiny-lru](https://npm.io/package/tiny-lru.md) ^11.2.2

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 4.0.5 (latest) — 2023-10-11
- 4.0.4 — 2023-10-11
- 4.0.3 — 2023-10-10
- 4.0.2 — 2023-10-10
- 4.0.1 — 2023-10-06
- 4.0.0 — 2023-10-05
- 3.0.3 — 2023-02-24
- 3.0.2 — 2022-10-28
- 3.0.1 — 2022-09-24
- 3.0.0 — 2022-09-22
- 2.1.1 — 2020-12-30
- 2.1.0 — 2020-12-27
- 2.0.16 — 2019-11-17
- 2.0.15 — 2019-01-26
- 2.0.14 — 2019-01-15
- … 76 more at https://npm.io/package/tiny-etag/versions

## README

# tiny-etag

ETag middleware for express.js API compatible routers.

## Using the factory

```javascript
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.

```console
---------------|---------|----------|---------|---------|---------------------
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

---
_Source: https://npm.io/package/tiny-etag · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
