tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

CalendarKind.mjs (5910B)


      1 // generated by diplomat-tool
      2 import { Locale } from "./Locale.mjs"
      3 import wasm from "./diplomat-wasm.mjs";
      4 import * as diplomatRuntime from "./diplomat-runtime.mjs";
      5 
      6 
      7 /**
      8 * The various calendar types currently supported by [`Calendar`]
      9 *
     10 * See the [Rust documentation for `AnyCalendarKind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html) for more information.
     11 */
     12 
     13 
     14 export class CalendarKind {
     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        ["HijriTabularTypeIiFriday", 12],
     31        ["HijriSimulatedMecca", 18],
     32        ["HijriTabularTypeIiThursday", 14],
     33        ["HijriUmmAlQura", 15],
     34        ["Persian", 16],
     35        ["Roc", 17]
     36    ]);
     37 
     38    static getAllEntries() {
     39        return CalendarKind.#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 CalendarKind.#objectValues[arguments[1]];
     51        }
     52 
     53        if (value instanceof CalendarKind) {
     54            return value;
     55        }
     56 
     57        let intVal = CalendarKind.#values.get(value);
     58 
     59        // Nullish check, checks for null or undefined
     60        if (intVal != null) {
     61            return CalendarKind.#objectValues[intVal];
     62        }
     63 
     64        throw TypeError(value + " is not a CalendarKind and does not correspond to any of its enumerator values.");
     65    }
     66 
     67    static fromValue(value) {
     68        return new CalendarKind(value);
     69    }
     70 
     71    get value(){
     72        for (let entry of CalendarKind.#values) {
     73            if (entry[1] == this.#value) {
     74                return entry[0];
     75            }
     76        }
     77    }
     78 
     79    get ffiValue(){
     80        return this.#value;
     81    }
     82    static #objectValues = {
     83        [0]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
     84        [1]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
     85        [2]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
     86        [3]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
     87        [4]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
     88        [5]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
     89        [6]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6),
     90        [7]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7),
     91        [8]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8),
     92        [9]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 9),
     93        [10]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 10),
     94        [11]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 11),
     95        [12]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 12),
     96        [18]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 18),
     97        [14]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 14),
     98        [15]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 15),
     99        [16]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 16),
    100        [17]: new CalendarKind(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 17),
    101    };
    102 
    103    static Iso = CalendarKind.#objectValues[0];
    104    static Gregorian = CalendarKind.#objectValues[1];
    105    static Buddhist = CalendarKind.#objectValues[2];
    106    static Japanese = CalendarKind.#objectValues[3];
    107    static JapaneseExtended = CalendarKind.#objectValues[4];
    108    static Ethiopian = CalendarKind.#objectValues[5];
    109    static EthiopianAmeteAlem = CalendarKind.#objectValues[6];
    110    static Indian = CalendarKind.#objectValues[7];
    111    static Coptic = CalendarKind.#objectValues[8];
    112    static Dangi = CalendarKind.#objectValues[9];
    113    static Chinese = CalendarKind.#objectValues[10];
    114    static Hebrew = CalendarKind.#objectValues[11];
    115    static HijriTabularTypeIiFriday = CalendarKind.#objectValues[12];
    116    static HijriSimulatedMecca = CalendarKind.#objectValues[18];
    117    static HijriTabularTypeIiThursday = CalendarKind.#objectValues[14];
    118    static HijriUmmAlQura = CalendarKind.#objectValues[15];
    119    static Persian = CalendarKind.#objectValues[16];
    120    static Roc = CalendarKind.#objectValues[17];
    121 
    122 
    123    /**
    124     * Creates a new [`CalendarKind`] for the specified locale, using compiled data.
    125     *
    126     * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendarKind.html#method.new) for more information.
    127     */
    128    static create(locale) {
    129 
    130        const result = wasm.icu4x_CalendarKind_create_mv1(locale.ffiValue);
    131 
    132        try {
    133            return new CalendarKind(diplomatRuntime.internalConstructor, result);
    134        }
    135 
    136        finally {
    137        }
    138    }
    139 
    140    constructor(value) {
    141        return this.#internalConstructor(...arguments)
    142    }
    143 }