UNPKG

@siren-js/client

Version:
12 lines (11 loc) 543 B
import { isString } from 'class-validator'; /** * Transforms an array of {@linkcode NameValuePair} objects into a * [`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) * object. If the value is a [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) * object, its `name` is used. */ export const serializeUrlEncodedForm = (nameValues) => nameValues.reduce((params, [name, value]) => { params.append(name, isString(value) ? value : value.name); return params; }, new URLSearchParams());