mirror of
https://github.com/Ku6epXBOCTuK/easy-png-tools.git
synced 2026-09-14 21:46:35 +00:00
feat: add text and date draw tools
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
const PAD2 = (n: number) => String(n).padStart(2, '0');
|
||||
|
||||
/**
|
||||
* Мини-форматтер штампа даты: токены YYYY MM DD hh mm ss заменяются
|
||||
* значениями локального времени, остальные символы остаются как есть.
|
||||
*/
|
||||
export function formatStamp(date: Date, pattern: string): string {
|
||||
return pattern.replace(/YYYY|MM|DD|hh|mm|ss/g, (token) => {
|
||||
switch (token) {
|
||||
case 'YYYY':
|
||||
return String(date.getFullYear());
|
||||
case 'MM':
|
||||
return PAD2(date.getMonth() + 1);
|
||||
case 'DD':
|
||||
return PAD2(date.getDate());
|
||||
case 'hh':
|
||||
return PAD2(date.getHours());
|
||||
case 'mm':
|
||||
return PAD2(date.getMinutes());
|
||||
case 'ss':
|
||||
return PAD2(date.getSeconds());
|
||||
default:
|
||||
return token;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user