1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! Configuration options for compression behavior.
//!
//! This module provides the [`Config`] struct and the global [`CONFIG`] constant
//! that controls how JSON values are compressed.
//!
//! # Current Limitations
//!
//! Configuration is currently compile-time only via the [`CONFIG`] constant.
//! Runtime configuration may be added in future versions.
//!
//! # Example
//!
//! ```rust
//! use compress_json_rs::CONFIG;
//!
//! // Check current configuration
//! println!("Sort keys: {}", CONFIG.sort_key);
//! println!("Preserve NaN: {}", CONFIG.preserve_nan);
//! println!("Preserve Infinity: {}", CONFIG.preserve_infinite);
//! ```
/// Global configuration for compression behavior.
///
/// This struct defines options that control how JSON values are processed
/// during compression. The library uses a compile-time constant [`CONFIG`]
/// with these settings.
///
/// # Fields
///
/// | Field | Default | Description |
/// |-------|---------|-------------|
/// | `sort_key` | `false` | Sort object keys alphabetically |
/// | `preserve_nan` | `false` | Encode NaN as `N\|0` (vs convert to null) |
/// | `error_on_nan` | `false` | Panic on NaN (only if `preserve_nan` is false) |
/// | `preserve_infinite` | `false` | Encode Infinity as `N\|+`/`N\|-` (vs convert to null) |
/// | `error_on_infinite` | `false` | Panic on Infinity (only if `preserve_infinite` is false) |
///
/// # Key Sorting
///
/// When `sort_key` is `true`, object keys are sorted alphabetically before
/// compression. This ensures consistent output regardless of insertion order,
/// which is useful for:
/// - Deterministic compression output
/// - Easier diff comparison
/// - Consistent hashing of compressed data
///
/// # Special Number Handling (v3.4.0+)
///
/// JSON doesn't support `NaN` or `Infinity`. The handling depends on config:
///
/// | Value | `preserve_*` = true | `preserve_*` = false, `error_*` = true | Both false |
/// |-------|---------------------|----------------------------------------|------------|
/// | NaN | Encoded as `N\|0` | Panic | Becomes `null` |
/// | Infinity | Encoded as `N\|+` | Panic | Becomes `null` |
/// | -Infinity | Encoded as `N\|-` | Panic | Becomes `null` |
///
/// Note: `error_on_nan` and `error_on_infinite` only take effect when
/// their corresponding `preserve_*` option is `false`.
///
/// # Example
///
/// ```rust
/// use compress_json_rs::{Config, CONFIG};
///
/// // View the default configuration
/// assert_eq!(CONFIG.sort_key, false);
/// assert_eq!(CONFIG.preserve_nan, false);
/// assert_eq!(CONFIG.error_on_nan, false);
/// assert_eq!(CONFIG.preserve_infinite, false);
/// assert_eq!(CONFIG.error_on_infinite, false);
/// ```
/// Default configuration matching the TypeScript implementation.
///
/// This constant provides the default behavior for compression:
/// - Object keys maintain their original order
/// - NaN values become `null` (like `JSON.stringify`)
/// - Infinity values become `null` (like `JSON.stringify`)
///
/// To preserve special values, set `preserve_nan` and/or `preserve_infinite` to `true`.
///
/// # Values
///
/// ```rust
/// use compress_json_rs::CONFIG;
///
/// // All options default to false
/// assert!(!CONFIG.sort_key);
/// assert!(!CONFIG.preserve_nan);
/// assert!(!CONFIG.error_on_nan);
/// assert!(!CONFIG.preserve_infinite);
/// assert!(!CONFIG.error_on_infinite);
/// ```
///
/// # Compatibility
///
/// These defaults match the JavaScript [compress-json](https://github.com/beenotung/compress-json)
/// library v3.4.0+, ensuring cross-platform compatibility.
pub const CONFIG: Config = Config ;