@patomation/query-param
TypeScript icon, indicating that this package has built-in type declarations

1.4.0 • Public • Published

Query Param Module

Gets query string parameters from window location substring.

Installation

yarn add @patomation/query-param
npm install @patomation/query-param --save

Usage

import { queryParam } from '@patomation/query-param'

const myParams = queryParam()

Example url might be:

https://mySite.com/?make=Tesla&model=T&year=2019electric=true

Result is one json object:

//  myParams =
{
  make: 'Tesla',
  model: 'T',
  year: 2019,
  electric: true
}

localStorage support

You can set a query param with this. It will be persisted in local storage. So when you redirect and go to a different page the param will be present.

import { localStorageQueryParam } from '@patomation/query-param'

const myParams = localStorageQueryParam()

Example:

  1. navigate to page one with the param
https://mySite.com/pageOne/?cool=beans
//  pageOne params =
{
  cool: 'beans'
}
  1. navigate to page two without the query string. The param will still exist in local storage
https://mySite.com/pageTwo/
//  pageTwo params =
{
  cool: 'beans'
}

The local storage key is 'persist:queryParam'

Additional notes

  • white spaces converts %20 to white space

Package Sidebar

Install

npm i @patomation/query-param

Weekly Downloads

1

Version

1.4.0

License

MIT

Unpacked Size

11.3 kB

Total Files

7

Last publish

Collaborators

  • patomation