Skip to content

Commit 31f5696

Browse files
authored
Merge pull request #3 from klos71/develop
Release 0.0.8
2 parents c9ebc03 + 78ea773 commit 31f5696

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.github/workflows/pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
repo_token: "${{ secrets.GITHUB_TOKEN }}"
3131
automatic_release_tag: "latest"
32-
prerelease: false
32+
prerelease: true
3333
files: |
3434
pkg/*
3535
id: "automatic_releases"

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "cwjh_wasm"
3-
version = "0.0.8"
3+
version = "0.0.9"
44
edition = "2021"
55
description = "A set of rust utils"
66
repository = "https://github.com/klos71/cwjh_wasm_tools.git"

src/lib.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ pub fn string_to_binary(msg: String) -> String {
1515
msg_in_binary
1616
}
1717

18+
#[wasm_bindgen]
19+
pub fn binary_to_string(msg: &str) -> String {
20+
return msg
21+
.split(" ")
22+
.map(|n| u32::from_str_radix(n, 2).unwrap())
23+
.map(|c| char::from_u32(c).unwrap())
24+
.collect();
25+
}
26+
1827
#[cfg(test)]
1928
mod test {
2029
use crate::add;
30+
use crate::binary_to_string;
2131
use crate::string_to_binary;
2232
use wasm_bindgen_test::*;
2333

@@ -40,4 +50,14 @@ mod test {
4050
"01101011 01101100 01101111 01110011 0110111 0110001 ".to_string()
4151
);
4252
}
53+
54+
#[wasm_bindgen_test]
55+
fn test_binary_to_string() {
56+
assert_eq!(binary_to_string("01100001"), "a");
57+
assert_eq!(binary_to_string("01100001 01100010"), "ab".to_string());
58+
assert_eq!(
59+
binary_to_string("01101011 01101100 01101111 01110011 0110111 0110001"),
60+
"klos71".to_string()
61+
);
62+
}
4363
}

0 commit comments

Comments
 (0)