1
0
mirror of https://github.com/ascribe/onion.git synced 2024-12-22 17:33:14 +01:00

Use query-string instead of qs

Saves bytes, as done by rackt/history:
https://github.com/rackt/history/issues/121
This commit is contained in:
Brett Sun 2016-01-05 14:13:46 +01:00
parent c3f05861cc
commit af9d9132d2
2 changed files with 6 additions and 7 deletions

View File

@ -2,7 +2,7 @@
import camelCase from 'camelcase'; import camelCase from 'camelcase';
import decamelize from 'decamelize'; import decamelize from 'decamelize';
import qs from 'qs'; import queryString from 'query-string';
import { sanitize } from './general_utils'; import { sanitize } from './general_utils';
@ -36,8 +36,7 @@ export function argsToQueryParams(obj) {
queryParamObj[decamelize(key)] = sanitizedObj[key]; queryParamObj[decamelize(key)] = sanitizedObj[key];
}); });
// Use bracket arrayFormat as history.js and react-router use it return '?' + queryString.stringify(queryParamObj);
return '?' + qs.stringify(queryParamObj, { arrayFormat: 'brackets' });
} }
/** /**
@ -56,13 +55,13 @@ export function getCurrentQueryParams() {
* @return {object} Query params dictionary * @return {object} Query params dictionary
*/ */
export function queryParamsToArgs(queryParamString) { export function queryParamsToArgs(queryParamString) {
const qsQueryParamObj = qs.parse(queryParamString); const queryParamObj = queryString.parse(queryParamString);
const camelCaseParamObj = {}; const camelCaseParamObj = {};
Object Object
.keys(qsQueryParamObj) .keys(queryParamObj)
.forEach((key) => { .forEach((key) => {
camelCaseParamObj[camelCase(key)] = qsQueryParamObj[key]; camelCaseParamObj[camelCase(key)] = queryParamObj[key];
}); });
return camelCaseParamObj; return camelCaseParamObj;

View File

@ -75,7 +75,7 @@
"object-assign": "^2.0.0", "object-assign": "^2.0.0",
"opn": "^3.0.2", "opn": "^3.0.2",
"q": "^1.4.1", "q": "^1.4.1",
"qs": "^4.0.0", "query-string": "^3.0.0",
"raven-js": "^1.1.19", "raven-js": "^1.1.19",
"react": "0.13.2", "react": "0.13.2",
"react-bootstrap": "0.25.1", "react-bootstrap": "0.25.1",