Skip to content

Commit

Permalink
fix: add a lambda function in the template to allow users to format d…
Browse files Browse the repository at this point in the history
…ate (#136)

* fix: add a lambda function in the template to allow users to format date

* return empty string if date variable is undefined in the formatDate function
  • Loading branch information
sywhb authored Nov 6, 2023
1 parent d906496 commit be1119b
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/settings/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,24 @@ function upperCaseFirst() {
};
}

function formatDateFunc() {
return function (text: string, render: (text: string) => string) {
// get the date and format from the text
const [dateVariable, format] = text.split(",", 2);
const date = render(dateVariable);
if (!date) {
return "";
}
// format the date
return formatDate(date, format);
};
}

const functionMap: FunctionMap = {
lowerCase,
upperCase,
upperCaseFirst,
formatDate: formatDateFunc,
};

export const renderFilename = (
Expand Down

0 comments on commit be1119b

Please sign in to comment.