queryfy
v1.1.1
Published
Utility to create query strings from objects
Downloads
7
Maintainers
Readme
queryfy
Install
bower install queryfy
<script src="bower_components/queryfy/index.js"></script>
or npm
npm install -S queryfy
Usage
Standard
const q = require('queryfy');
const params = {
param1: 'This is param1',
param2: 'This is param2'
};
const path = 'https://something.com/';
console.log(q.queryfy(path, params));
// https://something.com/?param1=This%20is%20param1¶m2=This%20is%20param2
or you can specify only the first argument with the query object
const params = {
param1: 'This is param1',
param2: 'This is param2'
};
console.log(q.queryfy(params));
// param1=This%20is%20param1¶m2=This%20is%20param2
Reversed
const q = require('queryfy');
const path = 'https://something.com/?param1=This%20is%20param1¶m2=This%20is%20param2';
console.log(q.deQueryfy(path));
// { param1: 'This is param1', param2: 'This is param2' }
it also supports only the query string with or without ?
console.log(q.deQueryfy('param1=This%20is%20param1¶m2=This%20is%20param2'));
// { param1: 'This is param1', param2: 'This is param2' }
console.log(q.deQueryfy('?param1=This%20is%20param1¶m2=This%20is%20param2'));
// { param1: 'This is param1', param2: 'This is param2' }