UNPKG

2.22 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = createContext;
7
8var _lodash = require('lodash');
9
10var _lodash2 = _interopRequireDefault(_lodash);
11
12var _time = require('./time');
13
14var _time2 = _interopRequireDefault(_time);
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18function createContext(configuration) {
19 if (_lodash2.default.isUndefined(configuration) || _lodash2.default.isUndefined(configuration.context)) {
20 throw new Error('Unable to create context, the given configuration is not valid');
21 }
22
23 var inputContext = _lodash2.default.omit(configuration.context, configuration.output);
24
25 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
26 args[_key - 1] = arguments[_key];
27 }
28
29 return _lodash2.default.reduce(args, function (context, arg) {
30 if (arg instanceof _time2.default) {
31 var day_of_month = arg.day_of_month,
32 day_of_week = arg.day_of_week,
33 month_of_year = arg.month_of_year,
34 time_of_day = arg.time_of_day,
35 timezone = arg.timezone;
36
37
38 return _lodash2.default.mapValues(inputContext, function (v, k) {
39 if (v.type === 'day_of_week' && (_lodash2.default.isUndefined(v.is_generated) || v.is_generated)) {
40 return day_of_week;
41 } else if (v.type === 'time_of_day' && (_lodash2.default.isUndefined(v.is_generated) || v.is_generated)) {
42 return time_of_day;
43 } else if (v.type === 'day_of_month' && (_lodash2.default.isUndefined(v.is_generated) || v.is_generated)) {
44 return day_of_month;
45 } else if (v.type === 'month_of_year' && (_lodash2.default.isUndefined(v.is_generated) || v.is_generated)) {
46 return month_of_year;
47 } else if (v.type === 'timezone') {
48 return timezone;
49 } else {
50 return context[k];
51 }
52 });
53 } else {
54 return _lodash2.default.mapValues(inputContext, function (v, k) {
55 return _lodash2.default.isUndefined(arg[k]) ? context[k] : arg[k];
56 });
57 }
58 }, _lodash2.default.mapValues(inputContext, function () {
59 return undefined;
60 }));
61}
\No newline at end of file