pgadmin4/web/pgadmin/static/js/url_for.js

34 lines
895 B
JavaScript
Raw Normal View History

2019-01-02 04:24:12 -06:00
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2024-01-01 02:43:48 -06:00
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
2019-01-02 04:24:12 -06:00
// 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;
};