Reddish
A Rust utility library, making easier by taking the hassle out of working. :octocat:
Install / Use
/learn @rodgeraraujo/ReddishREADME
🦀 Reddish
Reddish is a comprehensive Rust utility library inspired by popular JavaScript libraries like Lodash and Ramda. It provides a rich collection of utility functions for common programming tasks including string manipulation, array operations, object handling, cryptographic functions, random number generation, and date/time operations.
✨ Features
- 🔧 55+ Utility Functions across 7 modules
- 🎯 Zero Dependencies for core functionality (optional dependencies for specific modules)
- 🚀 High Performance with Rust's memory safety guarantees
- 📦 Modular Design with feature flags for selective compilation
- 🧪 100% Test Coverage with comprehensive unit tests and doctests
- 📚 Extensive Documentation with examples for every function
- 🔒 Type Safe leveraging Rust's powerful type system
🚀 Quick Start
Add Reddish to your Cargo.toml:
[dependencies]
reddish = "0.2.0"
Or install with specific features only:
[dependencies]
reddish = { version = "0.2.0", features = ["string", "array"] }
Basic Usage
use reddish::*;
fn main() {
// String utilities
let title = capitalize("hello world");
println!("{}", title); // "Hello world"
// Array operations
let numbers = vec![1, 2, 3, 4, 5];
let evens = find(&numbers, |&x| x % 2 == 0);
println!("{:?}", evens); // Some(2)
// Object manipulation
use std::collections::HashMap;
let mut user = HashMap::new();
user.insert("name", "John");
user.insert("age", "30");
let keys = keys(&user);
println!("{:?}", keys); // ["name", "age"]
// Date/time operations
use chrono::Utc;
let now = Utc::now();
let duration = format_duration(3661);
println!("{}", duration); // "1h 1m 1s"
// Random utilities
let random_num = random_int(1, 100);
let uuid = uuid();
println!("Random: {}, UUID: {}", random_num, uuid);
// Crypto functions
let hash = md5_hash("hello world");
let encoded = base64_encode("hello world");
println!("MD5: {}, Base64: {}", hash, encoded);
}
📦 Modules & Features
Reddish is organized into feature-gated modules, allowing you to include only what you need:
🔤 String Methods
Feature: string
Transform and manipulate strings with ease.
capitalize(s: &str)- Capitalizes the first charactercamel_case(s: &str)- Converts to camelCasesnake_case(s: &str)- Converts to snake_casekebab_case(s: &str)- Converts to kebab-casetitle_case(s: &str)- Converts to Title Casepad(s: &str, length: usize, pad_char: char)- Pads string to lengthpad_end(s: &str, length: usize, pad_char: char)- Pads string at endtruncate(s: &str, length: usize)- Truncates string to length
use reddish::*;
let text = "hello world";
assert_eq!(capitalize(text), "Hello world");
assert_eq!(camel_case(text), "helloWorld");
assert_eq!(snake_case("Hello World"), "hello_world");
📊 Array Methods
Feature: array
Powerful array manipulation and search functions.
concat(vec1: &[T], vec2: &[T])- Concatenates two arraysdifference(vec1: &[T], vec2: &[T])- Returns elements in first but not secondfind_index(vec: &[T], predicate: F)- Finds first matching indexfind_last_index(vec: &[T], predicate: F)- Finds last matching indexjoin(vec: &[T], separator: &str)- Joins elements into string
use reddish::*;
let numbers = vec![1, 2, 3, 4, 5];
let index = find_index(&numbers, |&x| x > 3);
assert_eq!(index, Some(3)); // Index of element 4
let words = vec!["hello", "world"];
assert_eq!(join(&words, " "), "hello world");
🗂️ Object Methods
Feature: object
HashMap utilities for object-like operations.
keys(map: &HashMap<K, V>)- Returns all keysvalues(map: &HashMap<K, V>)- Returns all valuesentries(map: &HashMap<K, V>)- Returns key-value pairshas_key(map: &HashMap<K, V>, key: &K)- Checks if key existspick(map: &HashMap<K, V>, keys: &[&K])- Creates new map with selected keysomit(map: &HashMap<K, V>, keys: &[&K])- Creates new map without selected keysmerge(map1: &HashMap<K, V>, map2: &HashMap<K, V>)- Merges two maps
use reddish::*;
use std::collections::HashMap;
let mut user = HashMap::new();
user.insert("name", "Alice");
user.insert("age", "25");
user.insert("city", "NYC");
let personal = pick(&user, &["name", "age"]);
// personal contains only "name" and "age"
📚 Collection Methods
Feature: collection
Advanced collection manipulation functions.
chunk(vec: &[T], size: usize)- Splits array into chunksflatten(vec: &[Vec<T>])- Flattens nested arraysgroup_by(vec: &[T], key_fn: F)- Groups elements by key functionunique(vec: &[T])- Returns unique elementspartition(vec: &[T], predicate: F)- Splits array by predicatezip(vec1: &[T], vec2: &[U])- Combines two arrays into tuplescount_by(vec: &[T], key_fn: F)- Counts elements by key function
use reddish::*;
let numbers = vec![1, 2, 3, 4, 5, 6];
let chunks = chunk(&numbers, 2);
// chunks: [[1, 2], [3, 4], [5, 6]]
let words = vec!["apple", "banana", "apricot"];
let grouped = group_by(&words, |s| s.chars().next().unwrap());
// Groups by first letter: {'a': ["apple", "apricot"], 'b': ["banana"]}
🔐 Crypto/Hash Methods
Feature: crypto
Cryptographic and encoding utilities.
md5_hash(data: &str)- Computes MD5 hashsha256_hash(data: &str)- Computes SHA256 hashbase64_encode(data: &str)- Encodes to Base64base64_decode(data: &str)- Decodes from Base64url_encode(data: &str)- URL encodes stringurl_decode(data: &str)- URL decodes stringhex_encode(data: &str)- Encodes to hexadecimalhex_decode(data: &str)- Decodes from hexadecimal
use reddish::*;
let text = "hello world";
let hash = sha256_hash(text);
let encoded = base64_encode(text);
let url_safe = url_encode("hello world!");
println!("SHA256: {}", hash);
println!("Base64: {}", encoded);
println!("URL: {}", url_safe);
🎲 Random Methods
Feature: random
Random number generation and sampling utilities.
random_int(min: i32, max: i32)- Random integer in rangerandom_float(min: f64, max: f64)- Random float in rangerandom_choice(slice: &[T])- Random element from sliceshuffle(vec: &mut Vec<T>)- Shuffles vector in placesample(slice: &[T], n: usize)- Random sample without replacementrandom_string(length: usize)- Random alphanumeric stringuuid()- Generates UUID v4random_bool()- Random booleanrandom_bool_with_probability(probability: f64)- Weighted random boolean
use reddish::*;
let dice_roll = random_int(1, 6);
let coin_flip = random_bool();
let user_id = uuid();
let colors = vec!["red", "green", "blue"];
let chosen_color = random_choice(&colors);
let mut deck = vec![1, 2, 3, 4, 5];
shuffle(&mut deck); // Randomizes order
📅 DateTime Methods
Feature: datetime
Comprehensive date and time manipulation.
format_duration(seconds: u64)- Formats duration as human readabletime_ago(datetime: &DateTime<Utc>)- Relative time formattingis_weekend(datetime: &DateTime<Utc>)- Checks if date is weekenddays_between(date1, date2)- Calculates days between datesadd_days(datetime, days)- Adds/subtracts daysstart_of_week(datetime)- Gets start of week (Monday)end_of_month(datetime)- Gets end of monthparse_date(date_str: &str)- Parses various date formatsformat_date(datetime, format)- Custom date formattingformat_date_human(datetime)- Human-readable date formatformat_date_iso(datetime)- ISO 8601 format
use reddish::*;
use chrono::{Utc, TimeZone};
let now = Utc::now();
let yesterday = add_days(&now, -1);
println!("Yesterday was: {}", time_ago(&yesterday));
println!("Duration: {}", format_duration(3661)); // "1h 1m 1s"
let date = parse_date("2023-12-25").unwrap();
println!("Christmas: {}", format_date_human(&date));
🔧 Feature Flags
Reddish uses Cargo features to allow selective compilation:
[dependencies]
# Include all features (default)
reddish = "0.2.0"
# Include only specific features
reddish = { version = "0.2.0", features = ["string", "array", "crypto"] }
# Minimal installation (no optional dependencies)
reddish = { version = "0.2.0", default-features = false, features = ["string"] }
Available Features
| Feature | Description | Dependencies |
|---------|-------------|--------------|
| string | String manipulation utilities | None |
| array | Array operations | None |
| object | HashMap utilities | None |
| collection | Advanced collection functions | None |
| crypto | Cryptographic functions | md5, sha2, base64, percent-encoding, hex |
| random | Random number generation | rand, uuid |
| datetime | Date/time operations | chrono |
📖 Examples
The examples/ directory contains comprehensive examples for each module:
# Run examples
cargo run --example string
cargo run --example array
cargo run --example object
cargo run --example collection
cargo run --example crypto
cargo run --example random
cargo run --example datetime
Each example demonstrates practical use cases and best practices.
🧪 Testing
Reddish has extensive test coverage with over 100 tests:
Related Skills
himalaya
347.2kCLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
node-connect
347.2kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
taskflow
347.2kname: taskflow description: Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layer
frontend-design
108.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
