DecimalSignedRoundingMode.mjs (3774B)
1 // generated by diplomat-tool 2 import wasm from "./diplomat-wasm.mjs"; 3 import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6 /** 7 * Mode used in a rounding operation for signed numbers. 8 * 9 * See the [Rust documentation for `SignedRoundingMode`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.SignedRoundingMode.html) for more information. 10 */ 11 12 13 export class DecimalSignedRoundingMode { 14 #value = undefined; 15 16 static #values = new Map([ 17 ["Expand", 0], 18 ["Trunc", 1], 19 ["HalfExpand", 2], 20 ["HalfTrunc", 3], 21 ["HalfEven", 4], 22 ["Ceil", 5], 23 ["Floor", 6], 24 ["HalfCeil", 7], 25 ["HalfFloor", 8] 26 ]); 27 28 static getAllEntries() { 29 return DecimalSignedRoundingMode.#values.entries(); 30 } 31 32 #internalConstructor(value) { 33 if (arguments.length > 1 && arguments[0] === diplomatRuntime.internalConstructor) { 34 // We pass in two internalConstructor arguments to create *new* 35 // instances of this type, otherwise the enums are treated as singletons. 36 if (arguments[1] === diplomatRuntime.internalConstructor ) { 37 this.#value = arguments[2]; 38 return this; 39 } 40 return DecimalSignedRoundingMode.#objectValues[arguments[1]]; 41 } 42 43 if (value instanceof DecimalSignedRoundingMode) { 44 return value; 45 } 46 47 let intVal = DecimalSignedRoundingMode.#values.get(value); 48 49 // Nullish check, checks for null or undefined 50 if (intVal != null) { 51 return DecimalSignedRoundingMode.#objectValues[intVal]; 52 } 53 54 throw TypeError(value + " is not a DecimalSignedRoundingMode and does not correspond to any of its enumerator values."); 55 } 56 57 static fromValue(value) { 58 return new DecimalSignedRoundingMode(value); 59 } 60 61 get value(){ 62 return [...DecimalSignedRoundingMode.#values.keys()][this.#value]; 63 } 64 65 get ffiValue(){ 66 return this.#value; 67 } 68 static #objectValues = [ 69 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 0), 70 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 1), 71 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 2), 72 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 3), 73 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 4), 74 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 5), 75 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 6), 76 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 7), 77 new DecimalSignedRoundingMode(diplomatRuntime.internalConstructor, diplomatRuntime.internalConstructor, 8), 78 ]; 79 80 static Expand = DecimalSignedRoundingMode.#objectValues[0]; 81 static Trunc = DecimalSignedRoundingMode.#objectValues[1]; 82 static HalfExpand = DecimalSignedRoundingMode.#objectValues[2]; 83 static HalfTrunc = DecimalSignedRoundingMode.#objectValues[3]; 84 static HalfEven = DecimalSignedRoundingMode.#objectValues[4]; 85 static Ceil = DecimalSignedRoundingMode.#objectValues[5]; 86 static Floor = DecimalSignedRoundingMode.#objectValues[6]; 87 static HalfCeil = DecimalSignedRoundingMode.#objectValues[7]; 88 static HalfFloor = DecimalSignedRoundingMode.#objectValues[8]; 89 90 91 constructor(value) { 92 return this.#internalConstructor(...arguments) 93 } 94 }