miscUtil.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
  2. export function leftPad(str, length) {
  3. var fill = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
  4. var current = String(str);
  5. while (current.length < length) {
  6. current = "".concat(fill).concat(current);
  7. }
  8. return current;
  9. }
  10. /**
  11. * Convert `value` to array. Will provide `[]` if is null or undefined.
  12. */
  13. export function toArray(val) {
  14. if (val === null || val === undefined) {
  15. return [];
  16. }
  17. return Array.isArray(val) ? val : [val];
  18. }
  19. export function fillIndex(ori, index, value) {
  20. var clone = _toConsumableArray(ori);
  21. clone[index] = value;
  22. return clone;
  23. }
  24. /** Pick props from the key list. Will filter empty value */
  25. export function pickProps(props, keys) {
  26. var clone = {};
  27. var mergedKeys = keys || Object.keys(props);
  28. mergedKeys.forEach(function (key) {
  29. if (props[key] !== undefined) {
  30. clone[key] = props[key];
  31. }
  32. });
  33. return clone;
  34. }
  35. export function getRowFormat(picker, locale, format) {
  36. if (format) {
  37. return format;
  38. }
  39. switch (picker) {
  40. // All from the `locale.fieldXXXFormat` first
  41. case 'time':
  42. return locale.fieldTimeFormat;
  43. case 'datetime':
  44. return locale.fieldDateTimeFormat;
  45. case 'month':
  46. return locale.fieldMonthFormat;
  47. case 'year':
  48. return locale.fieldYearFormat;
  49. case 'quarter':
  50. return locale.fieldQuarterFormat;
  51. case 'week':
  52. return locale.fieldWeekFormat;
  53. default:
  54. return locale.fieldDateFormat;
  55. }
  56. }
  57. export function getFromDate(calendarValues, activeIndexList, activeIndex) {
  58. var mergedActiveIndex = activeIndex !== undefined ? activeIndex : activeIndexList[activeIndexList.length - 1];
  59. var firstValuedIndex = activeIndexList.find(function (index) {
  60. return calendarValues[index];
  61. });
  62. return mergedActiveIndex !== firstValuedIndex ? calendarValues[firstValuedIndex] : undefined;
  63. }