WebAssembly support
This commit is contained in:
parent
280ccd77dd
commit
a16860f631
4 changed files with 12 additions and 3 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
||||||
|
/pkg
|
||||||
/target
|
/target
|
||||||
/Cargo.lock
|
/Cargo.lock
|
|
@ -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"
|
||||||
|
|
|
@ -13,6 +13,8 @@ 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.
|
||||||
|
|
|
@ -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() {
|
||||||
|
|
Loading…
Reference in a new issue