stringifyQuery

Serialize a query parameters object into a query string, with options for how repeated array values are formatted in the output.

Usage

stringifyQuery serializes an object into a query string.

import { stringifyQuery } from '@movk/core'

stringifyQuery({ name: 'John', age: 30 })
// 'name=John&age=30'

stringifyQuery({ tags: ['a', 'b', 'c'] })
// 'tags=a&tags=b&tags=c'

stringifyQuery({ name: '中文' })
// 'name=%E4%B8%AD%E6%96%87'

stringifyQuery({ a: null, b: undefined, c: '' }, { skipNull: true, skipEmpty: true })
// ''

API

stringifyQuery(params, options?)

Serialize an object into a query string.

Parameters

params
QueryParams required
The query parameters object.
options
object
Serialization options.
options.skipNull
boolean
Skip null and undefined values.
options.skipEmpty
boolean
Skip empty strings.
options.arrayFormat
'repeat' | 'bracket' | 'index' | 'comma'
Array format: repeat (default), bracket, index, or comma.

Returns

returns
string
The query string (without the leading ?).

Changelog

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