export default function normalizeToString(input) { // string or String object if (typeof input === 'string' || input instanceof String) return input.toString(); // boolean value if (typeof input === 'boolean') return input.toString(); // numeric value if (typeof input === 'number' || input instanceof Number) { // not a finite value - invalid input - return empty if (!Number.isFinite(input)) return ''; // safe integer, return as-is if (Number.isSafeInteger(input)) return input.toString(10); // not a safe integer, return with 5 decimal places return input.toFixed(5); // fix to 4 decimal places } // if there's a JSON method, use the result of that if (typeof input.toJSON === 'function') { const ret = input.toJSON(); if (typeof ret === 'string') return ret; } // unsupported value - empty string return ''; }