Function getSingleQueryParam

Returns the first value for the specified key in the query object. If pred specified, returns the first value that meets it.


返り値は、指定した key に対応するパラメータのうち最初の値。 もし pred が指定されている場合は、その関数に合格した値のうち最初のものが返る。

getSingleQueryParam({},            "id") === undefined
getSingleQueryParam({ id: "aaa" }, "id") === "aaa"

// with pred specified
const is_a = (s: string) => s === "a"
getSingleQueryParam({ id: "a" }, "id", is_a) === "a"
getSingleQueryParam({}, "id", is_a) === undefined
getSingleQueryParam({ id: "b" }, "id", is_a) === undefined
getSingleQueryParam({ id: ["b", "a"] }, "id", is_a) === "a"

optional. the first value that fits this predicate will be returned.

  • Type Parameters

    • T extends string

    Parameters

    • query: ParsedUrlQuery
    • key: string
    • pred: ((s: string) => s is T)
        • (s): s is T
        • Parameters

          • s: string

          Returns s is T

    Returns T | undefined

  • Parameters

    • query: ParsedUrlQuery
    • key: string
    • Optionalpred: ((s: string) => boolean)
        • (s): boolean
        • Parameters

          • s: string

          Returns boolean

    Returns string | undefined