https://github.com/bytebodger/get-url-parameters
https://github.com/bytebodger/get-url-parameters
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/bytebodger/get-url-parameters
- Owner: bytebodger
- License: mit
- Created: 2021-02-27T19:08:18.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2021-03-24T01:39:44.000Z (about 5 years ago)
- Last Synced: 2025-05-19T00:17:30.804Z (about 1 year ago)
- Language: JavaScript
- Size: 80.1 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# get-url-parameters
`get-url-parameters` is a utility that function that retrieves query string variables and attempts to convert them into native JS data types.
## Usage
After installation, import the package:
```javascript
import { getUrlParameters } from '@toolz/get-url-parameters';
```
### getUrlParameters()
The function returns an object containing any query string parameters and attempts to convert those values into native JS data types.
```javascript
const API = {
arguments: {
convertDataTypes: {
optional,
format: Boolean,
defaultValue: true,
},
},
returns: Object,
}
```
**Examples:**
```javascript
// URL = /foo?name=adam&age=42&isKool=true&criminalRecord=null&pi=3.14
const urlParameters = getUrlParameters();
/*
urlParameters = {
name: 'adam',
age: 42,
isKool: true,
criminalRecord: null,
pi: 3.14,
}
*/
```
```javascript
// URL = /foo?name=adam&age=42&isKool=true&criminalRecord=null&pi=3.14
const urlParameters = getUrlParameters(false);
/*
urlParameters = {
name: 'adam',
age: '42',
isKool: 'true',
criminalRecord: 'null',
pi: '3.14',
}
*/
```