1// generated by diplomat-tool 2import wasm from "./diplomat-wasm.mjs"; 3import * as diplomatRuntime from "./diplomat-runtime.mjs"; 4 5 6/** An ICU4X Units Converter object, capable of converting between two [`MeasureUnit`]s. 7* 8*You can create an instance of this object using [`UnitsConverterFactory`] by calling the `converter` method. 9* 10*See the [Rust documentation for `UnitsConverter`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html) for more information. 11*/ 12const UnitsConverter_box_destroy_registry = new FinalizationRegistry((ptr) => { 13 wasm.icu4x_UnitsConverter_destroy_mv1(ptr); 14}); 15 16export class UnitsConverter { 17 18 // Internal ptr reference: 19 #ptr = null; 20 21 // Lifetimes are only to keep dependencies alive. 22 // Since JS won't garbage collect until there are no incoming edges. 23 #selfEdge = []; 24 25 #internalConstructor(symbol, ptr, selfEdge) { 26 if (symbol !== diplomatRuntime.internalConstructor) { 27 console.error("UnitsConverter is an Opaque type. You cannot call its constructor."); 28 return; 29 } 30 31 this.#ptr = ptr; 32 this.#selfEdge = selfEdge; 33 34 // Are we being borrowed? If not, we can register. 35 if (this.#selfEdge.length === 0) { 36 UnitsConverter_box_destroy_registry.register(this, this.#ptr); 37 } 38 39 return this; 40 } 41 get ffiValue() { 42 return this.#ptr; 43 } 44 45 convertNumber(value) { 46 const result = wasm.icu4x_UnitsConverter_convert_double_mv1(this.ffiValue, value); 47 48 try { 49 return result; 50 } 51 52 finally {} 53 } 54 55 clone() { 56 const result = wasm.icu4x_UnitsConverter_clone_mv1(this.ffiValue); 57 58 try { 59 return new UnitsConverter(diplomatRuntime.internalConstructor, result, []); 60 } 61 62 finally {} 63 } 64 65 constructor(symbol, ptr, selfEdge) { 66 return this.#internalConstructor(...arguments) 67 } 68}