• 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 `JoiningType`](https://docs.rs/icu/latest/icu/properties/props/struct.JoiningType.html) for more information.
7*/
8
9
10export class JoiningType {
11
12    #value = undefined;
13
14    static #values = new Map([
15        ["NonJoining", 0],
16        ["JoinCausing", 1],
17        ["DualJoining", 2],
18        ["LeftJoining", 3],
19        ["RightJoining", 4],
20        ["Transparent", 5]
21    ]);
22
23    static getAllEntries() {
24        return JoiningType.#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 JoiningType.#objectValues[arguments[1]];
36        }
37
38        if (value instanceof JoiningType) {
39            return value;
40        }
41
42        let intVal = JoiningType.#values.get(value);
43
44        // Nullish check, checks for null or undefined
45        if (intVal != null) {
46            return JoiningType.#objectValues[intVal];
47        }
48
49        throw TypeError(value + " is not a JoiningType and does not correspond to any of its enumerator values.");
50    }
51
52    static fromValue(value) {
53        return new JoiningType(value);
54    }
55
56    get value() {
57        return [...JoiningType.#values.keys()][this.#value];
58    }
59
60    get ffiValue() {
61        return this.#value;
62    }
63    static #objectValues = [
64        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0),
65        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1),
66        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2),
67        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3),
68        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4),
69        new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5),
70    ];
71
72    static NonJoining = JoiningType.#objectValues[0];
73    static JoinCausing = JoiningType.#objectValues[1];
74    static DualJoining = JoiningType.#objectValues[2];
75    static LeftJoining = JoiningType.#objectValues[3];
76    static RightJoining = JoiningType.#objectValues[4];
77    static Transparent = JoiningType.#objectValues[5];
78
79    static forChar(ch) {
80        const result = wasm.icu4x_JoiningType_for_char_mv1(ch);
81
82        try {
83            return new JoiningType(diplomatRuntime.internalConstructor, result);
84        }
85
86        finally {}
87    }
88
89    longName() {
90        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
91
92        const result = wasm.icu4x_JoiningType_long_name_mv1(diplomatReceive.buffer, this.ffiValue);
93
94        try {
95            if (!diplomatReceive.resultFlag) {
96                return null;
97            }
98            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
99        }
100
101        finally {
102            diplomatReceive.free();
103        }
104    }
105
106    shortName() {
107        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 9, 4, true);
108
109        const result = wasm.icu4x_JoiningType_short_name_mv1(diplomatReceive.buffer, this.ffiValue);
110
111        try {
112            if (!diplomatReceive.resultFlag) {
113                return null;
114            }
115            return new diplomatRuntime.DiplomatSliceStr(wasm, diplomatReceive.buffer,  "string8", []).getValue();
116        }
117
118        finally {
119            diplomatReceive.free();
120        }
121    }
122
123    toIntegerValue() {
124        const result = wasm.icu4x_JoiningType_to_integer_value_mv1(this.ffiValue);
125
126        try {
127            return result;
128        }
129
130        finally {}
131    }
132
133    static fromIntegerValue(other) {
134        const diplomatReceive = new diplomatRuntime.DiplomatReceiveBuf(wasm, 5, 4, true);
135
136        const result = wasm.icu4x_JoiningType_from_integer_value_mv1(diplomatReceive.buffer, other);
137
138        try {
139            if (!diplomatReceive.resultFlag) {
140                return null;
141            }
142            return new JoiningType(diplomatRuntime.internalConstructor, diplomatRuntime.enumDiscriminant(wasm, diplomatReceive.buffer));
143        }
144
145        finally {
146            diplomatReceive.free();
147        }
148    }
149
150    constructor(value) {
151        return this.#internalConstructor(...arguments)
152    }
153}