util.jsView |
---|
1 | 1 | var URL = require('url') |
2 | | -var QS = require('querystring') |
| 2 | +var QS = require('qs') |
3 | 3 | var hyperscript = require('hyperscript') |
4 | 4 | var cpara = require('cont').para |
5 | 5 | var pull = require('pull-stream') |
6 | 6 | var paramap = require('pull-paramap') |
22 | 22 | function isString (s) { |
23 | 23 | return 'string' === typeof s |
24 | 24 | } |
25 | 25 | |
| 26 | +function cleanOpts (opts) { |
| 27 | + return (function copy (opts) { |
| 28 | + var o = undefined |
| 29 | + if(opts && 'object' === typeof opts) |
| 30 | + for(var k in opts) { |
| 31 | + if('undefined' !== typeof opts[k]) { |
| 32 | + var v = copy(opts[k]) |
| 33 | + if('undefined' !== typeof v) { |
| 34 | + o = o || {} |
| 35 | + o[k] = v |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + else |
| 40 | + return opts |
| 41 | + return o |
| 42 | + })(opts) |
| 43 | +} |
| 44 | + |
| 45 | +function encodeOpts (opts) { |
| 46 | + opts = cleanOpts(opts) |
| 47 | + return opts ? '?'+QS.stringify(opts) : '' |
| 48 | +} |
| 49 | + |
| 50 | +exports.cleanOpts = cleanOpts |
| 51 | + |
26 | 52 | exports.toUrl = function toUrl(path, opts) { |
27 | 53 | return '/'+( |
28 | 54 | Array.isArray(path) ? path.join('/') : ''+path |
29 | | - ) + ( |
30 | | - !isEmpty(opts) ? '?'+QS.encode(opts) : '' |
31 | | - ) |
| 55 | + ) + encodeOpts(opts) |
32 | 56 | } |
33 | 57 | exports.h = function () { |
34 | 58 | return [].slice.call(arguments) |
35 | 59 | } |
219 | 243 | |
220 | 244 | |
221 | 245 | |
222 | 246 | |
| 247 | + |
| 248 | + |
| 249 | + |
| 250 | + |
| 251 | + |
| 252 | + |
| 253 | + |