code-story
Version:
Get your code activity log for standup from git
79 lines (78 loc) • 2.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var helpers_1 = require("src/helpers");
var constants_1 = require("src/constants");
/**
* Format for set working days
* --workingDaysOfWeek="Fr,Su,Sa"
*/
var getWorkingDayMap = function (options) {
var workingDaysOption = options.workingDaysOfWeek;
var workingDaysParams = workingDaysOption === null || workingDaysOption === void 0 ? void 0 : workingDaysOption.split(',').map(helpers_1.trim);
var workingDay = {
0: null,
1: null,
2: null,
3: null,
4: null,
5: null,
6: null,
};
var hasValidParam = false;
var hasValidExcludeParam = false;
workingDaysParams === null || workingDaysParams === void 0 ? void 0 : workingDaysParams.forEach(function (param) {
var isExcludeParam = param.indexOf('!') !== -1;
var day = param.replace('!', '');
switch (day) {
case 'Su':
case 'Mo':
case 'Tu':
case 'We':
case 'Th':
case 'Fr':
case 'Sa':
if (isExcludeParam) {
hasValidExcludeParam = true;
}
else {
hasValidParam = true;
}
var dayCode = constants_1.OPTIONS_WEEK_DAY_CODE_MAP[day];
workingDay[dayCode] = !isExcludeParam;
break;
default:
// ignore values
}
});
/**
* Merge strategy
*/
if (hasValidParam) {
Object.keys(workingDay).forEach(function (day) {
if (workingDay[day] === null) {
workingDay[day] = false;
}
});
return workingDay;
}
else if (!hasValidParam && hasValidExcludeParam) {
Object.keys(workingDay).forEach(function (day) {
if (workingDay[day] === null) {
workingDay[day] = true;
}
});
return workingDay;
}
else {
return {
0: false,
1: true,
2: true,
3: true,
4: true,
5: true,
6: false,
};
}
};
exports.default = getWorkingDayMap;