Blame view

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