Skip to content

parseUrlParam

Category
Last Changed
8月15日16时0分
Related

Parse URL query parameters into an object, with optional auto type conversion.

parseUrlParam is used to parse a URL query string into an object. It supports automatic conversion of string values to corresponding JS types (such as number, boolean, null, undefined, NaN, Infinity, etc.), or you can get only string values.

Scientific notation, binary, octal, hexadecimal and other special number formats will NOT be automatically converted.

Demo

Result:{ "a": "1", "b": "true", "c": "null", "d": "undefined", "e": "NaN", "f": "10.5", "g": "Infinity", "h": "test" }

Usage

ts
import parseUrlParam from 'comuse-shared/parseUrlParam'

const url = '?key1=100&key2=true&key3=null&key4=undefined&key5=NaN&key6=10.888&key7=Infinity&key8=test'

// Parse as string only
const result1 = parseUrlParam(url)
// { key1: '100', key2: 'true', key3: 'null', ... }

// Auto type conversion
const result2 = parseUrlParam(url, true)
// { key1: 100, key2: true, key3: null, ... }

Source

SourceDemoDocs

Changelog

v4.1.2 on 8/15/2025
d074e - feat: add function getQueryParam
v4.1.0 on 8/1/2025
ffe0c - feat: add useQRCode and useVSConsle

Released under the MIT License.