// generated by diplomat-tool import { Locale } from "./Locale.mjs" import wasm from "./diplomat-wasm.mjs"; import * as diplomatRuntime from "./diplomat-runtime.mjs"; // Base enumerator definition /** The various calendar types currently supported by [`Calendar`] * *See the [Rust documentation for `AnyCalendarKind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html) for more information. */ export class AnyCalendarKind { #value = undefined; static #values = new Map([ ["Iso", 0], ["Gregorian", 1], ["Buddhist", 2], ["Japanese", 3], ["JapaneseExtended", 4], ["Ethiopian", 5], ["EthiopianAmeteAlem", 6], ["Indian", 7], ["Coptic", 8], ["Dangi", 9], ["Chinese", 10], ["Hebrew", 11], ["IslamicCivil", 12], ["IslamicObservational", 13], ["IslamicTabular", 14], ["IslamicUmmAlQura", 15], ["Persian", 16], ["Roc", 17] ]); static getAllEntries() { return AnyCalendarKind.#values.entries(); } constructor(value) { if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { // We pass in two internalConstructor arguments to create *new* // instances of this type, otherwise the enums are treated as singletons. if (arguments[1] === diplomatRuntime.internalConstructor ) { this.#value = arguments[2]; return; } return AnyCalendarKind.#objectValues[arguments[1]]; } if (value instanceof AnyCalendarKind) { return value; } let intVal = AnyCalendarKind.#values.get(value); // Nullish check, checks for null or undefined if (intVal == null) { return AnyCalendarKind.#objectValues[intVal]; } throw TypeError(value + " is not a AnyCalendarKind and does not correspond to any of its enumerator values."); } get value() { return [...AnyCalendarKind.#values.keys()][this.#value]; } get ffiValue() { return this.#value; } static #objectValues = [ new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 13), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16), new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17), ]; static Iso = AnyCalendarKind.#objectValues[0]; static Gregorian = AnyCalendarKind.#objectValues[1]; static Buddhist = AnyCalendarKind.#objectValues[2]; static Japanese = AnyCalendarKind.#objectValues[3]; static JapaneseExtended = AnyCalendarKind.#objectValues[4]; static Ethiopian = AnyCalendarKind.#objectValues[5]; static EthiopianAmeteAlem = AnyCalendarKind.#objectValues[6]; static Indian = AnyCalendarKind.#objectValues[7]; static Coptic = AnyCalendarKind.#objectValues[8]; static Dangi = AnyCalendarKind.#objectValues[9]; static Chinese = AnyCalendarKind.#objectValues[10]; static Hebrew = AnyCalendarKind.#objectValues[11]; static IslamicCivil = AnyCalendarKind.#objectValues[12]; static IslamicObservational = AnyCalendarKind.#objectValues[13]; static IslamicTabular = AnyCalendarKind.#objectValues[14]; static IslamicUmmAlQura = AnyCalendarKind.#objectValues[15]; static Persian = AnyCalendarKind.#objectValues[16]; static Roc = AnyCalendarKind.#objectValues[17]; static getForLocale(locale) { const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_AnyCalendarKind_get_for_locale_mv1(diplomatReceive.buffer, locale.ffiValue); try { if (!diplomatReceive.resultFlag) { return null; } return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); } finally { diplomatReceive.free(); } } static getForBcp47(s) { let functionCleanupArena = new diplomatRuntime.CleanupArena(); const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s)); const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true); const result = wasm.icu4x_AnyCalendarKind_get_for_bcp47_mv1(diplomatReceive.buffer, ...sSlice.splat()); try { if (!diplomatReceive.resultFlag) { return null; } return new AnyCalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer)); } finally { functionCleanupArena.free(); diplomatReceive.free(); } } get bcp47() { const write = new diplomatRuntime.DiplomatWriteBuf(wasm); wasm.icu4x_AnyCalendarKind_bcp47_mv1(this.ffiValue, write.buffer); try { return write.readString8(); } finally { write.free(); } } }