1
Fork 0
mirror of https://github.com/pds-nest/nest.git synced 2024-11-23 05:24:18 +00:00
pds-2021-g2-nest/nest_frontend/utils/makeURLSearchParams.js

19 lines
416 B
JavaScript
Raw Normal View History

2021-05-12 02:10:36 +00:00
import isString from "is-string"
export default function makeURLSearchParams(obj) {
let usp = new URLSearchParams()
for(const key in obj) {
if(!obj.hasOwnProperty(key)) {
return
}
const value = obj[key]
if(isString(value)) {
usp.set(key, value)
}
else {
usp.set(key, JSON.stringify(value))
}
}
return usp
}