properties-comparator 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/DOCUMENTATION.md CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  ## Overview
4
4
 
5
- This utility parses and compares **.properties** and **.yml or .yaml (YAML)** files. It reads each file as key-value pairs, compares the values for each key across multiple files, and logs the results.
5
+ This utility parses and compares **.properties** and **.yml or .yaml (YAML)** files. It reads each file as key-value pairs, compares the values for each key across multiple files, and produces detailed comparison reports.
6
6
 
7
7
  ### Features:
8
8
  - Parse **.properties** files into key-value objects.
9
9
  - Parse **.yml or .yaml** (YAML) files into flattened key-value objects (supports nested keys).
10
10
  - Compare key values across multiple files (both **.properties** and **.yml or .yaml**).
11
- - Log detailed comparison results, including mismatches.
11
+ - Generate reports in multiple formats:
12
+ - Console output with color-coded highlighting
13
+ - HTML reports with CSS styling
14
+ - Markdown reports
15
+ - Save reports to files or display in console
16
+ - Flexible command-line interface with options
12
17
 
13
18
  ---
14
19
 
@@ -26,7 +31,26 @@ This utility parses and compares **.properties** and **.yml or .yaml (YAML)** fi
26
31
  Run the script using Node.js with file paths provided as command-line arguments:
27
32
 
28
33
  ```bash
29
- node script.js <filePath1> <filePath2> [<filePath3> ...]
34
+ node compareUtility.js [options] <filePath1> <filePath2> [<filePath3> ...]
35
+ ```
36
+
37
+ ### Command-Line Options
38
+ ```
39
+ Options:
40
+ --format, -f <format> Output format: console, html, or markdown
41
+ --output, -o <file> Output file for html or markdown reports
42
+ ```
43
+
44
+ ### Examples
45
+ ```bash
46
+ # Basic comparison with console output
47
+ node compareUtility.js file1.properties file2.yaml
48
+
49
+ # Generate HTML report and save to output.html
50
+ node compareUtility.js --format html --output output.html file1.properties file2.yaml
51
+
52
+ # Short form options
53
+ node compareUtility.js -f markdown -o report.md file1.properties file2.properties file3.yml
30
54
  ```
31
55
 
32
56
  ### Input Format
@@ -37,6 +61,13 @@ key2=value2
37
61
  # Comments are ignored
38
62
  ```
39
63
 
64
+ YAML files should follow standard YAML format. Nested structures will be flattened with dot notation:
65
+ ```yaml
66
+ key1: value1
67
+ key2:
68
+ nestedKey: nestedValue # Will be accessible as "key2.nestedKey"
69
+ ```
70
+
40
71
  ---
41
72
 
42
73
  ## Functions
@@ -60,113 +91,213 @@ console.log(properties);
60
91
 
61
92
  ---
62
93
 
63
- ### `compareProperties(filePaths)`
94
+ ### `parseYamlFile(filePath)`
64
95
 
65
- Compares properties across multiple properties files and logs the results.
96
+ Parses a .yml or .yaml file into a flat key-value map using dot notation for nested keys.
66
97
 
67
98
  #### Parameters:
68
- - `filePaths` (string[]): Array of file paths to be compared.
99
+ - `filePath` (string): Path to the YAML file.
69
100
 
70
101
  #### Returns:
71
- - None. Outputs comparison results to the console.
102
+ - (Object): A flattened object containing key-value pairs from the YAML file.
72
103
 
73
104
  #### Example:
74
- ```bash
75
- node script.js file1.properties file2.yaml file3.yml
105
+ ```javascript
106
+ const data = parseYamlFile('/path/to/yaml/file');
107
+ console.log(data);
108
+ // Output: { 'key1': 'value1', 'key2.nestedKey': 'nestedValue' }
76
109
  ```
77
110
 
78
- #### Output Example:
79
- ```text
80
- Comparing properties across files:
111
+ ---
81
112
 
82
- Key: key1 - Values match across all files.
83
- Key: key2 - Mismatched values:
84
- File 1: value1
85
- File 2: value2
86
- File 3: value3
87
- ```
113
+ ### `parseFile(filePath)`
114
+
115
+ Detects file extension and parses the file content into an object.
116
+
117
+ #### Parameters:
118
+ - `filePath` (string): Path to the file (.properties, .yml, or .yaml).
119
+
120
+ #### Returns:
121
+ - (Object): Parsed content as a key-value map, or {} if unsupported.
88
122
 
89
123
  ---
90
124
 
91
- ### Runtime Input Handling
125
+ ### `compareFileData(filePaths)`
92
126
 
93
- The script expects file paths as command-line arguments:
94
- - Extracted from `process.argv`.
95
- - If no file paths are provided, it displays an error and exits:
96
- ```
97
- Please provide the paths to the properties files as command-line arguments.
98
- ```
99
- - Verifies the existence of all specified files. If any file is missing:
100
- ```
101
- One or more properties files are missing. Ensure all specified properties files exist.
102
- ```
127
+ Internal helper that compares key-value data from multiple files and returns structured results.
128
+
129
+ #### Parameters:
130
+ - `filePaths` (string[]): Array of file paths.
131
+
132
+ #### Returns:
133
+ - (Object): An object containing mismatch count and detailed comparison information.
134
+
135
+ ---
136
+
137
+ ### `checkIfAllValuesMatch(filePaths)`
138
+
139
+ Checks if all values match across the provided files.
140
+
141
+ #### Parameters:
142
+ - `filePaths` (string[]): Array of file paths.
143
+
144
+ #### Returns:
145
+ - (boolean): True if all properties match across all files, false otherwise.
103
146
 
104
147
  ---
105
148
 
106
- ### Additional Functions
149
+ ### `getMismatchFields(filePaths)`
107
150
 
108
- #### `parseFile(filePath)`
109
- Detects file extension and parses `.properties`, `.yaml`, or `.yml` files. Returns an object with flattened key-value pairs or `{}` if unsupported.
151
+ Returns a list of fields (keys) that do not match across the provided files.
110
152
 
111
- #### `parseYamlFile(filePath)`
112
- Parses a `.yml` or `.yaml` file into a flat key-value map. Returns an object with dot-notation keys for nested values.
153
+ #### Parameters:
154
+ - `filePaths` (string[]): Array of file paths.
113
155
 
114
- #### `compareFileData(filePaths)`
115
- Internally compares parsed data from multiple files. Returns an object with `mismatchCount` and detailed info for each key.
156
+ #### Returns:
157
+ - (string[]): List of mismatched keys.
116
158
 
117
- #### `checkIfAllValuesMatch(filePaths)`
118
- Checks if all keys match across all provided files. Returns a boolean.
159
+ ---
119
160
 
120
- #### `getMismatchFields(filePaths)`
121
- Returns an array of keys whose values differ across files.
161
+ ### `generateHtmlReport(filePaths, comparisonData)`
122
162
 
123
- #### `compareFiles(filePaths)`
124
- Logs detailed comparison of key-value pairs across files. Prints a summary indicating mismatched keys.
163
+ Generates an HTML report for the comparison results.
164
+
165
+ #### Parameters:
166
+ - `filePaths` (string[]): Array of file paths that were compared.
167
+ - `comparisonData` (Object): The output from compareFileData function.
125
168
 
126
- #### `run()`
127
- CLI entry point. Reads file paths, checks existence, and calls `compareFiles`.
169
+ #### Returns:
170
+ - (string): HTML document as string.
171
+
172
+ ---
173
+
174
+ ### `generateMarkdownReport(filePaths, comparisonData)`
175
+
176
+ Generates a Markdown report for the comparison results.
177
+
178
+ #### Parameters:
179
+ - `filePaths` (string[]): Array of file paths that were compared.
180
+ - `comparisonData` (Object): The output from compareFileData function.
181
+
182
+ #### Returns:
183
+ - (string): Markdown document as string.
184
+
185
+ ---
186
+
187
+ ### `compareFiles(filePaths, options)`
188
+
189
+ Compares properties/keys across multiple files and generates a report based on options.
190
+
191
+ #### Parameters:
192
+ - `filePaths` (string[]): Array of file paths.
193
+ - `options` (Object): Options for comparison output.
194
+ - `format` (string): Output format ('console', 'html', or 'markdown').
195
+ - `outputFile` (string): Path to save the report (for html and markdown).
196
+
197
+ #### Example:
198
+ ```javascript
199
+ // Compare with console output
200
+ compareFiles(['file1.properties', 'file2.yaml']);
201
+
202
+ // Generate HTML report
203
+ compareFiles(['file1.properties', 'file2.yaml'], {
204
+ format: 'html',
205
+ outputFile: 'report.html'
206
+ });
207
+ ```
208
+
209
+ ---
210
+
211
+ ### `run()`
212
+
213
+ CLI entry point. Parses command-line arguments and runs the comparison.
214
+
215
+ ---
216
+
217
+ ## Output Formats
218
+
219
+ ### Console Output
220
+ The default output format provides:
221
+ - A table showing all keys and their values across files
222
+ - Highlighted mismatched rows for easy identification
223
+ - A summary of mismatched keys
224
+
225
+ ### HTML Report
226
+ Generates a visually appealing HTML report with:
227
+ - CSS styling
228
+ - Color-coded cells for matches and mismatches
229
+ - Summary section with quick statistics
230
+ - Responsive design
231
+
232
+ ### Markdown Report
233
+ Creates a Markdown document with:
234
+ - File list with paths
235
+ - Comparison table
236
+ - Summary section with mismatched keys highlighted
128
237
 
129
238
  ---
130
239
 
131
240
  ## Error Handling
132
241
 
133
242
  - **No File Paths Provided**: Logs an error and exits.
243
+ - **Only One File Provided**: Logs an error about needing at least two files and exits.
134
244
  - **Missing Files**: Logs missing files and exits.
135
- - **Empty or Malformed Properties Files**: Skips invalid lines.
245
+ - **Unsupported File Extensions**: Logs a warning and treats as empty file.
246
+ - **Invalid YAML**: Logs error details and treats as empty file.
247
+ - **Invalid Format Option**: Falls back to console output with warning.
136
248
 
137
249
  ---
138
250
 
139
- ## Example Properties Files
251
+ ## Example Scenarios
252
+
253
+ ### Basic Comparison
140
254
 
141
- ### File 1 (`file1.properties`):
255
+ #### Command:
256
+ ```bash
257
+ node compareUtility.js file1.properties file2.properties
142
258
  ```
143
- key1=value1
144
- key2=value2
259
+
260
+ #### Output:
145
261
  ```
262
+ Comparing properties/keys across files:
263
+
264
+ ┌─────────┬─────┬────────────┬────────────┐
265
+ │ (index) │ Key │ Matched │ ... │
266
+ ├─────────┼─────┼────────────┼────────────┤
267
+ │ 0 │ ... │ 'Yes' │ ... │
268
+ │ 1 │ ... │ 'No' │ ... │
269
+ └─────────┴─────┴────────────┴────────────┘
146
270
 
147
- ### File 2 (`file2.properties`):
271
+ === Highlighted Mismatched Rows ===
272
+ Key: key2 | File 1: value2 | File 2: value3
273
+
274
+ === Summary ===
275
+ 1 key(s) have mismatched values.
276
+ Mismatched keys: key2
148
277
  ```
149
- key1=value1
150
- key2=value3
278
+
279
+ ### HTML Report Generation
280
+
281
+ #### Command:
282
+ ```bash
283
+ node compareUtility.js -f html -o report.html file1.properties file2.yaml
151
284
  ```
152
285
 
153
- ---
286
+ #### Output:
287
+ ```
288
+ HTML report saved to: report.html
289
+ ```
154
290
 
155
- ## Sample Execution
291
+ ### Markdown Report Generation
156
292
 
157
- ### Command:
293
+ #### Command:
158
294
  ```bash
159
- node script.js file1.properties file2.properties
295
+ node compareUtility.js -f markdown -o report.md file1.properties file2.properties
160
296
  ```
161
297
 
162
- ### Output:
163
- ```text
164
- Comparing properties across files:
165
-
166
- Key: key1 - Values match across all files.
167
- Key: key2 - Mismatched values:
168
- File 1: value2
169
- File 2: value3
298
+ #### Output:
299
+ ```
300
+ Markdown report saved to: report.md
170
301
  ```
171
302
 
172
303
  ---
@@ -174,21 +305,23 @@ Key: key2 - Mismatched values:
174
305
  ## Dependencies
175
306
 
176
307
  - `fs` module (Node.js File System)
177
- - `js-yaml` module (Node.js YAML library)
308
+ - `path` module (Node.js Path)
309
+ - `js-yaml` module (YAML parsing)
310
+ - `chalk` module (Terminal styling)
178
311
 
179
312
  ---
180
313
 
181
314
  ## Limitations
182
315
 
183
- - Assumes properties are simple key-value pairs separated by `=`.
184
- - Ignores keys without a corresponding value.
185
- - Does not support multi-line properties.
316
+ - Assumes properties are simple key-value pairs separated by `=`
317
+ - Does not support multi-line properties in .properties files
318
+ - Flattens all nested YAML structures to dot notation
186
319
 
187
320
  ---
188
321
 
189
322
  ## License
190
323
 
191
- This script is licensed under the MIT License.
324
+ This utility is licensed under the MIT License.
192
325
 
193
326
  ---
194
327
 
package/PUBLISH.MD CHANGED
@@ -4,13 +4,15 @@
4
4
  ### Test Locally
5
5
  `npm link`
6
6
 
7
+ `npm unlink -g`
8
+
9
+ `npm link properties-comparator`
7
10
 
8
11
  ## Now you can run the script globally using:
9
12
 
10
13
  ```properties-comparator <filePath1> <filePath2>```
11
14
 
12
15
 
13
-
14
16
  ## Publish the Package
15
17
  ### Login to npm (if you haven't already):
16
18
  `npm login`
package/README.md CHANGED
@@ -1,20 +1,91 @@
1
1
  # properties-comparator
2
- This utility provides functionality to parse and compare **.properties** and **.yml or .yaml(YAML)** files in the format of key-value pairs. It reads these files, compares the values for each key across multiple files, and logs the results.
3
2
 
3
+ A powerful utility for parsing and comparing **.properties** and **.yml/.yaml** files. This tool reads files as key-value pairs, compares values across multiple files, and generates detailed comparison reports in various formats.
4
4
 
5
- Utility is available as NPM Package [https://www.npmjs.com/package/properties-comparator](https://www.npmjs.com/package/properties-comparator)
5
+ [![NPM Package](https://img.shields.io/npm/v/properties-comparator.svg)](https://www.npmjs.com/package/properties-comparator)
6
6
 
7
+ ## Features
7
8
 
8
- ### Install the Package
9
- `npm install -g properties-comparator`
9
+ - **Multi-format Support**: Parse both **.properties** files and **.yml/.yaml** (YAML) files
10
+ - **Nested Structure Handling**: Flatten nested YAML structures into key-value pairs
11
+ - **Comprehensive Comparison**: Compare values across multiple files simultaneously
12
+ - **Multiple Report Formats**:
13
+ - Console output with color-coded highlighting
14
+ - HTML reports with CSS styling
15
+ - Markdown reports
16
+ - **Flexible Output Options**: Save reports to files or display in console
17
+ - **User-friendly CLI**: Simple command-line interface with intuitive options
10
18
 
19
+ ## Installation
11
20
 
12
- ## Now you can run the script globally using:
21
+ ```bash
22
+ # Install globally
23
+ npm install -g properties-comparator
13
24
 
14
- ```properties-comparator <filePath1> <filePath2>```
25
+ # To uninstall
26
+ npm uninstall -g properties-comparator
27
+ ```
15
28
 
16
- ## Compiled on npm@11.1.0 & node v22.13.0
17
- `npm install -g npm@11.1.0`
29
+ ## Usage
18
30
 
31
+ ### Basic Usage
19
32
 
20
- ### Check [Documentation](DOCUMENTATION.md) for more details
33
+ Compare two or more files:
34
+
35
+ ```bash
36
+ properties-comparator <filePath1> <filePath2> [<filePath3> ...]
37
+ ```
38
+
39
+ ### Examples
40
+
41
+ Compare multiple files:
42
+ ```bash
43
+ properties-comparator ./config1.properties ./config2.yml ./config3.properties
44
+ ```
45
+
46
+ Generate HTML report:
47
+ ```bash
48
+ properties-comparator -f html -o report.html ./config1.properties ./config2.yml
49
+ ```
50
+
51
+ Generate Markdown report:
52
+ ```bash
53
+ properties-comparator -f markdown -o report.md ./config1.properties ./config2.yml
54
+ ```
55
+
56
+ ### Command Options
57
+
58
+ - `-f, --format <type>` - Report format (console, html, markdown)
59
+ - `-o, --output <file>` - Output file for the report
60
+ - `-h, --help` - Display help information
61
+
62
+ ## Report Examples
63
+
64
+ ### Terminal View
65
+ ![Terminal Report](./screenshots/TerminalTable.png)
66
+
67
+ ### HTML View
68
+ ![HTML Report](./screenshots/HtmlReport.png)
69
+
70
+ ### Markdown View
71
+ ![Markdown Report](./screenshots/MarkDownReport.png)
72
+
73
+ ## Quality Assurance
74
+
75
+ This package is thoroughly tested with over 90% code coverage to ensure reliability.
76
+
77
+ ![Test Coverage](./screenshots/TestCoverage.png)
78
+
79
+ ## Compatibility
80
+
81
+ Developed and tested with:
82
+ - npm v11.1.0
83
+ - Node.js v22.13.0
84
+
85
+ ## Documentation
86
+
87
+ For more detailed information, please check the [Documentation](DOCUMENTATION.md).
88
+
89
+ ## License
90
+
91
+ [MIT](LICENSE)
package/TEST.md CHANGED
@@ -12,4 +12,51 @@ or
12
12
 
13
13
  ### Check jest.config.js for testing configuration
14
14
 
15
- `npm test -- --coverage`
15
+ `npm test -- --coverage`
16
+
17
+
18
+ ### Test Comparisons
19
+
20
+ `node index.js ./test/config1.properties ./test/config1.yaml`
21
+
22
+ `node index.js ./test/config1.properties ./test/config2.yml`
23
+
24
+ `node index.js ./test/config1.properties ./test/config2.properties`
25
+
26
+ `node index.js ./test/config2.properties ./test/config2.yml`
27
+
28
+ `node index.js ./test/config3.txt ./test/config3.yml2`
29
+
30
+ `node index.js --format html --output report.html ./test/config1.properties ./test/config2.yml`
31
+
32
+ `node index.js -f markdown -o report.md ./test/config1.properties ./test/config2.yml`
33
+
34
+ ### NPM LINK Test
35
+
36
+ `properties-comparator ./test/config1.properties ./test/config1.yaml`
37
+
38
+ `properties-comparator ./test/config1.properties ./test/config2.yml`
39
+
40
+ `properties-comparator ./test/config1.properties ./test/config2.properties`
41
+
42
+ `properties-comparator ./test/config2.properties ./test/config2.yml`
43
+
44
+ `properties-comparator ./test/config3.txt ./test/config3.yml2`
45
+
46
+ `properties-comparator --format html --output report.html ./test/config1.properties ./test/config2.yml`
47
+
48
+ `properties-comparator -f markdown -o report.md ./test/config1.properties ./test/config2.yml`
49
+
50
+
51
+ `properties-comparator ./test/config1.properties ./test/config2.yml ./test/config3.properties`
52
+
53
+ `properties-comparator -v ./test/config1.properties ./test/config2.yml ./test/config3.properties`
54
+
55
+
56
+ `properties-comparator -f html -o report.html ./test/config1.properties ./test/config1.yaml`
57
+
58
+ `properties-comparator -f html -o report.html ./test/config1.properties ./test/config2.yml`
59
+
60
+ `properties-comparator -f html -o report.html ./test/config1.properties ./test/config2.yml ./test/config3.properties`
61
+
62
+ `properties-comparator -f markdown -o report.md ./test/config1.properties ./test/config2.yml ./test/config3.properties`
@@ -0,0 +1,3 @@
1
+ export default {
2
+ presets: ['@babel/preset-env'],
3
+ };
package/cli.js ADDED
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+
3
+ import { program } from 'commander';
4
+ import { compareFiles } from './index.js';
5
+ import { readFileSync } from 'fs';
6
+ import path from 'path';
7
+
8
+ // Get version from package.json
9
+ let version = '1.0.0';
10
+
11
+ try {
12
+ const packageJson = JSON.parse(readFileSync('./package.json', 'utf8'));
13
+ version = packageJson.version;
14
+ } catch (err) {
15
+ // Use default version if package.json can't be read
16
+ }
17
+
18
+ // Check if no arguments were provided
19
+ if (process.argv.length <= 2) {
20
+ console.log(`properties-comparator v${version}`);
21
+ console.log('Usage: properties-comparator [options] <file1> <file2> [file3...]');
22
+ process.exit(0);
23
+ }
24
+
25
+ program
26
+ .version(version)
27
+ .description('Compare properties between multiple files')
28
+ .option('-f, --format <format>', 'Output format: console, html, or markdown (default: console)')
29
+ .option('-o, --output <path>', 'Output file path for results')
30
+ .option('-v, --verbose', 'Show verbose output')
31
+ .arguments('<files...>')
32
+ .usage('[options] <file1> <file2> [file3...]')
33
+ .action((files, options) => {
34
+ if (files.length < 2) {
35
+ console.error('Error: At least two files are required for comparison');
36
+ program.help();
37
+ process.exit(1);
38
+ }
39
+
40
+ try {
41
+ // Resolve all file paths
42
+ const resolvedPaths = files.map(file => path.resolve(file));
43
+
44
+ // Prepare options for compareFiles
45
+ const comparisonOptions = {
46
+ format: options.format || 'console',
47
+ outputFile: options.output,
48
+ verbose: options.verbose // Pass verbose option to compareFiles
49
+ };
50
+
51
+ // Run the comparison
52
+ compareFiles(resolvedPaths, comparisonOptions);
53
+
54
+ } catch (error) {
55
+ console.error('Error:', error.message);
56
+ process.exit(1);
57
+ }
58
+ });
59
+
60
+ program.parse(process.argv);