/** * {} * @author yutent * @date 2024/07/16 17:01:43 */ import { parse } from 'node:querystring' export function querystring(str) { let query = parse(str) for (let k of Object.keys(query)) { let val = query[k] if (k.endsWith('[]')) { let _k = k.slice(0, -2) query[_k] = val delete query[k] } else if (k.endsWith(']')) { let idx = k.lastIndexOf('[') let _pk = k.slice(0, idx) let _k = k.slice(idx + 1, -1) if (query[_pk]) { query[_pk][_k] = val } else { query[_pk] = { [_k]: val } } delete query[k] } } return query }