https://github.com/alexcambose/queryfy
Utility to create query strings from objects
https://github.com/alexcambose/queryfy
javascript object parameters querystring request string web
Last synced: 3 months ago
JSON representation
Utility to create query strings from objects
- Host: GitHub
- URL: https://github.com/alexcambose/queryfy
- Owner: alexcambose
- License: mit
- Created: 2017-08-16T12:47:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-11-27T12:19:50.000Z (about 7 years ago)
- Last Synced: 2025-03-27T05:35:36.139Z (10 months ago)
- Topics: javascript, object, parameters, querystring, request, string, web
- Language: JavaScript
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# queryfy
[](https://travis-ci.org/alexcambose/queryfy)
## Install
```
bower install queryfy
```
```html
```
or
[npm](https://www.npmjs.com/package/queryfy)
```
npm install -S queryfy
```
## Usage
### Standard
```js
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
```js
const params = {
param1: 'This is param1',
param2: 'This is param2'
};
console.log(q.queryfy(params));
// param1=This%20is%20param1¶m2=This%20is%20param2
```
### Reversed
```js
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 `?`
```js
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' }
```