Skip to content

Commit

Permalink
refactor: improve custom filters readability with optional chaining
Browse files Browse the repository at this point in the history
tested locally
  • Loading branch information
ManikantaMandala committed Oct 9, 2024
1 parent c2216f7 commit 3dba131
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions apps/nunjucks-filters/src/customFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function getPayloadExamples(msg) {
}

const payload = msg.payload();
if (payload?.examples()) {
if (payload && payload.examples()) {
return payload.examples().map(example => ({ example }));
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ function getHeadersExamples(msg) {
}

const headers = msg.headers();
if (headers?.examples()) {
if (headers && headers.examples()) {
return headers.examples().map(example => ({ example }));
}
}
Expand Down Expand Up @@ -198,7 +198,11 @@ function replaceServerVariablesWithValues(url, serverVariables) {
const getVariableValue = (object, variable) => {
const keyValue = object[variable]._json;

<<<<<<< HEAD
if (keyValue) return keyValue.default ?? keyValue.enum?.[0];
=======
if (keyValue) return keyValue.default || (keyValue.enum && keyValue.enum[0]);
>>>>>>> 9907055 (refactor: improve custom filters readability with optional chaining)
};

const urlVariables = getVariablesNamesFromUrl(url);
Expand Down

0 comments on commit 3dba131

Please sign in to comment.