18 lines
399 B
JavaScript
18 lines
399 B
JavaScript
export function formatDate(value, format) {
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
if (Array.isArray(format)) {
|
|
format = format[0];
|
|
}
|
|
if (typeof format === 'function') {
|
|
const result = format(value);
|
|
if (typeof result === 'string') {
|
|
return result;
|
|
} else {
|
|
throw new Error('The function of format does not return a string');
|
|
}
|
|
}
|
|
return value.format(format);
|
|
}
|