# @httpland/headers-utils

> Headers utility collection

Latest version **1.0.0** (published 2023-05-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install @httpland/headers-utils
pnpm add @httpland/headers-utils
yarn add @httpland/headers-utils
bun add @httpland/headers-utils
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-05-08 |
| First published | 2023-05-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 0 |
| Unpacked size | 22.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | miyauci |
| Keywords | http, headers, header, fetch, utility, utilities, collection |

## Links

- npm: https://www.npmjs.com/package/@httpland/headers-utils
- Repository: https://github.com/httpland/headers-utils
- Issues: https://github.com/httpland/headers-utils/issues
- npm.io page: https://npm.io/package/@httpland/headers-utils

## 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

- 1.0.0 (latest) — 2023-05-08
- 1.0.0-beta.1 (beta) — 2023-05-04

## README

# headers-utils

[![deno land](http://img.shields.io/badge/available%20on-deno.land/x-lightgrey.svg?logo=deno)](https://deno.land/x/headers_utils)
[![GitHub release (latest by date)](https://img.shields.io/github/v/release/httpland/headers-utils)](https://github.com/httpland/headers-utils/releases)
[![codecov](https://codecov.io/github/httpland/headers-utils/branch/main/graph/badge.svg)](https://codecov.io/gh/httpland/headers-utils)
[![GitHub](https://img.shields.io/github/license/httpland/headers-utils)](https://github.com/httpland/headers-utils/blob/main/LICENSE)

[![test](https://github.com/httpland/headers-utils/actions/workflows/test.yaml/badge.svg)](https://github.com/httpland/headers-utils/actions/workflows/test.yaml)
[![NPM](https://nodei.co/npm/@httpland/headers-utils.png?mini=true)](https://nodei.co/npm/@httpland/headers-utils/)

Headers utility collection.

## equalsHeaders

Check two `Headers` field name and field value equality.

```ts
import { equalsHeaders } from "https://deno.land/x/headers_utils@$VERSION/equal.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(equalsHeaders(new Headers({ a: "b" }), new Headers({ a: "b" })));
assertFalse(equalsHeaders(new Headers({ a: "b" }), new Headers({ c: "d" })));
```

## filterHeadersEntries

Returns a new `Headers` with all entries of the given headers except the ones
that do not match the given predicate.

```ts
import { filterHeadersEntries } from "https://deno.land/x/headers_utils@$VERSION/filter_entries.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

declare const isIMFDate: (input: string) => boolean;

const headers = filterHeadersEntries(
  new Headers({
    "date": "<date>",
    "content-type": "<content-type>",
  }),
  ([key, value]) => isIMFDate(value),
);

assert(headers.has("date"));
assert(headers.has("content-type"));
```

## filterHeadersKeys

Returns a new `Headers` with all entries of the given headers except the ones
that have a key(field name) that does not match the given predicate.

```ts
import { filterHeadersKeys } from "https://deno.land/x/headers_utils@$VERSION/filter_keys.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

const headers = filterHeadersKeys(
  new Headers({
    "date": "<date>",
    "content-type": "<content-type>",
  }),
  (key) => key.startsWith("content"),
);

assert(headers.has("content-type"));
assertFalse(headers.has("date"));
```

## filterHeadersValues

Returns a new `Headers` with all entries of the given headers except the ones
that have a value(field value) that does not match the given predicate.

```ts
import { filterHeadersValues } from "https://deno.land/x/headers_utils@$VERSION/filter_values.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

declare const isIMFDate: (input: string) => boolean;

const headers = filterHeadersValues(
  new Headers({
    "date": "<date>",
    "content-type": "<content-type>",
  }),
  isIMFDate,
);

assert(headers.has("date"));
assertFalse(headers.has("content-type"));
```

## isHeaders

Whether the input is `Headers` or not.

```ts
import { isHeaders } from "https://deno.land/x/headers_utils@$VERSION/is.ts";
import { assert, assertFalse } from "https://deno.land/std/testing/asserts.ts";

assert(isHeaders(new Headers()));
assertFalse(isHeaders({}));
```

## stringifyHeaders

Serialize `Headers` into string.

```ts
import { stringifyHeaders } from "https://deno.land/x/headers_utils@$VERSION/stringify.ts";
import { assertEquals } from "https://deno.land/std/testing/asserts.ts";

assertEquals(stringifyHeaders(new Headers()), "");
assertEquals(
  stringifyHeaders(
    new Headers({
      "content-type": "text/plain",
      "date": "Wed, 21 Oct 2015 07:28:00 GMT",
    }),
  ),
  `content-type: text/plain
date: Wed, 21 Oct 2015 07:28:00 GMT`,
);
```

## API

All APIs can be found in the [deno doc](https://deno.land/x/headers_utils?doc).

## License

Copyright © 2023-present [httpland](https://github.com/httpland).

Released under the [MIT](./LICENSE) license

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