# query-parameters

> **IMPORTANT NOTE**
>
> I reinvented the wheel, I know... This project was created with the intention of being used within my own personal projects. If you are building anything of importance, you're probably better off using a more popular alternative with more comprehensive tests such as [this one](https://github.com/sindresorhus/query-string) or [this](https://github.com/ljharb/qs).

![Minified size](https://img.shields.io/bundlephobia/min/query-parameters.svg?style=plastic)

This small package helps you extract query parameters from a URL string.

## Installation

Install the component via npm by running `npm i query-parameters` or `yarn add query-parameters`.

## Usage

```js
const extract = require('query-parameters')

extract('https://www.website.com?id=123')
// returns { id: '123' }
```

### Arrays

Parameter values can be specified as arrays.

```js
extract('https://www.website.com?post[]=1')
// returns { post: ['1'] }
```

The value's index in the array can also be specified.

```js
extract('https://www.website.com?post[1]=second&post[0]=first')
// returns { post: ['first', 'second'] }
```

If multiple parameter values with the same key are provided, the output will be an array of values.

```js
extract('https://www.website.com?post=1&post=2')
// returns { post: ['1', '2'] }
```

## Contributing

Feel free to discuss any bug fixes/features in the [issues](https://github.com/shwilliam/query-parameters/issues). If you wish to work on this project:

1.  [Fork the project](https://github.com/shwilliam/query-parameters)
2.  Create your feature branch (`git checkout -b new-feature-branch`)
3.  Commit your changes & check for any lint/test output (`git commit -am 'add new feature'`)
4.  Push to the branch (`git push origin new-feature-branch`)
5.  [Submit a pull request!](https://github.com/shwilliam/query-parameters/pull/new/master)
