rok-utils 0.2.2

Laravel/AdonisJS-inspired utility helpers for the Rok ecosystem
Documentation
//! # 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
//!
//! ```rust
//! 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
//!
//! ```rust
//! 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");
//! ```

pub mod arr;
pub mod data;
pub mod errors;
pub mod fp;
pub mod fs;
pub mod path;
pub mod result;
pub mod str;
pub mod string;
pub mod types;

pub use arr::*;
pub use data::numbers;
pub use errors::ResultExt as RokResultExt;
pub use errors::{ResultExt, RokError};
pub use fp::{apply, compose, memoize, or_default, pipe, retry, tap, Lazy};
pub use fs::{
    copy_dir_all, ensure_dir, find_files, is_dir, is_file, read_bytes, read_to_string, write_atomic,
};
pub use path::{normalize, stem_ext, with_extension};
pub use str::{to_base64, Str};
pub use string::{
    char_at, contains, contains_all, doesnt_contain, ends_with, ensure_start, finish, invert_case,
    is_alphanumeric, is_ascii, is_empty, is_url, lcfirst, length, mask, pad_both, pad_left,
    pad_right, pluralize, position, pretty_duration, repeat, replace_first, replace_last, reverse,
    slug, squish, starts_with, substr_count, to_camel_case, to_dot_case, to_headline,
    to_kebab_case, to_lower, to_no_case, to_pascal_case, to_screaming_snake, to_sentence_case,
    to_snake_case, to_title_case, to_upper, truncate, ucfirst, unwrap, word_count, wrap,
};

#[cfg(feature = "dates")]
pub use data::{
    add_days, add_hours, diff_days, format_date, human_diff, now, parse_date, today, tomorrow,
    yesterday,
};

#[cfg(feature = "crypto")]
pub use data::{generate_token, hash_sha256, secure_compare, verify_sha256};

#[cfg(feature = "ids")]
pub use data::{is_ulid, is_uuid, ulid, uuid_v4, uuid_v7};

#[cfg(feature = "random")]
pub use string::{password, random};

#[cfg(feature = "json")]
pub use str::escape_html;

#[cfg(feature = "json")]
pub use string::is_json;

#[cfg(feature = "json")]
pub use types::{
    deep_equal, get_path, is_array, is_bool, is_null, is_number, is_object, is_string, set_path,
};

#[cfg(feature = "random")]
pub use fp::shuffle;

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        assert!(true);
    }
}