pgadmin4/web/pgadmin/static/js/url_for.js
2024-01-01 14:13:48 +05:30

34 lines
899 B
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
const endpoints = require('pgadmin.browser.endpoints');
module.exports = function(endpoint, substitutions) {
let rawURL = endpoints[endpoint];
// captures things of the form <path:substitutionName>
let substitutionGroupsRegExp = /([<])([^:^>]*:)?([^>]+)([>])/g,
interpolated = rawURL;
if (!rawURL)
return rawURL;
interpolated = interpolated.replace(
substitutionGroupsRegExp,
function(_origin, _1, _2, substitutionName) {
if (substitutionName in substitutions) {
return substitutions[substitutionName];
}
return _origin;
}
);
return interpolated;
};