properties-comparator 1.0.0 → 1.0.2

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.
@@ -0,0 +1,189 @@
1
+
2
+ # Node.js Properties File Comparison Utility
3
+
4
+ ## Overview
5
+
6
+ This utility provides functionality to parse and compare properties files in the format of key-value pairs. It reads properties files, compares the values for each key across multiple files, and logs the results.
7
+
8
+ ### Features:
9
+ - Parse properties files into key-value objects.
10
+ - Compare key values across multiple properties files.
11
+ - Log detailed comparison results, including mismatches.
12
+
13
+ ---
14
+
15
+ ## Installation
16
+
17
+ ### Prerequisites
18
+ - Node.js installed on your system.
19
+ - Properties files in a valid key-value format.
20
+
21
+ ---
22
+
23
+ ## Usage
24
+
25
+ ### Running the Script
26
+ Run the script using Node.js with file paths provided as command-line arguments:
27
+
28
+ ```bash
29
+ node script.js <filePath1> <filePath2> [<filePath3> ...]
30
+ ```
31
+
32
+ ### Input Format
33
+ The properties files should follow the format:
34
+ ```
35
+ key1=value1
36
+ key2=value2
37
+ # Comments are ignored
38
+ ```
39
+
40
+ ---
41
+
42
+ ## Functions
43
+
44
+ ### `parsePropertiesFile(filePath)`
45
+
46
+ Parses a properties file and returns an object representation of the key-value pairs.
47
+
48
+ #### Parameters:
49
+ - `filePath` (string): Path to the properties file.
50
+
51
+ #### Returns:
52
+ - (Object): An object containing key-value pairs from the properties file.
53
+
54
+ #### Example:
55
+ ```javascript
56
+ // Assuming properties file contains:
57
+ // key1=value1
58
+ // key2=value2
59
+
60
+ const properties = parsePropertiesFile('/path/to/properties/file');
61
+ console.log(properties);
62
+ // Output: { key1: 'value1', key2: 'value2' }
63
+ ```
64
+
65
+ #### Implementation:
66
+ - Reads the file content using `fs.readFileSync`.
67
+ - Splits lines by `
68
+ ` or `
69
+ `.
70
+ - Filters out empty lines and lines starting with `#`.
71
+ - Processes valid lines into key-value pairs.
72
+
73
+ ---
74
+
75
+ ### `compareProperties(filePaths)`
76
+
77
+ Compares properties across multiple properties files and logs the results.
78
+
79
+ #### Parameters:
80
+ - `filePaths` (string[]): Array of file paths to be compared.
81
+
82
+ #### Returns:
83
+ - None. Outputs comparison results to the console.
84
+
85
+ #### Behavior:
86
+ - Parses each properties file into an object.
87
+ - Collects all unique keys across files.
88
+ - Compares values for each key across all files.
89
+ - Logs whether values match or are mismatched. For mismatches, displays values for each file.
90
+
91
+ #### Example:
92
+ ```bash
93
+ node script.js file1.properties file2.properties file3.properties
94
+ ```
95
+
96
+ #### Output Example:
97
+ ```text
98
+ Comparing properties across files:
99
+
100
+ Key: key1 - Values match across all files.
101
+ Key: key2 - Mismatched values:
102
+ File 1: value1
103
+ File 2: value2
104
+ File 3: value3
105
+ ```
106
+
107
+ ---
108
+
109
+ ### Runtime Input Handling
110
+
111
+ The script expects file paths as command-line arguments:
112
+ - Extracted from `process.argv`.
113
+ - If no file paths are provided, it displays an error and exits:
114
+ ```
115
+ Please provide the paths to the properties files as command-line arguments.
116
+ ```
117
+ - Verifies the existence of all specified files. If any file is missing:
118
+ ```
119
+ One or more properties files are missing. Ensure all specified properties files exist.
120
+ ```
121
+
122
+ ---
123
+
124
+ ## Error Handling
125
+
126
+ - **No File Paths Provided**: Logs an error and exits.
127
+ - **Missing Files**: Logs missing files and exits.
128
+ - **Empty or Malformed Properties Files**: Skips invalid lines.
129
+
130
+ ---
131
+
132
+ ## Example Properties Files
133
+
134
+ ### File 1 (`file1.properties`):
135
+ ```
136
+ key1=value1
137
+ key2=value2
138
+ ```
139
+
140
+ ### File 2 (`file2.properties`):
141
+ ```
142
+ key1=value1
143
+ key2=value3
144
+ ```
145
+
146
+ ---
147
+
148
+ ## Sample Execution
149
+
150
+ ### Command:
151
+ ```bash
152
+ node script.js file1.properties file2.properties
153
+ ```
154
+
155
+ ### Output:
156
+ ```text
157
+ Comparing properties across files:
158
+
159
+ Key: key1 - Values match across all files.
160
+ Key: key2 - Mismatched values:
161
+ File 1: value2
162
+ File 2: value3
163
+ ```
164
+
165
+ ---
166
+
167
+ ## Dependencies
168
+
169
+ - `fs` module (Node.js File System)
170
+
171
+ ---
172
+
173
+ ## Limitations
174
+
175
+ - Assumes properties are simple key-value pairs separated by `=`.
176
+ - Ignores keys without a corresponding value.
177
+ - Does not support multi-line properties.
178
+
179
+ ---
180
+
181
+ ## License
182
+
183
+ This script is licensed under the MIT License.
184
+
185
+ ---
186
+
187
+ ## Author
188
+
189
+ [Zack Dawood](http://www.zackdawood.com)
package/PUBLISH.MD ADDED
@@ -0,0 +1,13 @@
1
+ ## Publish the Package
2
+ ### Login to npm (if you haven't already):
3
+ `npm login`
4
+
5
+ ### Publish the package:
6
+ `npm publish`
7
+
8
+
9
+ ### Install the Package Globally
10
+ Once published, you (or anyone) can install the package globally using:
11
+ `npm install -g properties-comparator`
12
+
13
+ ### Check [Documentation](DOCUMENTATION.md) for more details
package/README.md CHANGED
@@ -1,2 +1,18 @@
1
1
  # properties-comparator
2
2
  This utility provides functionality to parse and compare properties files in the format of key-value pairs. It reads properties files, compares the values for each key across multiple files, and logs the results.
3
+
4
+ Utility is available as NPM Package [https://www.npmjs.com/package/properties-comparator](https://www.npmjs.com/package/properties-comparator)
5
+
6
+
7
+ ## Link your package locally for testing:
8
+
9
+ ### Test Locally
10
+ `npm link`
11
+
12
+
13
+ ## Now you can run the script globally using:
14
+
15
+ ```properties-comparator <filePath1> <filePath2>```
16
+
17
+
18
+ ### Check [Documentation](DOCUMENTATION.md) for more details
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "properties-comparator",
3
- "version": "1.0.0",
3
+ "version": "1.0.2",
4
4
  "description": "This utility provides functionality to parse and compare properties files in the format of key-value pairs. It reads properties files, compares the values for each key across multiple files, and logs the results.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1,32 +0,0 @@
1
- # General Application Settings
2
- app.name=MyApplication
3
- app.version=1.0.0
4
- app.environment=development
5
-
6
- # Database Configuration
7
- db.host=localhost
8
- db.port=3306
9
- db.username=root
10
- db.password=password123
11
- db.name=my_database
12
-
13
- # Logging Settings
14
- log.level=INFO
15
- log.filepath=/var/log/myapplication.log
16
-
17
- # API Settings
18
- api.url=https://api.example.com
19
- api.timeout=5000
20
- api.key=abcd1234efgh5678ijkl
21
-
22
- # Feature Flags
23
- feature.newUI.enabled=true
24
- feature.betaFeature.enabled=false
25
- feature.advancedSearch.enabled=true
26
-
27
- # Email Configuration
28
- email.host=smtp.example.com
29
- email.port=587
30
- email.username=noreply@example.com
31
- email.password=securepassword
32
- email.from=noreply@example.com
@@ -1,35 +0,0 @@
1
- # General Application Settings
2
- app.name=MyApplication
3
- app.version=1.0.0
4
- app.environment=development
5
-
6
-
7
-
8
- # Logging Settings
9
- log.level=INFO
10
- log.filepath=/var/log/myapplication.log
11
-
12
- # API Settings
13
- api.url=https://api.example.com
14
- api.timeout=5000
15
- api.key=abcd1234efgh5678ijkl
16
-
17
- # Feature Flags
18
- feature.newUI.enabled=true
19
- feature.betaFeature.enabled=false
20
- feature.advancedSearch.enabled=true
21
-
22
- # Email Configuration
23
- email.host=smtp.example.com
24
- email.port=587
25
- email.username=noreply@example.com
26
- email.password=securepassword
27
- email.from=noreply@example.com
28
-
29
-
30
- # Database Configuration
31
- db.host=localhost
32
- db.port=3306
33
- db.username=root
34
- db.password=password321
35
- db.name=my_database