From 53c5e9f87b8dbd13284a81da7e2aab886c63a76b Mon Sep 17 00:00:00 2001 From: ftasbasi Date: Sun, 21 Jan 2024 17:45:57 +0300 Subject: [PATCH] bugfix desc sort --- index.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 0ff6fd8..6b9c505 100644 --- a/index.js +++ b/index.js @@ -25,15 +25,17 @@ function replaceTemplateVariables(dataRaw, contextObj) { let data = dataRaw; try { - const regex = /ENV_\w+/g; // Find all matches of "ENV_" followed by a key in the data string const matches = data.match(regex); - // If there are matches, iterate over them + // If there are matches, sort them in descending order if (matches) { - for (const match of matches) { + const sortedMatches = matches.sort((a, b) => b.localeCompare(a)); + + // Iterate over the sorted matches + for (const match of sortedMatches) { const key = match.substring(4); // Extract the key from the match const contextValue = contextObj[key]; // Get the corresponding value from the context @@ -54,6 +56,7 @@ function replaceTemplateVariables(dataRaw, contextObj) { } } + function normalizeValue(value) { // Normalize newline characters to '\n' return value.replace(/\r\n/g, '\n');