A modern Rust, WebAssembly, FFI utility library.
Inspired by JavaScript Lodash library.
No dependencies.
wa-sm/wasm
folder)wa-sm
folder)Add wa
to your dependencies on Cargo.toml
. You need to set the features that will be used as well:
shell
wa = { version = "0.2.0", features = ["string", "vector", "array"] }
Wa makes Rust easier by taking the hassle out of working with arrays, numbers, objects, strings, etc. Wa’s modular methods are great for:
string
(Examples: cargo run --example strings
)vector
(Examples: cargo run --example vectors
)array
(Examples: cargo run --example arrays
)util
(Examples: cargo run --example utils
)wasm
(Examples: cargo run --example webassembly
)#[cfg(feature = "string")]
(String) Creates a compiled template function that can interpolate data properties in "interpolate" delimiters using vector
Example
```rust use wa::string::template_vec;
let urltemplate = templatevec("https://api.com/{1}/products/{2}?by={1}".to_string());
let url: String = urltemplate(vec!["85", "23"]); // "https://api.com/85/products/23?by=85" let url2: String = url_template(vec!["23", "85"]); // "https://api.com/23/products/85?by=23" ```
(String) Creates a compiled template function that can interpolate data properties in "interpolate" delimiters
Example:
```rust use std::collections::HashMap; use wa::string::template;
let urltemplate = template("https://api.com/{ userid }/products/{ productid }".tostring()); let url: String = urltemplate(HashMap::from([ ("userid", "85"), ("product_id", "23"), ]));
assert_eq!(url, "https://api.com/85/products/23"); // true ```
(String) replace extended ASCII codes to standards.
Example:
```rust use wa::string::replaceextendedascii;
asserteq!(replaceextendedascii("São Paulo".tostring()), "Sao Paulo"); asserteq!(replaceextendedascii("Água".tostring()), "Agua"); asserteq!(replaceextendedascii("Pão".tostring()), "Pao"); asserteq!(replaceextendedascii("Åke".tostring()), "Ake"); asserteq!(replaceextendedascii("Södermalm".tostring()), "Sodermalm"); asserteq!(replaceextendedascii("Rio de Janeiro".tostring()), "Rio de Janeiro"); ```
(String) Converts the input string into Camel-Case format.
Note: All special characters will be removed and only valid letters remained.
To replace extended ASCII codes to standards, e.g: "ã" to "a". Check wa::string::replace_extended_ascii
.
Example
```rust use wa::string::camel_case;
camelcase("São Paulo".tostring()); // "sãoPaulo" camelcase("Riode_JANEIRO".tostring()); // "rioDeJaneiro" camelcase("Rio de Janeiro".tostring()); // "rioDeJaneiro" camelcase("--stock-----holm--".tostring()); // "stockHolm" camelcase("--stock-----holm--".tostring()); // "stockHolm" camelcase("Rio2DE2janeiro".tostring()); // "rio2de2janeiro" ```
(String) Converts the input string into Kebab-Case format.
Note: All the special characters will be removed and only valid letters remained.
To replace extended ASCII codes to standards, e.g: "ã" to "a". Check wa::string::replace_extended_ascii
.
Example
```rust use wa::string::kebab_case;
kebabcase("São Paulo".tostring()); // "são-paulo" kebabcase("Rio de Janeiro".tostring()); // "foo-bar" kebabcase("--rio--1--".tostring()); // "foo-bar" kebabcase("rIO-de-Janeiro".to_string()); // "f-oo-ba-r" ```
(String) Checks if string ends with the given target string. Note: If position is not provided, it will search through the whole string by default.
Example:
rust
use wa::string::ends_with;
let is_ends_with = ends_with("abc".to_string(), "c".to_string(), None);
// true
let is_ends_with = ends_with("abc".to_string(), "b".to_string(), None);
// false
let is_ends_with = ends_with("abc".to_string(), "bc".to_string(), Some(2));
// false