getQueryParam

Read a single query parameter value from a URL by key, returning the first match or null when the parameter is not present.

Usage

getQueryParam retrieves the value of a specific query parameter from a URL.

import { getQueryParam } from '@movk/core'

getQueryParam('https://example.com?name=John&age=30', 'name')
// 'John'

getQueryParam('https://example.com?tags=a&tags=b', 'tags')
// 'a' (returns the first value)

getQueryParam('https://example.com', 'name')
// null

API

getQueryParam(url, key)

Get the value of a specific query parameter from a URL.

Parameters

url
string required
The URL string.
key
string required
The parameter key.

Returns

returns
string | null
The parameter value, or null if not present.

Note

  • If the parameter has multiple values, only the first is returned.
  • Use getQueryParams to retrieve all values.

Changelog

No recent changes
Copyright © 2024 - 2026 YiXuan - MIT License