|
1 | | -use fastqr_core::{EncodeOptions, ErrorCorrectionLevel, QrCode, encode_text}; |
2 | | -use fastqr_image::{DecodeOptions, RenderOptions, decode_rgba, render_to_rgba}; |
| 1 | +use fastqr_core::{encode_text, EncodeOptions, ErrorCorrectionLevel, QrCode}; |
| 2 | +use fastqr_image::{decode_rgba, render_to_rgba, DecodeOptions, RenderOptions}; |
3 | 3 | use js_sys::{Object, Reflect, Uint8Array}; |
4 | | -use wasm_bindgen::{Clamped, JsCast, JsValue, prelude::wasm_bindgen}; |
| 4 | +use wasm_bindgen::{prelude::wasm_bindgen, Clamped, JsCast, JsValue}; |
5 | 5 | use web_sys::{CanvasRenderingContext2d, HtmlCanvasElement, HtmlVideoElement, ImageData}; |
6 | 6 |
|
7 | 7 | #[wasm_bindgen] |
@@ -184,12 +184,12 @@ fn decoded_to_js(decoded: fastqr_core::DecodedQr) -> Result<JsValue, JsValue> { |
184 | 184 | &JsValue::from_str("bytes"), |
185 | 185 | &Uint8Array::from(decoded.bytes.as_ref()), |
186 | 186 | )?; |
187 | | - let text = decoded.text.map(String::from).unwrap_or_default(); |
188 | | - Reflect::set( |
189 | | - &object, |
190 | | - &JsValue::from_str("text"), |
191 | | - &JsValue::from_str(&text), |
192 | | - )?; |
| 187 | + let text = decoded |
| 188 | + .text |
| 189 | + .as_deref() |
| 190 | + .map(JsValue::from_str) |
| 191 | + .unwrap_or(JsValue::NULL); |
| 192 | + Reflect::set(&object, &JsValue::from_str("text"), &text)?; |
193 | 193 | Ok(object.into()) |
194 | 194 | } |
195 | 195 |
|
|
0 commit comments