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 committed Nov 6, 2023
1 parent 8d3015b commit fb961e7
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 fb961e7

Please sign in to comment.