UNPKG

@ministryofjustice/probation-search-frontend

Version:

A shared UI component to search for probation cases from within your Express/Nunjucks application

28 lines 1.09 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getAbsoluteUrl = getAbsoluteUrl; exports.addParameters = addParameters; exports.removeParameters = removeParameters; function getAbsoluteUrl(req) { return `${req.protocol}://${req.get('host')}${req.originalUrl}`; } function addParameters(url, params) { const newUrl = new URL(typeof url === 'string' ? url : getAbsoluteUrl(url)); if (params) Object.entries(params).forEach(([key, value]) => { if (Array.isArray(value)) { newUrl.searchParams.delete(`${key}[]`); value.forEach(v => newUrl.searchParams.append(`${key}[]`, v.toString())); } else { newUrl.searchParams.set(key, value.toString()); } }); return newUrl.toString(); } function removeParameters(url, ...params) { const newUrl = new URL(typeof url === 'string' ? url : getAbsoluteUrl(url)); params.forEach(key => newUrl.searchParams.delete(key)); return newUrl.toString(); } //# sourceMappingURL=url.js.map