Expand description
Rhai packages for cleaning business data: contact and company records, dates, numbers and money, and text.
Every function is written in plain Rhai, is pure, and uses only core Rhai, so it behaves the same in any engine. The packages compile the bundled scripts once; register a package with as many engines as you like.
§Quick start
use rhai::Engine;
use rhai::packages::Package;
use rhai_data_quality::DataQualityPackage;
let mut engine = Engine::new();
DataQualityPackage::new().register_into_engine(&mut engine);
let email: String = engine.eval(r#"normalize_email(" Jane.Doe@Example.COM ")"#).unwrap();
assert_eq!(email, "jane.doe@example.com");
let date: String = engine.eval(r#"to_iso_date("April 3rd, 2026", "mdy")"#).unwrap();
assert_eq!(date, "2026-04-03");§One module, under a namespace
use rhai::Engine;
use rhai::packages::Package;
use rhai_data_quality::{ContactsPackage, NumbersPackage};
let mut engine = Engine::new();
ContactsPackage::new().register_into_engine_as(&mut engine, "contacts");
NumbersPackage::new().register_into_engine_as(&mut engine, "num");
let phone: String = engine.eval(r#"contacts::phone_e164("(415) 555-0123", "1")"#).unwrap();
assert_eq!(phone, "+14155550123");
let cents: i64 = engine.eval(r#"num::to_cents("1.234,56 €", "auto")"#).unwrap();
assert_eq!(cents, 123456);§Packages
| Package | Script | What it does |
|---|---|---|
DataQualityPackage | all four | everything below |
ContactsPackage | data-quality.rhai | emails, phone numbers, names, company names, domains, URLs, postcodes, states, countries, Luhn check digits, match keys for finding duplicates, missing fields |
DatesPackage | dates.rhai | dates in mixed formats to YYYY-MM-DD, Excel serial dates, Unix timestamps, business days, ISO weeks, fiscal periods, months and ages |
NumbersPackage | numbers.rhai | amounts in US or European formats, percentages, currency codes, banker’s rounding, display formatting, durations, amounts in words |
TextPackage | text.rhai | accents, slugs, truncation, masking, padding, HTML snippets, title, snake, camel and kebab case |
The full function list, with examples and limits, is in the README.
§Requirements
The scripts use floating-point numbers, arrays, object maps and functions, so the engine must
not use Rhai’s no_float, no_index, no_object, no_function or no_module features. If
your engine uses unchecked, turn on this crate’s unchecked feature as well.
The script sources are also available in sources, to load them another way (for example,
as files for a module resolver).
Modules§
- sources
- The bundled Rhai scripts, as source text.
Structs§
- Contacts
Package - Contact and company records (
data-quality.rhai): emails, phone numbers, names, company names, domains, URLs, US ZIP codes and states, Canadian and UK postcodes, country codes, Luhn check digits, match keys for finding duplicates, and missing fields. - Data
Quality Package - Every function in this crate:
ContactsPackage,DatesPackage,NumbersPackageandTextPackagetogether. - Dates
Package - Dates (
dates.rhai): dates written in common formats toYYYY-MM-DD, Excel serial dates, Unix timestamps, days and business days between and added, weekdays, ISO weeks, month ends, quarters, fiscal years and quarters, months and ages. - Numbers
Package - Numbers and money (
numbers.rhai): numbers and amounts in US or European formats, percentages, currency codes, banker’s rounding, display formatting, percent change, safe division, durations, currency rounding, amounts in words and clamping. - Text
Package - Text (
text.rhai): accents, slugs, truncation at a word, initials, masking, left padding, HTML snippets, word counts, title, snake, camel and kebab case, hashtags and mentions, and typographic quotes and dashes.