{"action":"created","issue":{"url":"https://api.github.com/repos/medialize/URI.js/issues/262","labels_url":"https://api.github.com/repos/medialize/URI.js/issues/262/labels{/name}","comments_url":"https://api.github.com/repos/medialize/URI.js/issues/262/comments","events_url":"https://api.github.com/repos/medialize/URI.js/issues/262/events","html_url":"https://github.com/medialize/URI.js/issues/262","id":116441674,"number":262,"title":"Easiest way to filter query parameters","user":{"login":"justinmchase","id":10974,"avatar_url":"https://avatars.githubusercontent.com/u/10974?v=3","gravatar_id":"","url":"https://api.github.com/users/justinmchase","html_url":"https://github.com/justinmchase","followers_url":"https://api.github.com/users/justinmchase/followers","following_url":"https://api.github.com/users/justinmchase/following{/other_user}","gists_url":"https://api.github.com/users/justinmchase/gists{/gist_id}","starred_url":"https://api.github.com/users/justinmchase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinmchase/subscriptions","organizations_url":"https://api.github.com/users/justinmchase/orgs","repos_url":"https://api.github.com/users/justinmchase/repos","events_url":"https://api.github.com/users/justinmchase/events{/privacy}","received_events_url":"https://api.github.com/users/justinmchase/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-11T23:11:04Z","updated_at":"2015-11-11T23:21:54Z","closed_at":null,"body":"Suppose I want to remove all query parameters *except* a few from a whitelist. Is there a one-line way to do this? Or what is the easiest way currently?\r\n\r\nFor example, I would like to:\r\n```\r\nvar u = URI('http://example.com/foo?a=1&b=2&c=3');\r\nu.filterQuery('a');\r\nassert.equal('http://example.com/foo?a=1', u.toString());\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/medialize/URI.js/issues/comments/155941153","html_url":"https://github.com/medialize/URI.js/issues/262#issuecomment-155941153","issue_url":"https://api.github.com/repos/medialize/URI.js/issues/262","id":155941153,"user":{"login":"rodneyrehm","id":186837,"avatar_url":"https://avatars.githubusercontent.com/u/186837?v=3","gravatar_id":"","url":"https://api.github.com/users/rodneyrehm","html_url":"https://github.com/rodneyrehm","followers_url":"https://api.github.com/users/rodneyrehm/followers","following_url":"https://api.github.com/users/rodneyrehm/following{/other_user}","gists_url":"https://api.github.com/users/rodneyrehm/gists{/gist_id}","starred_url":"https://api.github.com/users/rodneyrehm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rodneyrehm/subscriptions","organizations_url":"https://api.github.com/users/rodneyrehm/orgs","repos_url":"https://api.github.com/users/rodneyrehm/repos","events_url":"https://api.github.com/users/rodneyrehm/events{/privacy}","received_events_url":"https://api.github.com/users/rodneyrehm/received_events","type":"User","site_admin":false},"created_at":"2015-11-11T23:21:54Z","updated_at":"2015-11-11T23:21:54Z","body":"There is no built-in way to filter the query data, but `.query()` accepts a callable that could be used for that. I guess best utility to filter the parsed query data object would be [`_.pick()`](http://underscorejs.org/#pick). For example:\r\n\r\n```js\r\n// using underscore\r\nvar filterQuery = function(data) {\r\n  return _.pick(data, 'a');\r\n};\r\n\r\n// no underscore at hand\r\nvar filterQuery = function(data) {\r\n  var _data = {};\r\n  ['a'].forEach(function(key) {\r\n    _data[key] = data[key];\r\n  });\r\n  return _data;\r\n};\r\n\r\nURI('http://example.com/foo?a=1&b=2&c=3').query(filterQuery).toString();\r\n```"}}