Açıklama Yok

assert.js 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import {
  2. getLocalTime
  3. } from "./util.js"
  4. const isDev = process.env.NODE_ENV !== 'production'
  5. export default function(args) {
  6. if (isDev) {
  7. const {
  8. mode,
  9. yearRange
  10. } = args
  11. let val
  12. // #ifdef VUE2
  13. val = args.value
  14. // #endif
  15. // #ifdef VUE3
  16. val = args.modelValue
  17. // #endif
  18. if ("ymdhis".indexOf(mode) === -1)
  19. throw new Error("illegal 'mode'")
  20. if (getLocalTime(mode) == undefined)
  21. throw new Error("'mode' is not found")
  22. if (val) {
  23. if (val.length !== getLocalTime(mode).length) {
  24. // #ifdef VUE2
  25. throw new Error("'value' cannot be formatted as 'mode'")
  26. // #endif
  27. // #ifdef VUE3
  28. throw new Error("'modelValue' cannot be formatted as 'mode'")
  29. // #endif
  30. }
  31. const arr = val.split(/-|:|\s/)
  32. if (arr.length != mode.length) {
  33. // #ifdef VUE2
  34. throw new Error("'value' cannot be formatted as 'mode'")
  35. // #endif
  36. // #ifdef VUE3
  37. throw new Error("'modelValue' cannot be formatted as 'mode'")
  38. // #endif
  39. }
  40. }
  41. if (yearRange.length !== 2)
  42. throw new Error("the length of array 'year-rang' must be 2")
  43. }
  44. }