Deparam.js is a lightweight query string to JavaScript object converter
npm install --save deparam.js
import deparam from 'deparam.js';
deparam(...);
const deparam = require('deparam.js');
deparam(...);
<script src="deparam.js"></script>
<script>
deparam(...);
</script>
Deparam can convert simple as well as complex query strings to regular JavaScript objects. Examples are shown below:
deparam('?a=10&b=helloworld'); // --> { a: 10, b: 'helloworld'}
deparam('a=10&a=20&b=test&c=test2&x[]=45&x[]=99&y[a]=22&y[b]=33');
// --> { a: [10, 20], b: 'test', c: 'test2', x: [99, 22], y: { a: 22, b: 33 } }
Deparam enables type coercion by default. However this can have performance implications and it's better to disable it. You can do so by passing a flag.
deparam('a=10&b=20', false); // --> { a: '10', b: '20' }