stringifyQuery

将对象序列化为查询字符串

用法

stringifyQuery 函数用于将对象序列化为查询字符串。

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?)

将对象序列化为查询字符串。

参数

params
QueryParams required
查询参数对象。
options
object
序列化选项。
options.skipNull
boolean
跳过 nullundefined 值。
options.skipEmpty
boolean
跳过空字符串。
options.arrayFormat
'repeat' | 'bracket' | 'index' | 'comma'
数组格式:repeat(默认)、bracketindexcomma

返回值

返回值
string
查询字符串(不含 ?)。

Changelog

7c832 — refactor!: 重构模块架构,拆分 utils 为专业化模块

Copyright © 2024 - 2026 YiXuan - MIT License