feat: add index operator for templating arrays

This commit is contained in:
Kelvin John Falk Szolnoky 2024-01-24 23:12:13 +01:00
parent 841fbec1a3
commit 22482f5bbd
No known key found for this signature in database
GPG key ID: 02BA666D8C0E7E1B

View file

@ -64,6 +64,16 @@ function replaceTag(match: string, mediaTypeModel: MediaTypeModel): string {
return '{{ INVALID TEMPLATE TAG - operator ENUM is only applicable on an array }}';
}
return obj.join(', ');
} else if (operator === 'FIRST') {
if (!Array.isArray(obj)) {
return '{{ INVALID TEMPLATE TAG - operator FIRST is only applicable on an array }}';
}
return obj[0];
} else if (operator === 'LAST') {
if (!Array.isArray(obj)) {
return '{{ INVALID TEMPLATE TAG - operator LAST is only applicable on an array }}';
}
return obj[obj.length - 1];
}
return `{{ INVALID TEMPLATE TAG - unknown operator ${operator} }}`;