1.0.2 • Published 5 years ago

querystring-helpers v1.0.2

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

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

ParameterTypeDescriptionOptionalDefault
urlstringA URL you want to get querystring parameters fortruewindow.location.href
paramToLowerCasebooleanSets whether the keys in the returned object should be converted to lower casetruefalse
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

ParameterTypeDescriptionOptionalDefault
paramsObjectA set of key value pairs for parameters you want to setfalsen/a
urlstringA URL you want to get querystring parameters fortruewindow.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

ParameterTypeDescriptionOptionalDefault
paramsObjectA set of key value pairs for parameters you want to setfalsen/a
addQuestionMarkSeparatorbooleanWhether to add a question mark to the start of the string or nottruefalse
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**

ParameterTypeDescriptionOptionalDefault
urlstringA URL you want to get without the querystringtruewindow.location.href
import { getBaseURL } from 'querystring-helpers';


getBaseURL('https://example.co.uk?a=goose');

/* Result
https://example.co.uk
*/