Skip to content

Commit

Permalink
Merge pull request #5 from ftasbasi/bugfix/sort-keys-desc
Browse files Browse the repository at this point in the history
bugfix desc sort
  • Loading branch information
ftasbasi authored Jan 21, 2024
2 parents 47f35ec + 53c5e9f commit 157b5a2
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -54,6 +56,7 @@ function replaceTemplateVariables(dataRaw, contextObj) {
}
}


function normalizeValue(value) {
// Normalize newline characters to '\n'
return value.replace(/\r\n/g, '\n');
Expand Down

0 comments on commit 157b5a2

Please sign in to comment.