index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. export const isValue = (val) => {
  2. if (val === null || val === undefined || (typeof val === 'string' && val.trim() === '') || (typeof val === 'object' && val?.length === 0)) {
  3. return false
  4. }
  5. return true
  6. }
  7. export const convertToCamelCase = (obj) => {
  8. for (let key in obj) {
  9. let newKey = key.replace(/_([a-z])/g, function($0, $1){ return $1.toUpperCase(); });
  10. if (newKey !== key) {
  11. obj[newKey] = obj[key];
  12. delete obj[key];
  13. }
  14. }
  15. }
  16. export const YMDHms = (date) => {
  17. const _date = new Date(date)
  18. const Y = `${_date.getFullYear()}`;
  19. const M = `${_date.getMonth() + 1 < 10 ? `0${_date.getMonth() + 1}` : _date.getMonth() + 1}`;
  20. const D = `${_date.getDate() < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
  21. const H = `${_date.getHours() < 10 ? `0${_date.getHours()}` : _date.getHours()}`;
  22. const m = `${_date.getMinutes() < 10 ? `0${_date.getMinutes()}` : _date.getMinutes()}`;
  23. const s = _date.getSeconds() < 10 ? `0${_date.getSeconds()}` : _date.getSeconds();
  24. return `${Y}-${M}-${D} ${H}:${m}:${s}`;
  25. }
  26. export const YMD = (date, format = false) => {
  27. const _date = new Date(date)
  28. const Y = `${_date.getFullYear()}`;
  29. const M = `${_date.getMonth() + 1 < 10 ? `0${_date.getMonth() + 1}` : _date.getMonth() + 1}`;
  30. const D = `${_date.getDate() < 10 ? `0${_date.getDate()}` : _date.getDate()}`;
  31. return format ? `${Y}年${M}月${D}日` : `${Y}-${M}-${D}`;
  32. }
  33. export const Hms = (date, format = false) => {
  34. const _date = new Date(date)
  35. const H = `${_date.getHours() < 10 ? `0${_date.getHours()}` : _date.getHours()}`;
  36. const m = `${_date.getMinutes() < 10 ? `0${_date.getMinutes()}` : _date.getMinutes()}`;
  37. const s = _date.getSeconds() < 10 ? `0${_date.getSeconds()}` : _date.getSeconds();
  38. return format ? `${H}时${m}分${s}秒` : `${H}:${m}:${s}`;
  39. }