Skip to main content
Module

x/http_utils/mod.ts>filterKeys

HTTP utility collection for Fetch API
Go to Latest
function filterKeys
import { filterKeys } from "https://deno.land/x/http_utils@1.0.0-beta.15/mod.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/mod.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