mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-02-07 16:40:05 +00:00
S&R improved filename sanitizing (#2784)
Co-authored-by: typpos <28550406+typpos@users.noreply.github.com>
This commit is contained in:
@@ -272,3 +272,28 @@ export function parseFilePath(filepath: string): {
|
||||
subfolder: normalizedPath.slice(0, lastSlashIndex)
|
||||
}
|
||||
}
|
||||
|
||||
// Simple date formatter
|
||||
const parts = {
|
||||
d: (d: Date) => d.getDate(),
|
||||
M: (d: Date) => d.getMonth() + 1,
|
||||
h: (d: Date) => d.getHours(),
|
||||
m: (d: Date) => d.getMinutes(),
|
||||
s: (d: Date) => d.getSeconds()
|
||||
}
|
||||
const format =
|
||||
Object.keys(parts)
|
||||
.map((k) => k + k + '?')
|
||||
.join('|') + '|yyy?y?'
|
||||
|
||||
export function formatDate(text: string, date: Date) {
|
||||
return text.replace(new RegExp(format, 'g'), (text: string): string => {
|
||||
if (text === 'yy') return (date.getFullYear() + '').substring(2)
|
||||
if (text === 'yyyy') return date.getFullYear().toString()
|
||||
if (text[0] in parts) {
|
||||
const p = parts[text[0] as keyof typeof parts](date)
|
||||
return (p + '').padStart(text.length, '0')
|
||||
}
|
||||
return text
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user