fix: ignore displaying undefined template error in file name

This commit is contained in:
Kelvin John Falk Szolnoky 2024-01-24 23:33:36 +01:00
parent 22482f5bbd
commit 45b14dfd75
No known key found for this signature in database
GPG key ID: 02BA666D8C0E7E1B
2 changed files with 7 additions and 6 deletions

View file

@ -22,11 +22,11 @@ export function replaceIllegalFileNameCharactersInString(string: string): string
return string.replace(/[\\,#%&{}/*<>$"@.?]*/g, '').replace(/:+/g, ' -');
}
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel): string {
return template.replace(new RegExp('{{.*?}}', 'g'), (match: string) => replaceTag(match, mediaTypeModel));
export function replaceTags(template: string, mediaTypeModel: MediaTypeModel, ignoreUndefined: boolean = false): string {
return template.replace(new RegExp('{{.*?}}', 'g'), (match: string) => replaceTag(match, mediaTypeModel, ignoreUndefined));
}
function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
function replaceTag(match: string, mediaTypeModel: MediaTypeModel, ignoreUndefined: boolean): string {
let tag = match;
tag = tag.substring(2);
tag = tag.substring(0, tag.length - 2);
@ -39,7 +39,7 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
const obj = traverseMetaData(path, mediaTypeModel);
if (obj === undefined) {
return '{{ INVALID TEMPLATE TAG - object undefined }}';
return ignoreUndefined ? '' : '{{ INVALID TEMPLATE TAG - object undefined }}';
}
return obj;
@ -51,7 +51,7 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
const obj = traverseMetaData(path, mediaTypeModel);
if (obj === undefined) {
return '{{ INVALID TEMPLATE TAG - object undefined }}';
return ignoreUndefined ? '' : '{{ INVALID TEMPLATE TAG - object undefined }}';
}
if (operator === 'LIST') {