Blame view

天文台pc/tianwentai-ui/node_modules/date-fns/locale/_lib/buildLocalizeFn.d.ts 2.76 KB
bc518174   王天杨   提交两个项目文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
  import type { Day, Era, Month, Quarter } from "../../types.js";
  import type {
    LocaleDayPeriod,
    LocaleUnitValue,
    LocaleWidth,
    LocalizeFn,
  } from "../types.js";
  export type BuildLocalizeFnArgs<
    Value extends LocaleUnitValue,
    ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
  > = {
    values: LocalizePeriodValuesMap<Value>;
    defaultWidth: LocaleWidth;
    formattingValues?: LocalizePeriodValuesMap<Value>;
    defaultFormattingWidth?: LocaleWidth;
  } & (ArgCallback extends undefined
    ? {
        argumentCallback?: undefined;
      }
    : {
        argumentCallback: LocalizeFnArgCallback<Value>;
      });
  /**
   * The localize function argument callback which allows to convert raw value to
   * the actual type.
   *
   * @param value - The value to convert
   *
   * @returns The converted value
   */
  export type LocalizeFnArgCallback<Value extends LocaleUnitValue | number> = (
    value: Value,
  ) => LocalizeUnitIndex<Value>;
  /**
   * The map of localized values for each width.
   */
  export type LocalizePeriodValuesMap<Value extends LocaleUnitValue> = {
    [Pattern in LocaleWidth]?: LocalizeValues<Value>;
  };
  /**
   * The index type of the locale unit value. It types conversion of units of
   * values that don't start at 0 (i.e. quarters).
   */
  export type LocalizeUnitIndex<Value extends LocaleUnitValue | number> =
    Value extends LocaleUnitValue ? keyof LocalizeValues<Value> : number;
  /**
   * Converts the unit value to the tuple of values.
   */
  export type LocalizeValues<Value extends LocaleUnitValue> =
    Value extends LocaleDayPeriod
      ? Record<LocaleDayPeriod, string>
      : Value extends Era
        ? LocalizeEraValues
        : Value extends Quarter
          ? LocalizeQuarterValues
          : Value extends Day
            ? LocalizeDayValues
            : Value extends Month
              ? LocalizeMonthValues
              : never;
  /**
   * The tuple of localized era values. The first element represents BC,
   * the second element represents AD.
   */
  export type LocalizeEraValues = readonly [string, string];
  /**
   * The tuple of localized quarter values. The first element represents Q1.
   */
  export type LocalizeQuarterValues = readonly [string, string, string, string];
  /**
   * The tuple of localized day values. The first element represents Sunday.
   */
  export type LocalizeDayValues = readonly [
    string,
    string,
    string,
    string,
    string,
    string,
    string,
  ];
  /**
   * The tuple of localized month values. The first element represents January.
   */
  export type LocalizeMonthValues = readonly [
    string,
    string,
    string,
    string,
    string,
    string,
    string,
    string,
    string,
    string,
    string,
    string,
  ];
  export declare function buildLocalizeFn<
    Value extends LocaleUnitValue,
    ArgCallback extends LocalizeFnArgCallback<Value> | undefined,
  >(args: BuildLocalizeFnArgs<Value, ArgCallback>): LocalizeFn<Value>;