utils/getQueryParam.js

/**
 * Get query string parameter by key
 *
 * @module utils/text/getQueryParam
 * @param {string} key - Key of query string parameter to retrieve
 * @return {string} - query string parameter if key is found, empty if not found
 */
const getQueryParam = ( key ) => {
	const regex = new RegExp( `${key}=([^\\&\\#]+)`, 'i' );
	const matches = regex.exec( window.location.search );
	let val = '';
	if ( matches && matches.length > 1 ) {
		[, val] = matches;
	}

	return val;
};

export default getQueryParam;