Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix desc sort #5

Merged
merged 1 commit into from
Jan 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading