deparam.js
TypeScript icon, indicating that this package has built-in type declarations

3.0.16 • Public • Published

GitHub package.json version GitHub Build Status

Deparam.js

Deparam.js is a lightweight query string to object converter

Install

npm i deparam.js

Usage

ES6

import deparam from 'deparam.js';
deparam(...);

CommonJS

const deparam = require('deparam.js');
deparam(...);

Browser

<script src="deparam.js"></script>
<script>
  deparam(...);
</script>

How it works?

Deparam can convert simple as well as complex query strings to regular JavaScript objects. Examples are shown below:

Simple string

deparam('?a=10&b=helloworld'); // --> { a: '10', b: 'helloworld'}

Complex string

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' } }

Enable type coercion

Deparam disables type coercion by default for performance reasons. To enable it you can pass an additional flag.

deparam('a=10&b=20&c=hello', true); // --> { a: 10, b: 20, c: 'hello' }

Package Sidebar

Install

npm i deparam.js

Weekly Downloads

236

Version

3.0.16

License

MIT

Unpacked Size

45.9 kB

Total Files

10

Last publish

Collaborators

  • scssyworks