0d47ddf3d5a18d606991cc683d2d0da9501e38a34fd2a97807aec5689d76f5829180e79c187f0affca976cdc1bceadf3ed94947f9733f9fefff24268e576bb 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import isObjectEmpty from './is-object-empty';
  2. import hasOwnProp from './has-own-prop';
  3. import isObject from './is-object';
  4. import isDate from './is-date';
  5. import isNumber from './is-number';
  6. import isString from './is-string';
  7. import { isMoment } from '../moment/constructor';
  8. import isArray from './is-array';
  9. // type MomentInput = Moment | Date | string | number | (number | string)[] | MomentInputObject | void; // null | undefined
  10. export function isMomentInput(input) {
  11. return (
  12. isMoment(input) ||
  13. isDate(input) ||
  14. isString(input) ||
  15. isNumber(input) ||
  16. isNumberOrStringArray(input) ||
  17. isMomentInputObject(input) ||
  18. input === null ||
  19. input === undefined
  20. );
  21. }
  22. export function isMomentInputObject(input) {
  23. var objectTest = isObject(input) && !isObjectEmpty(input),
  24. propertyTest = false,
  25. properties = [
  26. 'years',
  27. 'year',
  28. 'y',
  29. 'months',
  30. 'month',
  31. 'M',
  32. 'days',
  33. 'day',
  34. 'd',
  35. 'dates',
  36. 'date',
  37. 'D',
  38. 'hours',
  39. 'hour',
  40. 'h',
  41. 'minutes',
  42. 'minute',
  43. 'm',
  44. 'seconds',
  45. 'second',
  46. 's',
  47. 'milliseconds',
  48. 'millisecond',
  49. 'ms',
  50. ],
  51. i,
  52. property,
  53. propertyLen = properties.length;
  54. for (i = 0; i < propertyLen; i += 1) {
  55. property = properties[i];
  56. propertyTest = propertyTest || hasOwnProp(input, property);
  57. }
  58. return objectTest && propertyTest;
  59. }
  60. function isNumberOrStringArray(input) {
  61. var arrayTest = isArray(input),
  62. dataTypeTest = false;
  63. if (arrayTest) {
  64. dataTypeTest =
  65. input.filter(function (item) {
  66. return !isNumber(item) && isString(input);
  67. }).length === 0;
  68. }
  69. return arrayTest && dataTypeTest;
  70. }