query-string-encode
Tiny query string serializer (~20 lines of code). Handles nested objects and arrays. Useful in combination with Fetch and XMLHttpRequest (for example).
Similar to jQuery's $.param
and qs.stringify()
Installation
npm i query-string-encode
or
yarn add query-string-encode
Usage
const queryStringEncode = ;
// Using with Fetch API;
Beware
Unlike serialized JSON, query strings are lossy. The only supported data type is string, so it's not possible to distinguishing between "true"
vs true
or 5
vs "5"
or ["a"]
vs {0:'a'}
. Using JSON is safer. This is an inherent problem with the format and applies to any query string serializer.