• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import { Locale } from "./Locale.mjs"
3import wasm from "./diplomat-wasm.mjs";
4import * as diplomatRuntime from "./diplomat-runtime.mjs";
5
6
7/** The various calendar types currently supported by [`Calendar`]
8*
9*See the [Rust documentation for `AnyCalendarKind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html) for more information.
10*/
11
12
13export class AnyCalendarKind {
14
15    #value = undefined;
16
17    static #values = new Map([
18        ["Iso", 0],
19        ["Gregorian", 1],
20        ["Buddhist", 2],
21        ["Japanese", 3],
22        ["JapaneseExtended", 4],
23        ["Ethiopian", 5],
24        ["EthiopianAmeteAlem", 6],
25        ["Indian", 7],
26        ["Coptic", 8],
27        ["Dangi", 9],
28        ["Chinese", 10],
29        ["Hebrew", 11],
30        ["IslamicCivil", 12],
31        ["IslamicObservational", 13],
32        ["IslamicTabular", 14],
33        ["IslamicUmmAlQura", 15],
34        ["Persian", 16],
35        ["Roc", 17]
36    ]);
37
38    static getAllEntries() {
39        return AnyCalendarKind.#values.entries();
40    }
41
42    #internalConstructor(value) {
43        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
44            // We pass in two internalConstructor arguments to create *new*
45            // instances of this type, otherwise the enums are treated as singletons.
46            if (arguments[1] === diplomatRuntime.internalConstructor ) {
47                this.#value = arguments[2];
48                return this;
49            }
50            return AnyCalendarKind.#objectValues[arguments[1]];
51        }
52
53        if (value instanceof AnyCalendarKind) {
54            return value;
55        }
56
57        let intVal = AnyCalendarKind.#values.get(value);
58
59        // Nullish check, checks for null or undefined
60        if (intVal != null) {
61            return AnyCalendarKind.#objectValues[intVal];
62        }
63
64        throw TypeError(value + " is not a AnyCalendarKind and does not correspond to any of its enumerator values.");
65    }
66
67    static fromValue(value) {
68        return new AnyCalendarKind(value);
69    }
70
71    get value() {
72        return [...AnyCalendarKind.#values.keys()][this.#value];
73    }
74
75    get ffiValue() {
76        return this.#value;
77    }
78    static #objectValues = [
79        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
80        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
81        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
82        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
83        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
84        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
85        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
86        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
87        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
88        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
89        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
90        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
91        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
92        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13),
93        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
94        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15),
95        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16),
96        new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17),
97    ];
98
99    static Iso = AnyCalendarKind.#objectValues[0];
100    static Gregorian = AnyCalendarKind.#objectValues[1];
101    static Buddhist = AnyCalendarKind.#objectValues[2];
102    static Japanese = AnyCalendarKind.#objectValues[3];
103    static JapaneseExtended = AnyCalendarKind.#objectValues[4];
104    static Ethiopian = AnyCalendarKind.#objectValues[5];
105    static EthiopianAmeteAlem = AnyCalendarKind.#objectValues[6];
106    static Indian = AnyCalendarKind.#objectValues[7];
107    static Coptic = AnyCalendarKind.#objectValues[8];
108    static Dangi = AnyCalendarKind.#objectValues[9];
109    static Chinese = AnyCalendarKind.#objectValues[10];
110    static Hebrew = AnyCalendarKind.#objectValues[11];
111    static IslamicCivil = AnyCalendarKind.#objectValues[12];
112    static IslamicObservational = AnyCalendarKind.#objectValues[13];
113    static IslamicTabular = AnyCalendarKind.#objectValues[14];
114    static IslamicUmmAlQura = AnyCalendarKind.#objectValues[15];
115    static Persian = AnyCalendarKind.#objectValues[16];
116    static Roc = AnyCalendarKind.#objectValues[17];
117
118    static getForLocale(locale) {
119        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
120
121        const result = wasm.icu4x_AnyCalendarKind_get_for_locale_mv1(diplomatReceive.buffer, locale.ffiValue);
122
123        try {
124            if (!diplomatReceive.resultFlag) {
125                return null;
126            }
127            return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
128        }
129
130        finally {
131            diplomatReceive.free();
132        }
133    }
134
135    static getForBcp47(s) {
136        let functionCleanupArena = new diplomatRuntime.CleanupArena();
137
138        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
139
140        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
141
142        const result = wasm.icu4x_AnyCalendarKind_get_for_bcp47_mv1(diplomatReceive.buffer, ...sSlice.splat());
143
144        try {
145            if (!diplomatReceive.resultFlag) {
146                return null;
147            }
148            return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
149        }
150
151        finally {
152            functionCleanupArena.free();
153
154            diplomatReceive.free();
155        }
156    }
157
158    get bcp47() {
159        const write = new diplomatRuntime.DiplomatWriteBuf(wasm);
160        wasm.icu4x_AnyCalendarKind_bcp47_mv1(this.ffiValue, write.buffer);
161
162        try {
163            return write.readString8();
164        }
165
166        finally {
167            write.free();
168        }
169    }
170
171    constructor(value) {
172        return this.#internalConstructor(...arguments)
173    }
174}