Skip to content

Commit

Permalink
add decode option to parseQS, export parseQS closes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
_gt3 committed Jun 16, 2017
1 parent 94af169 commit 2a01b11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { spec, miss, check, assignValues } from './router/spec'
export { match, toggle, toggleSelected } from './router/match'
export { parseQS } from './router/utils-path'
export { container } from './container'
export { Anchor } from './anchor'
3 changes: 2 additions & 1 deletion src/router/utils-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,13 @@ function parseHref(loc) {
return makeLocation(...extractQSHash(loc))
}

function parseQS(qs, ids, path = '', delim = ',') {
function parseQS(qs, ids, path = '', { delim = ',', decodeValues } = {}) {
if (qs[0] !== '?') qs = '?' + qs
let values = ids.map(id => {
let rx = new RegExp('[?&;]+' + escapeRx(id) + '=([^&;#]+)', 'i')
return qs.split(rx).slice(1).filter(s => /^[^&;#]/.test(s)).join(delim)
})
if (decodeValues) values = values.map(decode)
let slashes = new Array(ids.length).fill('/', path.slice(-1) === '/' ? 1 : 0)
return substitute([path, ...values], slashes)
}
Expand Down

0 comments on commit 2a01b11

Please sign in to comment.