# querystring-helpers

> Querystring helpers for reading and setting parameters (TypeScript types included)

Latest version **1.0.2** (published 2019-03-29) · MIT license · 0 weekly downloads

## Install

```sh
npm install querystring-helpers
pnpm add querystring-helpers
yarn add querystring-helpers
bun add querystring-helpers
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-03-29 |
| First published | 2018-09-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 125.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Ben Meyrick |
| Maintainers | bameyrick |
| Keywords | url, querystring, parameters, typescript, types |

## Links

- npm: https://www.npmjs.com/package/querystring-helpers
- Repository: https://github.com/bameyrick/querystring-helpers
- Homepage: https://github.com/bameyrick/querystring-helpers#readme
- Issues: https://github.com/bameyrick/querystring-helpers/issues
- npm.io page: https://npm.io/package/querystring-helpers

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-03-29
- 1.0.1 — 2019-03-29
- 1.0.0 — 2018-09-11

## README

# querystring-helpers

## Install
You can install via npm or yarn.

### npm
```bash
npm install --save querystring-helpers
```

### yarn
```bash
yarn add querystring-helpers
```

## Usage
You can import using ES6 imports. If you are using typescript this package includes a typings file.
```javascript
import { getQueryStringParams } from 'querystring-helpers';
```

### getQueryStringParams
Returns an object of querystring parameters and values from a URL

**Parameters**

| Parameter        | Type    | Description                                                                    | Optional | Default                |
|------------------|---------|--------------------------------------------------------------------------------|----------|------------------------|
| url              | string  | A URL you want to get querystring parameters for                               | true     | `window.location.href` |
| paramToLowerCase | boolean | Sets whether the keys in the returned object should be converted to lower case | true     | `false`                |

```javascript
import { getQueryStringParams } from 'querystring-helpers';


getQueryStringParams('https://example.co.uk?a=duck&b=attack');

/* Result
{
	a: 'duck',
	b: 'attack',
}
*/
```

### setQueryStringParams
Returns an string with query string parameters set

**Parameters**

| Parameter        | Type   | Description                                             | Optional | Default                |
|------------------|--------|---------------------------------------------------------|----------|------------------------|
| params           | Object | A set of key value pairs for parameters you want to set | false    | n/a                    |
| url              | string | A URL you want to get querystring parameters for        | true     | `window.location.href` |

```javascript
import { setQueryStringParams } from 'querystring-helpers';


setQueryStringParams({ a: 'cow', b: 'attack' }, 'https://example.co.uk?a=duck');

/* Result
https://example.co.uk?a=cow&b=attack
*/
```

### buildQueryStringParams
Returns an string with query string parameters set to add to the end of a url

**Parameters**

| Parameter                | Type    | Description                                                      | Optional | Default |
|--------------------------|---------|------------------------------------------------------------------|----------|---------|
| params                   | Object  | A set of key value pairs for parameters you want to set          | false    | n/a     |
| addQuestionMarkSeparator | boolean | Whether to add a question mark to the start of the string or not | true     | `false` |

```javascript
import { buildQueryStringParams } from 'querystring-helpers';


buildQueryStringParams({ a: 'pig', b: 'attack' }, true);

/* Result
?a=pig&b=attack
*/
```

### getBaseURL
Returns an url without a query string
*
Parameters**

| Parameter | Type   | Description                                   | Optional | Default                |
|-----------|--------|-----------------------------------------------|----------|------------------------|
| url       | string | A URL you want to get without the querystring | true     | `window.location.href` |

```javascript
import { getBaseURL } from 'querystring-helpers';


getBaseURL('https://example.co.uk?a=goose');

/* Result
https://example.co.uk
*/
```

---
_Source: https://npm.io/package/querystring-helpers · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
