UNPKG

respond-framework

Version:
35 lines (34 loc) 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = settingsToHash; exports.stripPermalink = exports.permalinkPrefix = exports.hashToSettings = void 0; var _constants = require("../../../helpers/constants.js"); var _searchQuery = require("../../../helpers/searchQuery.js"); function settingsToHash({ ...query }, branch) { if (branch) query.focusedBranch = branch; return permalinkPrefix + (0, _searchQuery.stringifyQuery)(query); } const hashToSettings = () => { if (_constants.isProd) return; const h = typeof window !== undefined && window.location?.hash; if (h && h[1] === '!') { const search = stripUserHash(h.slice(2)); // strip possible second hash by user, eg: #!userId=123#foo return (0, _searchQuery.parseSearch)(search); // use hash so search can still be used unobstructed in userland (as hash can easily used for both purposes as handled in this file) } }; exports.hashToSettings = hashToSettings; const stripPermalink = (h = '') => h[0] === '!' ? stripPermalinkHash(h) : h; exports.stripPermalink = stripPermalink; const stripPermalinkHash = h => { const userHashIndex = h.indexOf('#'); return userHashIndex > -1 ? h.slice(userHashIndex + 1) : ''; // eg: stripPermalink('#!userId=123#foo') -> '#foo' or '#!userId=123' -> '' }; const stripUserHash = h => { const userHashIndex = h.indexOf('#'); return userHashIndex > -1 ? h.slice(0, userHashIndex) : h; // eg: stripPermalink('userId=123#foo') -> 'userId=123' }; const permalinkPrefix = exports.permalinkPrefix = '#!';