lo_

Crates.iolo_
lib.rslo_
version0.3.1
created_at2023-10-31 07:23:51.290161+00
updated_at2025-07-28 16:44:50.789708+00
descriptionA modern Rust utility library delivering modularity, performance & extras ported from JavaScript Lodash
homepagehttps://github.com/thedevsaddam/lo_
repositoryhttps://github.com/thedevsaddam/lo_
max_upload_size
id1019411
size92,862
Saddam H (thedevsaddam)

documentation

https://docs.rs/lo_

README

Lo_ as Lodash โ€ƒ

github docs.rs crates.io build status

A modern Rust utility library delivering modularity, performance & extras ported from JavaScript Lodash

Installation

Add lo_ to your Cargo.toml:

[dependencies]
lo_ = { version = "0.3.0", features = ["async_retry"] }

Or run the following command:

cargo add lo_ --features "async_retry"

Usage Examples

๐Ÿงต String Manipulation Utilities

Basic Case Conversions

For quick use, you can import and call built-in helpers like camel_case, snake_case, etc., without needing the trait:

use lo_::camel_case;

let input = "Foo Bar";
let result = camel_case(input);
println!("{:?}", result); // "fooBar"

Use the Transform trait for chainable and expressive string utilities:

use lo_::CaseTransform;

let s = "HelloWorld";
println!("to_snake_case: {:?}", s.to_snake_case()); // "hello_world"
println!("to_camel_case: {:?}", s.to_camel_case()); // "helloWorld"
println!("to_title_case: {:?}", s.to_title_case()); // "Hello World"
println!("to_lower_first: {:?}", s.to_lower_first()); // "helloWorld"
println!("to_upper_first: {:?}", s.to_upper_first()); // "HelloWorld"

use lo_::WordTransform;

let input = "fred, barney, & pebbles";
println!("to_words: {:?}", input.to_words()); // ["fred", "barney", "pebbles"]
println!("to_slug: {:?}", "Rust is awesome ๐Ÿš€".to_slug()); // "rust-is-awesome"

use lo_::UtilityTransform;

let num: Option<i32> = "123".to_safe_parse();
println!("to_safe_parse: {:?}", num); // Some(123)

Word Wrapping

use lo_::WordTransform;

let text = "Rust is blazing fast and memory-efficient.";
let wrapped = text.wordwrap(10, "\n", false);
println!("{}", wrapped);

/*
Rust is
blazing
fast and
memory-efficient.
*/

Padding

use lo_::{UtilityTransform, Alignment};

let s = "42";
assert_eq!(s.pad(5, "0", Alignment::Left), "00042");
assert_eq!(s.pad(5, " ", Alignment::Right), "42   ");
assert_eq!(s.pad(6, "-", Alignment::Center), "--42--");

Word Extraction

use lo_::WordTransform;

let s = "Hello world, this is Rust!";
let words = s.to_words();
assert_eq!(words, vec!["Hello", "world", "this", "is", "Rust"]);

String Templating

use std::collections::HashMap;
use lo_::UtilityTransform;

let mut data = HashMap::new();
data.insert("name", "Ragnar");
data.insert("lang", "Rust");

let template = "Hi {name}, welcome to {lang}!";
let rendered = template.to_template(&data);
assert_eq!(rendered, "Hi Ragnar, welcome to Rust!");

๐Ÿ“ฆ Collection Utilities

use lo_::{chunk, find, uniq};

let array = vec![1, 2, 3, 4, 5, 6, 7];
let size = 3;
let chunks = chunk(array, size);
println!("array chunks: {:?}", chunks); // array chunks: [[1, 2, 3], [4, 5, 6], [7]]


let numbers = vec![1, 2, 3, 4, 5];
let is_even = |x: &i32| *x % 2 == 0;
println!("{:?}", find(&numbers, is_even)); // Some(2)


let input = vec![2, 1, 2];
let output = uniq(input);
println!("{:?}", output) // [2, 1]

โœ‚๏ธ General Utilities

use lo_::retry;
use std::time::Duration;

let mut count = 0;
let result = retry(4, Duration::from_millis(10), || {
    count += 1;
    if count < 3 {
        Err("fail")
    } else {
        Ok("success")
    }
});
println!("{:?} after {:?} retry", result, count); // Ok("success") after 3 retry
Commit count: 35

cargo fmt