mirror of
https://github.com/Viren070/AIOStreams.git
synced 2025-12-01 23:14:04 +01:00
fix(core/formatters): ensure null values trigger the false check case in conditional modifiers (#348)
Co-authored-by: David Garcia <dgarcia3@atlassian.com>
This commit is contained in:
@@ -211,7 +211,7 @@ export const conditionalModifiers = {
|
||||
'exists': (value: any) => {
|
||||
// Handle null, undefined, empty strings, empty arrays
|
||||
if (value === undefined || value === null) return false;
|
||||
if (typeof value === 'string') return (value.trim().length > 0 && value != 'null' && value != 'undefined');
|
||||
if (typeof value === 'string') return (value.replace(/ /g, '').length > 0);
|
||||
if (Array.isArray(value)) return value.length > 0;
|
||||
// For other types (numbers, booleans, objects), consider them as "existing"
|
||||
return true;
|
||||
@@ -539,7 +539,14 @@ export abstract class BaseFormatter {
|
||||
// try to coerce true/false value from modifier
|
||||
let conditional: boolean | undefined;
|
||||
try {
|
||||
if (isExact) {
|
||||
|
||||
// PRE-CHECK(s) -- skip resolving conditional modifier if value DNE, defaulting to false conditional
|
||||
if (!conditionalModifiers.exact.exists(value)) {
|
||||
conditional = false;
|
||||
}
|
||||
|
||||
// EXACT
|
||||
else if (isExact) {
|
||||
const modAsKey = mod as keyof typeof conditionalModifiers.exact;
|
||||
conditional = conditionalModifiers.exact[modAsKey](value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user