es-toolkit
Version:
A state-of-the-art, high-performance JavaScript utility library with a small bundle size and strong type annotations.
19 lines (17 loc) • 388 B
JavaScript
function toString(value) {
if (value == null) {
return '';
}
if (typeof value === 'string') {
return value;
}
if (Array.isArray(value)) {
return value.map(toString).join(',');
}
const result = String(value);
if (result === '0' && Object.is(Number(value), -0)) {
return '-0';
}
return result;
}
export { toString };