-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d52b076
commit 9e0f8a9
Showing
6 changed files
with
136 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use wasm_bindgen::prelude::*; | ||
use crate::utils::process_lines; | ||
|
||
#[wasm_bindgen] | ||
pub fn reverse_string(s: &str) -> String { | ||
process_lines(s, |line| line.chars().rev().collect()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn count_vowels(s: &str) -> u32 { | ||
s.chars() | ||
.filter(|c| "aeiou".contains(*c)) | ||
.count() as u32 | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn lowercase_string(s: &str) -> String { | ||
process_lines(s, |line| line.to_ascii_lowercase()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn uppercase_string(s: &str) -> String { | ||
process_lines(s, |line| line.to_ascii_uppercase()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn remove_whitespace(s: &str) -> String { | ||
process_lines(s, |line| line.chars().filter(|c| !c.is_whitespace()).collect()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
use wasm_bindgen::prelude::*; | ||
use base64::{Engine as _, engine::general_purpose}; | ||
use data_encoding::{HEXLOWER as BASE16, BASE32}; | ||
use base85::{encode, decode}; | ||
use crate::utils::process_lines; | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base16(s: &str) -> String { | ||
process_lines(s, |line| BASE16.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base16(s: &str) -> String { | ||
process_lines(s, |line| { | ||
BASE16.decode(line.as_bytes()) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base32(s: &str) -> String { | ||
process_lines(s, |line| BASE32.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base32(s: &str) -> String { | ||
process_lines(s, |line| { | ||
BASE32.decode(line.as_bytes()) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base85(s: &str) -> String { | ||
process_lines(s, |line| encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base85(s: &str) -> String { | ||
process_lines(s, |line| { | ||
decode(line).map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base64_standard(s: &str) -> String { | ||
process_lines(s, |line| general_purpose::STANDARD.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base64_standard(s: &str) -> String { | ||
process_lines(s, |line| { | ||
general_purpose::STANDARD.decode(line) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base64_url(s: &str) -> String { | ||
process_lines(s, |line| general_purpose::URL_SAFE.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base64_url(s: &str) -> String { | ||
process_lines(s, |line| { | ||
general_purpose::URL_SAFE.decode(line) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
use wasm_bindgen::prelude::*; | ||
use md5::{Md5, Digest}; | ||
use sha1::Sha1; | ||
use sha2::Sha256; | ||
use crate::utils::process_lines; | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_md5(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Md5::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_sha1(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Sha1::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_sha256(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Sha256::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,126 +1,3 @@ | ||
use wasm_bindgen::prelude::*; | ||
use base64::{Engine as _, engine::general_purpose}; | ||
use data_encoding::{HEXLOWER as BASE16, BASE32}; | ||
use base85::{encode, decode}; | ||
use crate::utils::process_lines; | ||
use md5::{Md5, Digest as Md5Digest}; | ||
use sha1::{Sha1, Digest as Sha1Digest}; | ||
use sha2::{Sha256, Digest as Sha256Digest}; | ||
|
||
#[wasm_bindgen] | ||
pub fn reverse_string(s: &str) -> String { | ||
process_lines(s, |line| line.chars().rev().collect()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn count_vowels(s: &str) -> u32 { | ||
s.chars() | ||
.filter(|c| "aeiou".contains(*c)) | ||
.count() as u32 | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn lowercase_string(s: &str) -> String { | ||
process_lines(s, |line| line.to_ascii_lowercase()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn uppercase_string(s: &str) -> String { | ||
process_lines(s, |line| line.to_ascii_uppercase()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn remove_whitespace(s: &str) -> String { | ||
process_lines(s, |line| line.chars().filter(|c| !c.is_whitespace()).collect()) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base16(s: &str) -> String { | ||
process_lines(s, |line| BASE16.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base16(s: &str) -> String { | ||
process_lines(s, |line| { | ||
BASE16.decode(line.as_bytes()) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base32(s: &str) -> String { | ||
process_lines(s, |line| BASE32.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base32(s: &str) -> String { | ||
process_lines(s, |line| { | ||
BASE32.decode(line.as_bytes()) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base85(s: &str) -> String { | ||
process_lines(s, |line| encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base85(s: &str) -> String { | ||
process_lines(s, |line| { | ||
decode(line).map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base64_standard(s: &str) -> String { | ||
process_lines(s, |line| general_purpose::STANDARD.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base64_standard(s: &str) -> String { | ||
process_lines(s, |line| { | ||
general_purpose::STANDARD.decode(line) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn encode_base64_url(s: &str) -> String { | ||
process_lines(s, |line| general_purpose::URL_SAFE.encode(line.as_bytes())) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn decode_base64_url(s: &str) -> String { | ||
process_lines(s, |line| { | ||
general_purpose::URL_SAFE.decode(line) | ||
.map_or(String::new(), |v| String::from_utf8_lossy(&v).into_owned()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_md5(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Md5::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_sha1(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Sha1::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} | ||
|
||
#[wasm_bindgen] | ||
pub fn calculate_sha256(s: &str) -> String { | ||
process_lines(s, |line| { | ||
let mut hasher = Sha256::new(); | ||
hasher.update(line.as_bytes()); | ||
format!("{:x}", hasher.finalize()) | ||
}) | ||
} | ||
mod basic; | ||
mod encoding; | ||
mod hash; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters