/** * DRF backends commonly serialize booleans as 'Y'/'N' instead of JSON * true/false. These helpers centralize the encode/decode so services and * views never touch the magic strings directly. * * Both helpers tolerate the polymorphic shapes the backend may surface — * 'Y' / 'N' / true / false / 1 / 0 / null / undefined — so a caller that * gets a boolean today and a string tomorrow keeps working. */ /** * @param {*} value anything * @returns {'Y'|'N'} */ export function toApiBool(value) { return fromApiBool(value) ? 'Y' : 'N' } /** * @param {*} value 'Y' | 'N' | true | false | 1 | 0 | null | undefined * @returns {boolean} */ export function fromApiBool(value) { return value === 'Y' || value === true || value === 1 }