/**
* To work out which environment the site is on (dev/staging/live)
* @module
* @since 0.0.51
*/
/**
* Returns true if the code is being executed on a local development server; false otherwise
* @returns {boolean}
*/
const isDev = () => window.location.href.search(/(http:\/\/|https:\/\/)d51[a-z]+/g) > -1;
/**
* Returns true if the code is being executed on a staging server; false otherwise
* @returns {boolean}
*/
const isStaging = () => window.location.href.search(/(http:\/\/|https:\/\/)d51[0-9]+/g) > -1;
/**
* Returns true if the code is being executed on a live server; false if it's on a local dev or staging server
* @returns {boolean}
*/
const isLive = () => !isDev() && !isStaging();
/**
* Get the prefix of the url identifying the development/staging server.
* @returns {string} eg: d51alfie.comcar.co.uk --> d51alfie, d5117.comcar.co.uk --> d5117, comcar.co.uk --> [empty string]
*/
const extractDevUrlPrefix = () => {
let str_dev_url_prefix = '';
const arr_dev_url_prefix_with_dot = window.location.href.match(/d51[a-z0-9]+($|\.)/g);
if (arr_dev_url_prefix_with_dot.length) {
const str_dev_url_prefixWithDot = arr_dev_url_prefix_with_dot[0];
str_dev_url_prefix = str_dev_url_prefixWithDot.replace(/\./g, '');
}
return str_dev_url_prefix;
};
export {
isDev,
isStaging,
isLive,
extractDevUrlPrefix,
};