@toolz/get-url-parameters

1.0.3 • Public • Published

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:

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.

const API = {
   arguments: {
      convertDataTypes: {
         optional,
         format: Boolean,
         defaultValue: true,
      },
   },
   returns: Object,
}

Examples:

// 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,
   }
 */
// 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',
   }
 */

Package Sidebar

Install

npm i @toolz/get-url-parameters

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

4.56 kB

Total Files

4

Last publish

Collaborators

  • bytebodger