UNPKG

@awhere/api

Version:

The awesome aWhere API for JavaScript.

70 lines 2.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseHash = exports.parseQuery = exports.getOrigin = void 0; var getOrigin = function () { if (typeof window === 'undefined' || typeof window.location === 'undefined') { return '/'; } var p = window.location.pathname.split('/'); return p[p.length - 1].match(/(\.(\w|\d)+)$/) ? window.location.origin + p.slice(0, -1).join('/') + '/' : window.location.origin + window.location.pathname; }; exports.getOrigin = getOrigin; var parseQuery = function (query) { var queryString = ''; if (!query) { if (typeof window === 'undefined' || typeof window.location === 'undefined') { return {}; } queryString = window.location.search.substring(1); } else if (typeof query === 'string') { var _a = query.split('?') || [], _ = _a[0], str = _a[1]; queryString = str; } else if (typeof (query === null || query === void 0 ? void 0 : query.search) === 'string') { var _b = (query === null || query === void 0 ? void 0 : query.search.split('?')) || [], _ = _b[0], str = _b[1]; queryString = str; } if (queryString) { return queryString.split('&').reduce(function (params, param) { var _a = param.split('='), key = _a[0], value = _a[1]; if (key && value) { params[key] = decodeURIComponent(value); } return params; }, {}); } return {}; }; exports.parseQuery = parseQuery; var parseHash = function (hash) { var hashString = ''; if (!hash) { if (typeof window === 'undefined' || typeof window.location === 'undefined') { return {}; } hashString = window.location.hash.substring(1); } else if (typeof hash === 'string') { var _a = hash.split('#') || [], _ = _a[0], str = _a[1]; hashString = str; } else if (typeof (hash === null || hash === void 0 ? void 0 : hash.hash) === 'string') { var _b = (hash === null || hash === void 0 ? void 0 : hash.hash.split('#')) || [], _ = _b[0], str = _b[1]; hashString = str; } if (hashString) { return hashString.split('&').reduce(function (params, param) { var _a = param.split('='), key = _a[0], value = _a[1]; if (key && value) { params[key] = decodeURIComponent(value); } return params; }, {}); } return {}; }; exports.parseHash = parseHash; //# sourceMappingURL=url.js.map