querystring-helpers
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

querystring-helpers

Install

You can install via npm or yarn.

npm

npm install --save querystring-helpers

yarn

yarn add querystring-helpers

Usage

You can import using ES6 imports. If you are using typescript this package includes a typings file.

import { getQueryStringParams } from 'querystring-helpers';

getQueryStringParams

Returns an object of querystring parameters and values from a URL

Parameters

Parameter Type Description Optional Default
url string A URL you want to get querystring parameters for true window.location.href
paramToLowerCase boolean Sets whether the keys in the returned object should be converted to lower case true false
import { getQueryStringParams } from 'querystring-helpers';
 
 
getQueryStringParams('https://example.co.uk?a=duck&b=attack');
 
/* Result
{
    a: 'duck',
    b: 'attack',
}
*/

setQueryStringParams

Returns an string with query string parameters set

Parameters

Parameter Type Description Optional Default
params Object A set of key value pairs for parameters you want to set false n/a
url string A URL you want to get querystring parameters for true window.location.href
import { setQueryStringParams } from 'querystring-helpers';
 
 
setQueryStringParams({ a: 'cow', b: 'attack' }, 'https://example.co.uk?a=duck');
 
/* Result
https://example.co.uk?a=cow&b=attack
*/

buildQueryStringParams

Returns an string with query string parameters set to add to the end of a url

Parameters

Parameter Type Description Optional Default
params Object A set of key value pairs for parameters you want to set false n/a
addQuestionMarkSeparator boolean Whether to add a question mark to the start of the string or not true false
import { buildQueryStringParams } from 'querystring-helpers';
 
 
buildQueryStringParams({ a: 'pig', b: 'attack' }, true);
 
/* Result
?a=pig&b=attack
*/

getBaseURL

Returns an url without a query string * Parameters**

Parameter Type Description Optional Default
url string A URL you want to get without the querystring true window.location.href
import { getBaseURL } from 'querystring-helpers';
 
 
getBaseURL('https://example.co.uk?a=goose');
 
/* Result
https://example.co.uk
*/

Package Sidebar

Install

npm i querystring-helpers

Weekly Downloads

2

Version

1.0.2

License

MIT

Unpacked Size

128 kB

Total Files

13

Last publish

Collaborators

  • bameyrick