The SearchParamsParser is a specialized parser designed to safely extract and validate values from a URLSearchParams object. It simplifies access to URL search parameters in a type-safe manner and offers support for multiple input types (e.g., URLSearchParams, URL, Request, or URL strings).

  • URLSearchParams: Directly parses the given URLSearchParams object.
  • URL: Extracts the searchParams from the URL object.
  • Request: Parses the URL's search parameters from a Request object.
  • string: Parses the search parameters from a string representing a URL.
let url = new URL(request.url);
let parser = new SearchParamsParser(url.searchParams);
let url = new URL(request.url);
let parser = new SearchParamsParser(url);
let parser = new SearchParamsParser(request.url);
let parser = new SearchParamsParser(request);

Hierarchy (View Summary)

Constructors

Properties

Methods

Constructors

Properties

Methods

  • Retrieves the value associated with the specified search parameter.

    Parameters

    • key: string

      The name of the search parameter.

    Returns string

    The value associated with the key.

    If the key is missing from the search parameters.

  • Checks if a key exists in the search parameters.

    Parameters

    • key: string

      The name of the search parameter.

    Returns boolean

    true if the key exists, otherwise false.

  • Sets the value of a search parameter.

    If the key already exists, the value is replaced with the new value.

    Parameters

    • key: string

      The name of the search parameter.

    • value: string

      The value to set for the key.

    Returns void

    parser.set("username", "johndoe");