mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-01-24 07:16:52 -06:00
df2f3460f0
1) Use the "RegExp.exec()" method instead. 2) Remove parameter form or provide default value. 3) Extract this nested ternary operation into an independent statement. 4) Replace this character class by the character itself. 5) Unnecessary use of conditional expression for default assignment. 6) Prefer using an optional chain expression instead, as it's more concise and easier to read.
34 lines
895 B
JavaScript
34 lines
895 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;
|
|
};
|