utils.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. var __defProp = Object.defineProperty;
  2. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  3. var __getOwnPropNames = Object.getOwnPropertyNames;
  4. var __hasOwnProp = Object.prototype.hasOwnProperty;
  5. var __export = (target, all) => {
  6. for (var name in all)
  7. __defProp(target, name, { get: all[name], enumerable: true });
  8. };
  9. var __copyProps = (to, from, except, desc) => {
  10. if (from && typeof from === "object" || typeof from === "function") {
  11. for (let key of __getOwnPropNames(from))
  12. if (!__hasOwnProp.call(to, key) && key !== except)
  13. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  14. }
  15. return to;
  16. };
  17. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  18. var stdin_exports = {};
  19. __export(stdin_exports, {
  20. formatValueRange: () => formatValueRange,
  21. genOptions: () => genOptions,
  22. getMonthEndDay: () => getMonthEndDay,
  23. pickerInheritKeys: () => pickerInheritKeys,
  24. sharedProps: () => sharedProps,
  25. times: () => times
  26. });
  27. module.exports = __toCommonJS(stdin_exports);
  28. var import_utils = require("../utils");
  29. var import_Picker = require("../picker/Picker");
  30. const sharedProps = (0, import_utils.extend)({}, import_Picker.pickerSharedProps, {
  31. modelValue: (0, import_utils.makeArrayProp)(),
  32. filter: Function,
  33. formatter: {
  34. type: Function,
  35. default: (type, option) => option
  36. }
  37. });
  38. const pickerInheritKeys = Object.keys(import_Picker.pickerSharedProps);
  39. function times(n, iteratee) {
  40. if (n < 0) {
  41. return [];
  42. }
  43. const result = Array(n);
  44. let index = -1;
  45. while (++index < n) {
  46. result[index] = iteratee(index);
  47. }
  48. return result;
  49. }
  50. const getMonthEndDay = (year, month) => 32 - new Date(year, month - 1, 32).getDate();
  51. const genOptions = (min, max, type, formatter, filter, values) => {
  52. const options = times(max - min + 1, (index) => {
  53. const value = (0, import_utils.padZero)(min + index);
  54. return formatter(type, {
  55. text: value,
  56. value
  57. });
  58. });
  59. return filter ? filter(type, options, values) : options;
  60. };
  61. const formatValueRange = (values, columns) => values.map((value, index) => {
  62. const column = columns[index];
  63. if (column.length) {
  64. const minValue = +column[0].value;
  65. const maxValue = +column[column.length - 1].value;
  66. return (0, import_utils.padZero)((0, import_utils.clamp)(+value, minValue, maxValue));
  67. }
  68. return value;
  69. });