1 | 'use strict';
|
2 |
|
3 | exports.__esModule = true;
|
4 | exports.checkMomentObj = checkMomentObj;
|
5 | exports.checkDateValue = checkDateValue;
|
6 | exports.formatDateValue = formatDateValue;
|
7 |
|
8 | var _moment = require('moment');
|
9 |
|
10 | var _moment2 = _interopRequireDefault(_moment);
|
11 |
|
12 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
13 |
|
14 |
|
15 | function checkMomentObj(props, propName, componentName) {
|
16 | if (props[propName] && !_moment2.default.isMoment(props[propName])) {
|
17 | return new Error('Invalid prop ' + propName + ' supplied to ' + componentName + '. Required a moment object');
|
18 | }
|
19 | }
|
20 |
|
21 |
|
22 | function checkDateValue(props, propName, componentName) {
|
23 | if (props[propName] && !_moment2.default.isMoment(props[propName]) && typeof props[propName] !== 'string') {
|
24 | return new Error('Invalid prop ' + propName + ' supplied to ' + componentName + '. Required a moment object or format date string!');
|
25 | }
|
26 | }
|
27 |
|
28 | function formatDateValue(value, format) {
|
29 | var val = typeof value === 'string' ? (0, _moment2.default)(value, format, true) : value;
|
30 | if (val && _moment2.default.isMoment(val) && val.isValid()) {
|
31 | return val;
|
32 | }
|
33 | return null;
|
34 | } |
\ | No newline at end of file |