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 `EastAsianWidth`](https://docs.rs/icu/latest/icu/properties/props/struct.EastAsianWidth.html) for more information. 7*/ 8 9 10export class EastAsianWidth { 11 12 #value = undefined; 13 14 static #values = new Map([ 15 ["Neutral", 0], 16 ["Ambiguous", 1], 17 ["Halfwidth", 2], 18 ["Fullwidth", 3], 19 ["Narrow", 4], 20 ["Wide", 5] 21 ]); 22 23 static getAllEntries() { 24 return EastAsianWidth.#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 EastAsianWidth.#objectValues[arguments[1]]; 36 } 37 38 if (value instanceof EastAsianWidth) { 39 return value; 40 } 41 42 let intVal = EastAsianWidth.#values.get(value); 43 44 // Nullish check, checks for null or undefined 45 if (intVal != null) { 46 return EastAsianWidth.#objectValues[intVal]; 47 } 48 49 throw TypeError(value + " is not a EastAsianWidth and does not correspond to any of its enumerator values."); 50 } 51 52 static fromValue(value) { 53 return new EastAsianWidth(value); 54 } 55 56 get value() { 57 return [...EastAsianWidth.#values.keys()][this.#value]; 58 } 59 60 get ffiValue() { 61 return this.#value; 62 } 63 static #objectValues = [ 64 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), 65 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), 66 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), 67 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), 68 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), 69 new EastAsianWidth(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), 70 ]; 71 72 static Neutral = EastAsianWidth.#objectValues[0]; 73 static Ambiguous = EastAsianWidth.#objectValues[1]; 74 static Halfwidth = EastAsianWidth.#objectValues[2]; 75 static Fullwidth = EastAsianWidth.#objectValues[3]; 76 static Narrow = EastAsianWidth.#objectValues[4]; 77 static Wide = EastAsianWidth.#objectValues[5]; 78 79 static forChar(ch) { 80 const result = wasm.icu4x_EastAsianWidth_for_char_mv1(ch); 81 82 try { 83 return new EastAsianWidth(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_EastAsianWidth_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_EastAsianWidth_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_EastAsianWidth_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_EastAsianWidth_from_integer_value_mv1(diplomatReceive.buffer, other); 137 138 try { 139 if (!diplomatReceive.resultFlag) { 140 return null; 141 } 142 return new EastAsianWidth(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}