diff --git a/wasm/demo/node/src/main.ts b/wasm/demo/node/src/main.ts index 124d5d1..c4a1c39 100644 --- a/wasm/demo/node/src/main.ts +++ b/wasm/demo/node/src/main.ts @@ -1,7 +1,7 @@ import { Dater } from "cesride-wasm"; function main() { - const date = new Dater("2020-08-22T17:50:09.988921+00:00", undefined, undefined, undefined, undefined, undefined); + const date = Dater.new_with_dts("2020-08-22T17:50:09.988921+00:00"); console.log("

Date:

"); console.log("dts: " + date.dts + "
"); console.log("dtsb: " + date.dtsb + "
"); diff --git a/wasm/demo/web/index.html b/wasm/demo/web/index.html index 6240d13..81026df 100644 --- a/wasm/demo/web/index.html +++ b/wasm/demo/web/index.html @@ -45,7 +45,7 @@ await init(); let dts = "2020-08-22T17:50:09.988921+00:00"; - let dater = new Dater(dts, undefined, undefined, undefined, undefined, undefined); + let dater = Dater.new_with_dts(dts); document.write("

Date:

"); document.write("") document.write("dts: " + dater.dts + "
"); @@ -57,7 +57,7 @@ document.write("qb64b: " + dater.qb64b + "
"); document.write("qb2: " + dater.qb2 + "
"); try { - dater = new Dater("asdf", undefined, undefined, undefined, undefined, undefined); + dater = Dater.new_with_dts(dts = "asdf"); document.write("Wrong dater: " + dater.dts + "
"); } catch (error) { document.write("Error: " + error + "
"); diff --git a/wasm/demo/webpack/index.js b/wasm/demo/webpack/index.js index 3223355..3e90a9a 100644 --- a/wasm/demo/webpack/index.js +++ b/wasm/demo/webpack/index.js @@ -13,7 +13,7 @@ document.write(` `) let dts = "2020-08-22T17:50:09.988921+00:00"; -let dater = new cesride.Dater(dts, undefined, undefined, undefined, undefined, undefined); +let dater = cesride.Dater.new_with_dts(dts); const icp = { "v": "KERI10JSON00015a_", diff --git a/wasm/src/primitives/dater.rs b/wasm/src/primitives/dater.rs index eddcb28..94e2970 100644 --- a/wasm/src/primitives/dater.rs +++ b/wasm/src/primitives/dater.rs @@ -31,6 +31,31 @@ impl DaterWrapper { Ok(DaterWrapper(dater)) } + pub fn new_with_dts(dts: &str, code: Option) -> Result { + let dater = Dater::new_with_dts(dts, code.as_deref()).as_js()?; + Ok(DaterWrapper(dater)) + } + + pub fn new_with_raw(raw: &[u8], code: Option) -> Result { + let dater = Dater::new_with_raw(raw, code.as_deref()).as_js()?; + Ok(DaterWrapper(dater)) + } + + pub fn new_with_qb64b(qb64b: &[u8]) -> Result { + let dater = Dater::new_with_qb64b(qb64b).as_js()?; + Ok(DaterWrapper(dater)) + } + + pub fn new_with_qb64(qb64: &str) -> Result { + let dater = Dater::new_with_qb64(qb64).as_js()?; + Ok(DaterWrapper(dater)) + } + + pub fn new_with_qb2(qb2: &[u8]) -> Result { + let dater = Dater::new_with_qb2(qb2).as_js()?; + Ok(DaterWrapper(dater)) + } + #[wasm_bindgen(getter)] pub fn dts(&self) -> Result { self.0.dts().as_js().map_err(JsValue::from)