Skip to main content
Latest
function filterKeys
import { filterKeys } from "https://deno.land/x/etag_middleware@1.1.0/deps.ts";

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

Examples

Example 1

import { filterKeys } from "https://deno.land/x/http_utils@$VERSION/header.ts";
import { assert } from "https://deno.land/std@$VERSION/testing/asserts.ts";

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

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

Parameters

headers: Headers
predicate: (key: string) => boolean