helpers.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import moment from 'moment'
  2. function date2s (date) {
  3. return moment(date).format('DD.MM.')
  4. }
  5. function time2s (date) {
  6. return moment(date).format('HH:mm')
  7. }
  8. function datetime2s (date) {
  9. return moment(date).format('DD.MM. HH:mm')
  10. }
  11. function sortTable (array, columns) {
  12. function compare (item1, item2) {
  13. if (item1 instanceof Date) {
  14. }
  15. }
  16. }
  17. function normalize (item, type) {
  18. return item ? String(item).replace(/\s+/g, ' ').trim() : null
  19. }
  20. function normalizePhone (item) {
  21. let phone = String(item).replace(/\s|\+|\/|,|-|'/g, '').replace(/\(0\)/, '').replace(/^0+/, '')
  22. if (phone.match(/[^\d*]/)) {
  23. return `FEHLER (nicht-numerische Zeichen): ${phone}`
  24. }
  25. if (phone.length === 0) {
  26. return null
  27. } else if (phone.length === 9) {
  28. // Assume swiss number
  29. phone = `+41${phone}`
  30. } else if (phone.length === 11) {
  31. phone = `+${phone}`
  32. } else {
  33. return `FEHLER (falsche Länge): ${phone}`
  34. }
  35. return phone
  36. }
  37. export { date2s, time2s, datetime2s, sortTable, normalize, normalizePhone }