utils.js 396 B

1234567891011121314151617
  1. export function formatDate(value, format) {
  2. if (!value) {
  3. return '';
  4. }
  5. if (Array.isArray(format)) {
  6. format = format[0];
  7. }
  8. if (typeof format === 'function') {
  9. var result = format(value);
  10. if (typeof result === 'string') {
  11. return result;
  12. } else {
  13. throw new Error('The function of format does not return a string');
  14. }
  15. }
  16. return value.format(format);
  17. }