tidy_viewer_core/
lib.rs

1//! # Tidy-Viewer Core Library
2//! 
3//! This crate contains the core formatting logic for tidy-viewer,
4//! shared between the CLI and Python bindings.
5//! 
6//! ## Overview
7//! 
8//! The core library provides data type inference, string formatting, and significant figure
9//! handling for tabular data. It's designed to be used by both the command-line interface
10//! and Python bindings to ensure consistent behavior across all interfaces.
11//! 
12//! ## Key Features
13//! 
14//! - **Data Type Inference**: Automatically detect and format different data types
15//! - **Significant Figure Formatting**: Intelligent number formatting with configurable precision
16//! - **Column Width Calculation**: Smart column width calculation with Unicode support
17//! - **NA Handling**: Consistent handling of missing values across all formats
18//! - **Unicode Support**: Full Unicode character width calculation and truncation
19//! 
20//! ## Usage
21//! 
22//! ```rust
23//! use tidy_viewer_core::{format_strings, calculate_column_width, is_na};
24//! 
25//! // Format a column of strings
26//! let data = vec!["123.456", "NA", "-42.1", "hello"];
27//! let formatted = format_strings(
28//!     &data,
29//!     2,    // min_col_width
30//!     20,   // max_col_width
31//!     3,    // significant_figures
32//!     false, // preserve_scientific
33//!     13,   // max_decimal_width
34//! );
35//! 
36//! // Calculate optimal column width
37//! let width = calculate_column_width(&formatted, 2, 20);
38//! 
39//! // Check if a value is NA
40//! let is_missing = is_na("NA");
41//! ```
42//! 
43//! ## Data Types Supported
44//! 
45//! - **Numbers**: Integers, floats, scientific notation
46//! - **Dates**: Various date formats
47//! - **Times**: Time formats
48//! - **Logical**: Boolean values (true/false)
49//! - **Text**: General string data
50//! - **NA**: Missing values
51//! 
52//! ## Significant Figures
53//! 
54//! The library provides intelligent significant figure formatting through the `DecimalSplits` struct:
55//! 
56//! ```rust
57//! use tidy_viewer_core::{DecimalSplits, get_final_string};
58//! 
59//! // Create a DecimalSplits instance for formatting
60//! let splits = DecimalSplits {
61//!     val: 123.456,
62//!     sigfig: 3,
63//! };
64//! 
65//! // Get the formatted string
66//! let result = splits.final_string();
67//! assert_eq!(result, "123.");
68//! ```
69
70pub mod datatype;
71
72// Re-export main functions
73pub use datatype::format_strings;
74pub use datatype::is_na;
75pub use datatype::is_negative_number;
76pub use datatype::is_double;
77pub use datatype::is_scientific_notation;
78pub use datatype::format_if_na;
79pub use datatype::format_if_num;
80pub use datatype::calculate_column_width;
81pub use datatype::parse_delimiter;
82pub use datatype::ValueType;
83pub use datatype::infer_type_from_string;
84pub use datatype::get_col_data_type;
85pub use datatype::is_logical;
86pub use datatype::is_integer;
87pub use datatype::is_number;
88pub use datatype::is_time;
89pub use datatype::is_date;
90pub use datatype::is_date_time;
91pub use datatype::is_na_string_padded;
92
93// Re-export sigfig module
94pub use datatype::sigfig::{DecimalSplits, get_final_string};