ifc_lite_wasm/api/
export_data.rs1use super::IfcAPI;
8use ifc_lite_export::{CsvMode, CsvOptions, Ifc5Options, JsonLdOptions, JsonOptions};
9use wasm_bindgen::prelude::*;
10
11#[wasm_bindgen]
12impl IfcAPI {
13 #[wasm_bindgen(js_name = exportCsv)]
17 pub fn export_csv(
18 &self,
19 content: &[u8],
20 mode: String,
21 delimiter: String,
22 include_properties: bool,
23 ) -> Vec<u8> {
24 let mode = match mode.as_str() {
25 "properties" => CsvMode::Properties,
26 "quantities" => CsvMode::Quantities,
27 "spatial" => CsvMode::SpatialHierarchy,
28 _ => CsvMode::Entities,
29 };
30 let opts = CsvOptions {
31 delimiter: if delimiter.is_empty() { ",".to_string() } else { delimiter },
32 include_properties,
33 };
34 ifc_lite_export::export_csv(content, mode, &opts).into_bytes()
35 }
36
37 #[wasm_bindgen(js_name = exportJson)]
39 pub fn export_json(
40 &self,
41 content: &[u8],
42 pretty: bool,
43 include_properties: bool,
44 include_quantities: bool,
45 ) -> Vec<u8> {
46 let opts = JsonOptions { pretty, include_properties, include_quantities };
47 ifc_lite_export::export_json(content, &opts).into_bytes()
48 }
49
50 #[wasm_bindgen(js_name = exportJsonld)]
54 pub fn export_jsonld(
55 &self,
56 content: &[u8],
57 context: String,
58 include_properties: bool,
59 include_quantities: bool,
60 pretty: bool,
61 included: &[u32],
62 ) -> Vec<u8> {
63 let mut opts = JsonLdOptions {
64 include_properties,
65 include_quantities,
66 pretty,
67 included: included.to_vec(),
68 ..Default::default()
69 };
70 if !context.is_empty() {
71 opts.context = context;
72 }
73 ifc_lite_export::export_jsonld(content, &opts).into_bytes()
74 }
75
76 #[wasm_bindgen(js_name = exportIfcx)]
79 pub fn export_ifcx(
80 &self,
81 content: &[u8],
82 only_known_properties: bool,
83 pretty: bool,
84 ) -> Vec<u8> {
85 let opts = Ifc5Options { only_known_properties, pretty, ..Default::default() };
86 ifc_lite_export::export_ifc5(content, &opts).into_bytes()
87 }
88
89 #[wasm_bindgen(js_name = exportUsd)]
93 pub fn export_usd(&self, content: &[u8]) -> Vec<u8> {
94 ifc_lite_export::export_usd(content, &Default::default()).into_bytes()
95 }
96}