WebAssembly support

This commit is contained in:
JonOfUs 2024-05-10 14:32:05 +02:00
parent 280ccd77dd
commit a16860f631
4 changed files with 12 additions and 3 deletions

3
.gitignore vendored
View file

@ -1,2 +1,3 @@
/pkg
/target /target
/Cargo.lock /Cargo.lock

View file

@ -1,6 +1,6 @@
[package] [package]
name = "schmfy" name = "schmfy"
version = "0.2.2" version = "0.3.0"
edition = "2021" edition = "2021"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
description = "Schmfication library" description = "Schmfication library"
@ -8,4 +8,8 @@ readme = "README.md"
repository = "https://git.flueren.eu/JonOfUs/Schmfy" repository = "https://git.flueren.eu/JonOfUs/Schmfy"
documentation = "https://docs.rs/schmfy" documentation = "https://docs.rs/schmfy"
[lib]
crate-type = ["cdylib"]
[dependencies] [dependencies]
wasm-bindgen = "0.2"

View file

@ -13,8 +13,10 @@ fn improve_text(text: &str) {
} }
``` ```
The library can be compiled to WebAssembly. You will need wasm-pack (`cargo install wasm-pack`) and can then build the library with `wasm-pack build --target web`. This generates a `pkg` folder which can be used in web environments.
## Capabilities ## Capabilities
The schmfication capabilities are able to preserve text case and any non-alphabetical characters. The schmfication capabilities are able to preserve text case and any non-alphabetical characters.
If a non-alphabetical character is between two alphabetical strings, both of the alphabetical strings will be interpreted as completely separate words. If a non-alphabetical character is between two alphabetical strings, both of the alphabetical strings will be interpreted as completely separate words.
For example, the HTML code `<span>Entry<br></span>` will be converted into `<schman>Schmentry<schmer></schman>`. For example, the HTML code `<span>Entry<br></span>` will be converted into `<schman>Schmentry<schmer></schman>`.

View file

@ -1,4 +1,5 @@
//! schmfy - a library to schmfy everything //! schmfy - a library to schmfy everything
use wasm_bindgen::prelude::*;
#[derive(PartialEq, Copy, Clone)] #[derive(PartialEq, Copy, Clone)]
enum CaseType { enum CaseType {
@ -63,6 +64,7 @@ fn restore_case(txt: String, case: CaseType) -> String {
} }
/// Schmfies any str, preserving case and everything non-alphabetical /// Schmfies any str, preserving case and everything non-alphabetical
#[wasm_bindgen]
pub fn schmfy(source: &str) -> String { pub fn schmfy(source: &str) -> String {
// instantly return if input is non-alphabetic single char // instantly return if input is non-alphabetic single char
if source.len() == 1 && !source.chars().next().unwrap().is_alphabetic() { if source.len() == 1 && !source.chars().next().unwrap().is_alphabetic() {