query-extend

like _.extend, just for url queries.

query-extend

Like _.extend, just for URL queries.

 
var queryExtend = require('query-extend');
 
queryExtend('http://foo.com', { per_page: 20, page: 1 });
// => http://foo.com?per_page=20&page=1 
 
queryExtend('http://foo.com?per_page=10', { per_page: 20, page: 1 });
// => http://foo.com?per_page=20&page=1 
 
queryExtend('http://foo.com?per_page=10', { per_page: 20, tags: ['shoes', 'shirts'] });
// => http://foo.com?per_page=20&tags[]=shoes&tags[]=shirts 
 
queryExtend('http://foo.com?per_page=10', '?per_page=50');
// => http://foo.com?per_page=50 
 
queryExtend('http://foo.com?per_page=10', '?per_page=50', { per_page: 20 });
// => http://foo.com?per_page=20 
 
// Passing in 'true' as last parameter makes 
// queryExtend return the result as Object 
queryExtend('?per_page=10', '?per_page=50', true);
// => { per_page: '50' } 
 
// ... I think you get it.. :) 
 

npm install query-extend

bower install query-extend

  1. Setup: Run npm install.

  2. Testing: Run npm test to see if the tests pass.

  3. Minify: Run gulp.

Copyright (c) 2014 Simon Kusterer Licensed under the MIT license.