From ecda368d338a7fae526ff614b51c99d39b6d394b Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Thu, 28 Sep 2023 15:15:20 +0800 Subject: [PATCH 1/2] fix: add a lambda function in the template to allow users to format date --- src/settings/template.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/settings/template.ts b/src/settings/template.ts index 99ed2b7..c9b9608 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -118,10 +118,21 @@ 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); + // format the date + return formatDate(date, format); + }; +} + const functionMap: FunctionMap = { lowerCase, upperCase, upperCaseFirst, + formatDate: formatDateFunc, }; export const renderFilename = ( From 74b2114a6599dcf9375aa788233a7ab4c1aad0aa Mon Sep 17 00:00:00 2001 From: Hongbo Wu Date: Fri, 29 Sep 2023 10:59:28 +0800 Subject: [PATCH 2/2] return empty string if date variable is undefined in the formatDate function --- src/settings/template.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/settings/template.ts b/src/settings/template.ts index c9b9608..c49b87b 100644 --- a/src/settings/template.ts +++ b/src/settings/template.ts @@ -123,6 +123,9 @@ function formatDateFunc() { // 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); };