1.1.5 • Published 6 years ago
jquerydeparam v1.1.5
JQuery deparam
JQuery deparam is a lightweight plugin that converts querystring to a JavaScript object
Installation
npm install --save jquerydeparam
Usage
ES6
import deparam from 'jquerydeparam';
deparam(...);
CommonJS
const deparam = require('jquerydeparam');
deparam(...);
Browser
deparam(...);
As JQuery plugin
import $ from 'jquery';
import 'jquerydeparam';
$.deparam(...);
Note: JQuery deparam is dependent on jquery. Therefore, if the package throws an error, you know what to do!
How it works?
Deparam converts simple and complex query strings into JavaScript objects. Examples are shown below:
#1 Simple query
var query = "key1=value1&key2=value2";
console.log(deparam(query));
Result:
{
key1: "value1",
key2: "value2"
}
#2 Complex query
var query = "flag=true&arr[]=Hello&arr[]=World&ob[key1]=value1&ob[key2]=value2";
console.log(deparam(query));
Result:
{
flag: true,
arr: [
"Hello",
"World"
],
ob: {
key1: "value1",
key2: "value2"
}
}