baobab-router
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -78,3 +78,3 @@ 'use strict'; | ||
}).map(function (k) { | ||
return escape(k) + '=' + escape(qry[k]); | ||
return escape(k) + '=' + escape(_typeof(qry[k]) === 'object' && qry[k] ? JSON.stringify(qry[k]) : '' + qry[k]); | ||
}).join('&'); | ||
@@ -521,13 +521,20 @@ | ||
var query = (route.query || {})[arr[0]] || {}; | ||
var value = undefined; | ||
var value = unescape(arr[1]); | ||
switch (query.cast) { | ||
case 'number': | ||
value = +arr[1]; | ||
value = +value; | ||
break; | ||
case 'boolean': | ||
value = arr[1] === 'true' ? true : false; | ||
value = value === 'true' ? true : false; | ||
break; | ||
case 'json': | ||
try { | ||
value = value ? JSON.parse(value) : null; | ||
} catch (e) { | ||
value = null; | ||
} | ||
break; | ||
default: | ||
value = arr[1]; | ||
// Nothing actually... | ||
} | ||
@@ -758,3 +765,3 @@ | ||
// Baobab-Router version: | ||
BaobabRouter.version = '2.1.0'; | ||
BaobabRouter.version = '2.2.0'; | ||
@@ -761,0 +768,0 @@ // Expose private methods for unit testing: |
@@ -71,3 +71,7 @@ /** | ||
.filter(k => qry[k] !== null && qry[k] !== undefined) | ||
.map(k => escape(k) + '=' + escape(qry[k])) | ||
.map(k => escape(k) + '=' + escape( | ||
(typeof qry[k] === 'object' && qry[k]) ? | ||
JSON.stringify(qry[k]) : | ||
('' + qry[k]) | ||
)) | ||
.join('&'); | ||
@@ -559,13 +563,22 @@ | ||
const query = (route.query || {})[arr[0]] || {}; | ||
let value; | ||
let value = unescape(arr[1]); | ||
switch (query.cast) { | ||
case 'number': | ||
value = +arr[1]; | ||
value = +value; | ||
break; | ||
case 'boolean': | ||
value = arr[1] === 'true' ? true : false; | ||
value = value === 'true' ? true : false; | ||
break; | ||
case 'json': | ||
try { | ||
value = value ? | ||
JSON.parse(value) : | ||
null; | ||
} catch (e) { | ||
value = null; | ||
} | ||
break; | ||
default: | ||
value = arr[1]; | ||
// Nothing actually... | ||
} | ||
@@ -818,3 +831,3 @@ | ||
// Baobab-Router version: | ||
BaobabRouter.version = '2.1.0'; | ||
BaobabRouter.version = '2.2.0'; | ||
@@ -821,0 +834,0 @@ // Expose private methods for unit testing: |
{ | ||
"name": "baobab-router", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "A router for Baobab", | ||
@@ -5,0 +5,0 @@ "main": "baobab-router.dist.js", |
63648
1437