UNPKG

vue-router-webcache

Version:

Enable vue-router routing for google webcache(and same caches)

49 lines 1.88 kB
"use strict"; exports.__esModule = true; exports.getFullPath = exports.patchNuxtRouter = exports.getRealUrl = exports.isCacheUrl = exports.getCache = void 0; var config_1 = require("./config"); var getCache = function (fullUrl, cacheList) { if (cacheList === void 0) { cacheList = config_1.defaultCacheUrls; } var parsedUrl = new URL(fullUrl); var found = cacheList .find(function (_a) { var hostname = _a.hostname, pathname = _a.pathname; return parsedUrl.hostname === hostname && parsedUrl.pathname === pathname; }); return found || null; }; exports.getCache = getCache; var isCacheUrl = function (fullUrl, cacheList) { if (cacheList === void 0) { cacheList = config_1.defaultCacheUrls; } var cache = (0, exports.getCache)(fullUrl, cacheList); return !!cache; }; exports.isCacheUrl = isCacheUrl; var getRealUrl = function (fullUrl, cacheList) { if (cacheList === void 0) { cacheList = config_1.defaultCacheUrls; } var cache = (0, exports.getCache)(fullUrl, cacheList); if (!cache || !cache.getRealUrl) return null; return cache.getRealUrl(fullUrl); }; exports.getRealUrl = getRealUrl; var patchNuxtRouter = function (router, href) { var origRouterResolve = router.resolve.bind(router); router.resolve = function () { router.resolve = origRouterResolve; return origRouterResolve(href); }; }; exports.patchNuxtRouter = patchNuxtRouter; var getFullPath = function (fullUrl, base) { if (base === void 0) { base = '/'; } var parsed = new URL(fullUrl); var fullPath = parsed.pathname + parsed.search + parsed.hash; if (fullPath.startsWith(base)) fullPath = fullPath.replace(base, ''); if (!fullPath.startsWith('/')) fullPath = '/' + fullPath; return fullPath; }; exports.getFullPath = getFullPath; //# sourceMappingURL=utils.js.map