query-parameters
v0.1.2
Published
extract URL query params
Downloads
5
Maintainers
Readme
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 or this.
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
const extract = require('query-parameters')
extract('https://www.website.com?id=123')
// returns { id: '123' }
Arrays
Parameter values can be specified as arrays.
extract('https://www.website.com?post[]=1')
// returns { post: ['1'] }
The value's index in the array can also be specified.
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.
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. If you wish to work on this project:
- Fork the project
- Create your feature branch (
git checkout -b new-feature-branch
) - Commit your changes & check for any lint/test output (
git commit -am 'add new feature'
) - Push to the branch (
git push origin new-feature-branch
) - Submit a pull request!