WebAssembly support
This commit is contained in:
parent
280ccd77dd
commit
a16860f631
4 changed files with 12 additions and 3 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/pkg
|
||||
/target
|
||||
/Cargo.lock
|
||||
/Cargo.lock
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "schmfy"
|
||||
version = "0.2.2"
|
||||
version = "0.3.0"
|
||||
edition = "2021"
|
||||
license = "MIT OR Apache-2.0"
|
||||
description = "Schmfication library"
|
||||
|
@ -8,4 +8,8 @@ readme = "README.md"
|
|||
repository = "https://git.flueren.eu/JonOfUs/Schmfy"
|
||||
documentation = "https://docs.rs/schmfy"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = "0.2"
|
||||
|
|
|
@ -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
|
||||
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.
|
||||
|
||||
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>`.
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
//! schmfy - a library to schmfy everything
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
#[derive(PartialEq, Copy, Clone)]
|
||||
enum CaseType {
|
||||
|
@ -63,6 +64,7 @@ fn restore_case(txt: String, case: CaseType) -> String {
|
|||
}
|
||||
|
||||
/// Schmfies any str, preserving case and everything non-alphabetical
|
||||
#[wasm_bindgen]
|
||||
pub fn schmfy(source: &str) -> String {
|
||||
// instantly return if input is non-alphabetic single char
|
||||
if source.len() == 1 && !source.chars().next().unwrap().is_alphabetic() {
|
||||
|
|
Loading…
Reference in a new issue