json_fixer/jsonfixer/
jsonfixer_config.rs

1use crate::jsonfixer::jsonformatter::IndentStyle;
2
3#[derive(Debug, Clone)]
4pub struct JsonFixerConfig {
5    pub preserve: bool,      // Keep whitesapces, keeps original format
6    pub space_between: bool, // Adds one space after between key and value eg. {"key":"value"} to { "key" : "value" }
7    /*
8    Make it humain readable
9    eg. {"key":"value", "key2": "value"} to
10    {
11        "key": "value",
12        "key2": "value"
13    }
14     */
15    pub beautify: bool,
16    pub indent_style: IndentStyle,
17    pub indent_size: usize,
18    pub sort_keys: bool,
19}
20
21impl Default for JsonFixerConfig {
22    fn default() -> Self {
23        Self {
24            preserve: false,
25            space_between: false,
26            beautify: false,
27            indent_style: IndentStyle::Spaces,
28            indent_size: 0,
29            sort_keys: false,
30        }
31    }
32}
33
34impl JsonFixerConfig {
35    pub fn preserve(&self) -> bool {
36        self.preserve
37    }
38
39    pub fn space_between(&self) -> bool {
40        self.space_between && self.preserve == false
41    }
42
43    pub fn beautify(&self) -> bool {
44        self.beautify && self.preserve == false
45    }
46}