77 lines
2.2 KiB
JavaScript
Raw Normal View History

2024-08-20 23:25:37 +04:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.fillIndex = fillIndex;
exports.getFromDate = getFromDate;
exports.getRowFormat = getRowFormat;
exports.leftPad = leftPad;
exports.pickProps = pickProps;
exports.toArray = toArray;
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
function leftPad(str, length) {
var fill = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
var current = String(str);
while (current.length < length) {
current = "".concat(fill).concat(current);
}
return current;
}
/**
* Convert `value` to array. Will provide `[]` if is null or undefined.
*/
function toArray(val) {
if (val === null || val === undefined) {
return [];
}
return Array.isArray(val) ? val : [val];
}
function fillIndex(ori, index, value) {
var clone = (0, _toConsumableArray2.default)(ori);
clone[index] = value;
return clone;
}
/** Pick props from the key list. Will filter empty value */
function pickProps(props, keys) {
var clone = {};
var mergedKeys = keys || Object.keys(props);
mergedKeys.forEach(function (key) {
if (props[key] !== undefined) {
clone[key] = props[key];
}
});
return clone;
}
function getRowFormat(picker, locale, format) {
if (format) {
return format;
}
switch (picker) {
// All from the `locale.fieldXXXFormat` first
case 'time':
return locale.fieldTimeFormat;
case 'datetime':
return locale.fieldDateTimeFormat;
case 'month':
return locale.fieldMonthFormat;
case 'year':
return locale.fieldYearFormat;
case 'quarter':
return locale.fieldQuarterFormat;
case 'week':
return locale.fieldWeekFormat;
default:
return locale.fieldDateFormat;
}
}
function getFromDate(calendarValues, activeIndexList, activeIndex) {
var mergedActiveIndex = activeIndex !== undefined ? activeIndex : activeIndexList[activeIndexList.length - 1];
var firstValuedIndex = activeIndexList.find(function (index) {
return calendarValues[index];
});
return mergedActiveIndex !== firstValuedIndex ? calendarValues[firstValuedIndex] : undefined;
}