rs-utils
This is a utility library for Portalnesia projects. It contains various helper functions and components that are commonly used across different parts of the application.
Modules
Crypto
The crypto
module provides cryptographic functionalities for securing data. It includes
features encryption, and decryption.
Features
- Encryption/Decryption:
encrypt
: Encrypts data using AES-256-GCM.encrypt_json
: Jsonify and encrypts a structdecrypt
: Decrypts data encrypted with AES-256-GCM.decrypt_json
: Decrypt data and parse to struct
Usage
use Crypto;
use ;
Password
The password
module provides functionalities for securely handling passwords. It includes features for hashing
passwords and verifying them against their hashed versions.
Features
- Hashing:
hash_password
: Securely hashes a password using Argon2.compare_password
: Verifies a password against its hashed version.
Usage
use ;
Helper
The helper
module provides a collection of general-purpose utility functions and macros that are useful across various
parts of the application. This module aims to reduce code duplication and provide convenient tools for common tasks.
Features
String Manipulation
truncate
: Truncates a string to a maximum length, adding "..." at the end if the string is longer thanmax
.clean
: Cleans a string by removing HTML tags and extra whitespace.clean_truncate
: Combinesclean
andtruncate
to clean a string and then truncate it to a maximum length.ucwords
: Capitalizes the first letter of each word in a sentence.capitalize_first
: Capitalizes the first character of a string.slug
: Converts a string to a URL-friendly slug.first_letter!
: Macro to extract the first letter of each word in a string and return them in uppercase.parse_url
: Parses a URL string and returns a simplified version (host, path, query).
ID Generation
uuid
: Generates a UUID v7 string.nanoid!
: Macro to generate a nanoid.
Check
is_url
: Checks if a given string is a valid URL.is_twitter_url
: Checks if a given string is a valid Twitter URL.is_true!
: Macro to check the "truthiness" of a valuevalidate_email
: Validates if a given string is a valid email address.
Number Formatter
bytes_format!
: Macro to format float64 bytes to human-readable string.format_number!
: Macro to format float64 with a thousand separator.format_short_number
: Format a number into a short format.
Usage
use ;
use ;