Debian Codegraph @

intl/icu_capi/bindings/js/ICU4XWeekCalculator.mjs

raw
1 import wasm from "./diplomat-wasm.mjs"
2 import * as diplomatRuntime from "./diplomat-runtime.mjs"
3 import { ICU4XError_js_to_rust, ICU4XError_rust_to_js } from "./ICU4XError.mjs"
4 import { ICU4XIsoWeekday_js_to_rust, ICU4XIsoWeekday_rust_to_js } from "./ICU4XIsoWeekday.mjs"
5 import { ICU4XWeekendContainsDay } from "./ICU4XWeekendContainsDay.mjs"
6
7 const ICU4XWeekCalculator_box_destroy_registry = new FinalizationRegistry(underlying => {
8 wasm.ICU4XWeekCalculator_destroy(underlying);
9 });
10
11 export class ICU4XWeekCalculator {
12 #lifetimeEdges = [];
13 constructor(underlying, owned, edges) {
14 this.underlying = underlying;
15 this.#lifetimeEdges.push(...edges);
16 if (owned) {
17 ICU4XWeekCalculator_box_destroy_registry.register(this, underlying);
18 }
19 }
20
21 static create(arg_provider, arg_locale) {
22 return (() => {
23 const diplomat_receive_buffer = wasm.diplomat_alloc(5, 4);
24 wasm.ICU4XWeekCalculator_create(diplomat_receive_buffer, arg_provider.underlying, arg_locale.underlying);
25 const is_ok = diplomatRuntime.resultFlag(wasm, diplomat_receive_buffer, 4);
26 if (is_ok) {
27 const ok_value = new ICU4XWeekCalculator(diplomatRuntime.ptrRead(wasm, diplomat_receive_buffer), true, []);
28 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
29 return ok_value;
30 } else {
31 const throw_value = ICU4XError_rust_to_js[diplomatRuntime.enumDiscriminant(wasm, diplomat_receive_buffer)];
32 wasm.diplomat_free(diplomat_receive_buffer, 5, 4);
33 throw new diplomatRuntime.FFIError(throw_value);
34 }
35 })();
36 }
37
38 static create_from_first_day_of_week_and_min_week_days(arg_first_weekday, arg_min_week_days) {
39 return new ICU4XWeekCalculator(wasm.ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday_js_to_rust[arg_first_weekday], arg_min_week_days), true, []);
40 }
41
42 first_weekday() {
43 return ICU4XIsoWeekday_rust_to_js[wasm.ICU4XWeekCalculator_first_weekday(this.underlying)];
44 }
45
46 min_week_days() {
47 return wasm.ICU4XWeekCalculator_min_week_days(this.underlying);
48 }
49
50 weekend() {
51 return (() => {
52 const diplomat_receive_buffer = wasm.diplomat_alloc(7, 1);
53 wasm.ICU4XWeekCalculator_weekend(diplomat_receive_buffer, this.underlying);
54 const out = new ICU4XWeekendContainsDay(diplomat_receive_buffer);
55 wasm.diplomat_free(diplomat_receive_buffer, 7, 1);
56 return out;
57 })();
58 }
59 }