append-query
Version:
Append querystring params to a URL.
75 lines (50 loc) • 1.97 kB
Markdown
[](https://travis-ci.org/lakenen/node-append-query)
Append querystring params to a URL.
```
npm install append-query
```
`appendQuery(url, query[, options])`
* **url** - a string URL to append to.
* **query** - a string or object containing query params to append.
* **options** (optional)
* **encodeComponents** - whether or not to encode appended passed params using `encodeURIComponent`. Default: true.
* **removeNull** - whether or not to remove params for null properties in the query object. Default: false (properties will be preserved with no value).
Example
```js
var appendQuery = require('append-query')
appendQuery('http://example.com/foo', 'bar=baz&beep=boop')
// http://example.com/foo?bar=baz&beep=boop
appendQuery('http://example.com/?foo=bar', 'hello=world')
// http://example.com/?foo=bar&hello=world
appendQuery('http://example.com/', { beep: 'boop' })
// http://example.com/?beep=boop
appendQuery('http://example.com/', { nothing: null })
// http://example.com/?nothing
// using pre-encoded values
appendQuery('http://example.com/', { preEncoded: '%22hello%2C%20world!%22' }, { encodeComponents: false })
// http://example.com/?preEncoded=%22hello%2C%20world!%22
// remove existing values
appendQuery('http://example.com/?test=1', { test: null }, { removeNull: true })
// http://example.com/
```
```
npm test
```
* **2.1.0**
- [
* **2.0.1**
- fix typo
* **2.0.0**
- fix [
- add options: `encodeComponents` and `removeNull`
* **1.1.0**
- add support for recursive serialization of nested objects
- add support for arrays as properties
([The MIT License](LICENSE))
Copyright 2014 Cameron Lakenen