Expand description
§rok-utils
A Laravel/AdonisJS-inspired utility crate for Rust with zero-bloat, ergonomic helpers.
§Features
- String utilities — case conversion, truncation, pluralization, fluent builder
- Array utilities — map, filter, reduce, chunk, unique, group_by
- Error handling — AdonisJS-style error codes with HTTP status
- Functional patterns — pipe, compose, tap, retry, lazy, memoize
- Data utilities — numbers, dates (feature: dates), hashing (feature: crypto), ids (feature: ids)
- Type guards — JSON type guards (feature: json)
- File system helpers — ensure_dir, find_files, copy_dir_all
- Path helpers — normalize, stem_ext, with_extension
§Quick Start
use rok_utils::{to_snake_case, Str};
let snake = to_snake_case("HelloWorld");
assert_eq!(snake, "hello_world");
let result = Str::of(" hello world ")
.trim()
.lower()
.replace(" ", "_")
.value();
assert_eq!(result, "hello_world");§Feature Flags
| Feature | Description |
|---|---|
full | Enable all features |
dates | Enable date/time utilities |
crypto | Enable hashing and token generation |
ids | Enable UUID/ULID generation |
json | Enable JSON type guards and path access |
random | Enable random string generation |
§Example
use rok_utils::{RokError, RokResultExt, Str};
fn find_user(id: u64) -> Result<String, RokError> {
if id == 42 {
Ok("Alice".to_string())
} else {
Err(RokError::NotFound(format!("User #{id}")))
}
}
let result = find_user(42).context("Database query failed");Re-exports§
pub use data::numbers;pub use errors::ResultExt as RokResultExt;pub use errors::ResultExt;pub use errors::RokError;pub use fp::apply;pub use fp::compose;pub use fp::compose;pub use fp::memoize;pub use fp::or_default;pub use fp::pipe;pub use fp::retry;pub use fp::tap;pub use fp::Lazy;pub use fs::copy_dir_all;pub use fs::ensure_dir;pub use fs::find_files;pub use fs::is_dir;pub use fs::is_file;pub use fs::read_bytes;pub use fs::read_to_string;pub use fs::write_atomic;pub use path::normalize;pub use path::stem_ext;pub use path::with_extension;pub use str::to_base64;pub use str::Str;pub use string::char_at;pub use string::contains;pub use string::contains_all;pub use string::doesnt_contain;pub use string::ends_with;pub use string::ensure_start;pub use string::finish;pub use string::invert_case;pub use string::is_alphanumeric;pub use string::is_ascii;pub use string::is_empty;pub use string::is_url;pub use string::lcfirst;pub use string::length;pub use string::mask;pub use string::pad_both;pub use string::pad_left;pub use string::pad_right;pub use string::pluralize;pub use string::position;pub use string::pretty_duration;pub use string::repeat;pub use string::replace_first;pub use string::replace_last;pub use string::reverse;pub use string::slug;pub use string::squish;pub use string::starts_with;pub use string::substr_count;pub use string::to_camel_case;pub use string::to_dot_case;pub use string::to_headline;pub use string::to_kebab_case;pub use string::to_lower;pub use string::to_no_case;pub use string::to_pascal_case;pub use string::to_screaming_snake;pub use string::to_sentence_case;pub use string::to_snake_case;pub use string::to_title_case;pub use string::to_upper;pub use string::truncate;pub use string::ucfirst;pub use string::unwrap;pub use string::word_count;pub use string::wrap;pub use data::add_days;pub use data::add_hours;pub use data::diff_days;pub use data::format_date;pub use data::human_diff;pub use data::now;pub use data::parse_date;pub use data::today;pub use data::tomorrow;pub use data::yesterday;pub use data::generate_token;pub use data::hash_sha256;pub use data::secure_compare;pub use data::verify_sha256;pub use data::is_ulid;pub use data::is_uuid;pub use data::ulid;pub use data::uuid_v4;pub use data::uuid_v7;pub use string::password;pub use string::random;pub use str::escape_html;pub use string::is_json;pub use types::deep_equal;pub use types::get_path;pub use types::is_array;pub use types::is_bool;pub use types::is_null;pub use types::is_number;pub use types::is_object;pub use types::is_string;pub use types::set_path;pub use fp::shuffle;pub use arr::*;
Modules§
- arr
- Array and collection utilities.
- data
- Data utilities for numbers, dates, IDs, and cryptographic operations.
- errors
- Error handling with AdonisJS-inspired typed errors.
- fp
- Functional programming utilities.
- fs
- File system utilities.
- path
- Path helpers.
- result
- Result / error extension traits.
- str
- string
- String case-conversion helpers.
- types
- Runtime type guards and JSON path utilities.