oxidite-utils
Utility functions and helpers for the Oxidite web framework. Provides common utilities for date handling, string manipulation, ID generation, and validation.
Overview
oxidite-utils is a collection of general-purpose utility functions and helpers that are commonly needed in web applications. It provides utilities for date/time handling, string manipulation, unique ID generation, validation, and other common tasks.
Installation
Add this to your Cargo.toml:
[]
= "0.1"
Features
- Date/Time utilities - Easy date/time manipulation and formatting
- String utilities - Common string operations and transformations
- ID generation - Unique identifier generation (UUID, snowflake IDs, etc.)
- Validation helpers - Common validation functions for web applications
- Random utilities - Secure random generation for tokens and secrets
- Formatting helpers - Number, currency, and text formatting
- File utilities - Common file operations and path manipulations
- URL utilities - URL parsing, encoding, and manipulation
- Collection helpers - Common operations on vectors, hashes, and other collections
Usage
Date/Time Utilities
Work with dates and times in a convenient way:
use *;
// Get current timestamp
let now = current_timestamp;
println!;
// Format a timestamp
let formatted = format_timestamp;
println!;
// Parse a date string
let parsed = parse_date?;
println!;
// Calculate time differences
let duration = time_since;
println!;
String Utilities
Common string operations:
use *;
// Generate slugs
let slug = slugify;
println!; // Output: "hello-world-this-is-a-test"
// Generate random strings
let random_str = random_string;
println!;
// Case conversion
let snake_case = to_snake_case;
println!; // Output: "camel_case_string"
let kebab_case = to_kebab_case;
println!; // Output: "snake-case-string"
// Safe string truncation
let long_text = "This is a very long text that needs to be truncated";
let truncated = truncate_safe;
println!;
ID Generation
Generate unique identifiers:
use *;
// Generate UUIDs
let uuid = generate_uuid;
println!;
// Generate ULIDs (Universally Unique Lexicographically Sortable Identifiers)
let ulid = generate_ulid;
println!;
// Generate short random IDs
let short_id = generate_short_id;
println!;
// Generate incrementing IDs (useful for databases)
let incrementing_id = generate_incrementing_id;
println!;
Validation Helpers
Validate common input formats:
use *;
// Validate email addresses
let is_email_valid = is_valid_email;
println!;
// Validate URLs
let is_url_valid = is_valid_url;
println!;
// Validate phone numbers
let is_phone_valid = is_valid_phone;
println!;
// Validate passwords
let is_password_strong = is_strong_password;
println!;
Random Utilities
Secure random generation:
use *;
// Generate secure random bytes
let random_bytes = generate_random_bytes;
println!;
// Generate secure random tokens
let token = generate_secure_token;
println!;
// Generate random numbers in range
let random_num = random_range;
println!;
// Generate random boolean
let coin_flip = random_bool;
println!;
Collection Helpers
Utilities for working with collections:
use *;
// Shuffle a vector
let mut numbers = vec!;
shuffle_vec;
println!;
// Get random elements
let random_elements = random_choice;
println!;
// Chunk a vector
let chunks = chunk_vec;
println!;
// Filter duplicates
let unique = unique_items;
println!;
Formatting Helpers
Format values for display:
use *;
// Format numbers
let formatted_num = format_number;
println!;
// Format currency
let formatted_currency = format_currency;
println!;
// Format file sizes
let file_size = format_file_size; // 5 MB
println!;
URL Utilities
Work with URLs:
use *;
// Build query strings
let params = vec!;
let query_string = build_query_string;
println!;
// Sanitize URLs
let sanitized = sanitize_url;
println!;
Custom Validation
Create custom validation rules:
use *;
// Define custom validation rules
let is_valid = validate_username;
println!;
Integration with Oxidite
The utilities are designed to work seamlessly with Oxidite applications:
use *;
use generate_uuid;
async
Performance
The utilities are optimized for performance:
- Minimal allocations where possible
- Efficient algorithms for common operations
- Zero-cost abstractions where applicable
- Proper error handling without performance penalties
Security
Security considerations are built into the utilities:
- Secure random generation for tokens and IDs
- Input sanitization for user-provided data
- Safe string operations that prevent buffer overflows
- Proper validation to prevent injection attacks
License
MIT