0.1.2 • Published 5 years ago

query-parameters v0.1.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

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.

Minified size

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:

  1. Fork the project
  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!