UNPKG

@shopgate/engage

Version:
14 lines 1.53 kB
function _slicedToArray(arr,i){return _arrayWithHoles(arr)||_iterableToArrayLimit(arr,i)||_nonIterableRest();}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance");}function _iterableToArrayLimit(arr,i){var _arr=[];var _n=true;var _d=false;var _e=undefined;try{for(var _i=arr[Symbol.iterator](),_s;!(_n=(_s=_i.next()).done);_n=true){_arr.push(_s.value);if(i&&_arr.length===i)break;}}catch(err){_d=true;_e=err;}finally{try{if(!_n&&_i["return"]!=null)_i["return"]();}finally{if(_d)throw _e;}}return _arr;}function _arrayWithHoles(arr){if(Array.isArray(arr))return arr;}/** * Regular expression to decode all possible types of base url from an url * * URLs of deployed apps * https://sandbox.cdn.connect.shopgate.com/shop_30186/@shopgate/theme-ios11/6.22.4/11953/index.html * * URLs while local development * http://192.168.0.1:8080 */var baseUrlRegex=/https?:\/\/(?:(?:(?:[0-9]{1,3}\.){3}[0-9]{1,3}(?::[0-9]+)?)|(?:.+index.html))/gm;/** * Decodes the base url from a passed url. When url parameter left empty, window.location.href will * be used as source * @param {string} [sourceUrl=''] An optional url to be used for decode process * @return {string} The decoded base url */export var getAppBaseUrl=function getAppBaseUrl(){var sourceUrl=arguments.length>0&&arguments[0]!==undefined?arguments[0]:'';var _ref=(sourceUrl||window.location.href).match(baseUrlRegex)||[],_ref2=_slicedToArray(_ref,1),_ref2$=_ref2[0],basedUrl=_ref2$===void 0?'':_ref2$;return basedUrl;};