• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// generated by diplomat-tool
2import wasm from "./diplomat-wasm.mjs";
3import * as diplomatRuntime from "./diplomat-runtime.mjs";
4
5
6/** See the [Rust documentation for `PluralCategory`](https://docs.rs/icu/latest/icu/plurals/enum.PluralCategory.html) for more information.
7*/
8
9
10export class PluralCategory {
11
12    #value = undefined;
13
14    static #values = new Map([
15        ["Zero", 0],
16        ["One", 1],
17        ["Two", 2],
18        ["Few", 3],
19        ["Many", 4],
20        ["Other", 5]
21    ]);
22
23    static getAllEntries() {
24        return PluralCategory.#values.entries();
25    }
26
27    #internalConstructor(value) {
28        if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) {
29            // We pass in two internalConstructor arguments to create *new*
30            // instances of this type, otherwise the enums are treated as singletons.
31            if (arguments[1] === diplomatRuntime.internalConstructor ) {
32                this.#value = arguments[2];
33                return this;
34            }
35            return PluralCategory.#objectValues[arguments[1]];
36        }
37
38        if (value instanceof PluralCategory) {
39            return value;
40        }
41
42        let intVal = PluralCategory.#values.get(value);
43
44        // Nullish check, checks for null or undefined
45        if (intVal != null) {
46            return PluralCategory.#objectValues[intVal];
47        }
48
49        throw TypeError(value + " is not a PluralCategory and does not correspond to any of its enumerator values.");
50    }
51
52    static fromValue(value) {
53        return new PluralCategory(value);
54    }
55
56    get value() {
57        return [...PluralCategory.#values.keys()][this.#value];
58    }
59
60    get ffiValue() {
61        return this.#value;
62    }
63    static #objectValues = [
64        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
65        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
66        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
67        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
68        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
69        new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
70    ];
71
72    static Zero = PluralCategory.#objectValues[0];
73    static One = PluralCategory.#objectValues[1];
74    static Two = PluralCategory.#objectValues[2];
75    static Few = PluralCategory.#objectValues[3];
76    static Many = PluralCategory.#objectValues[4];
77    static Other = PluralCategory.#objectValues[5];
78
79    static getForCldrString(s) {
80        let functionCleanupArena = new diplomatRuntime.CleanupArena();
81
82        const sSlice = functionCleanupArena.alloc(diplomatRuntime.DiplomatBuf.str8(wasm, s));
83
84        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
85
86        const result = wasm.icu4x_PluralCategory_get_for_cldr_string_mv1(diplomatReceive.buffer, ...sSlice.splat());
87
88        try {
89            if (!diplomatReceive.resultFlag) {
90                return null;
91            }
92            return new PluralCategory(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
93        }
94
95        finally {
96            functionCleanupArena.free();
97
98            diplomatReceive.free();
99        }
100    }
101
102    constructor(value) {
103        return this.#internalConstructor(...arguments)
104    }
105}