properties-comparator 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Zack Dawood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # properties-comparator
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.
package/index.js ADDED
@@ -0,0 +1,75 @@
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+
5
+ /**
6
+ * Parses a properties file into an object.
7
+ * @param {string} filePath - The path to the properties file.
8
+ * @returns {Object} - An object containing key-value pairs.
9
+ */
10
+ function parsePropertiesFile(filePath) {
11
+ return fs.readFileSync(filePath, 'utf-8')
12
+ .split(/\r?\n/)
13
+ .filter(line => line.trim() && !line.startsWith('#'))
14
+ .reduce((acc, line) => {
15
+ const [key, value] = line.split('=');
16
+ if (key && value !== undefined) {
17
+ acc[key.trim()] = value.trim();
18
+ }
19
+ return acc;
20
+ }, {});
21
+ }
22
+
23
+ /**
24
+ * Compares properties across multiple files.
25
+ * @param {string[]} filePaths - Array of file paths.
26
+ */
27
+ function compareProperties(filePaths) {
28
+ const propertiesList = filePaths.map(parsePropertiesFile);
29
+ const allKeys = new Set(propertiesList.flatMap(Object.keys));
30
+
31
+ console.log('Comparing properties across files:\n');
32
+
33
+ allKeys.forEach(key => {
34
+ const values = propertiesList.map(props => props[key]?.replace(/\s+/g, '') || 'N/A');
35
+ const allMatch = values.every(value => value === values[0]);
36
+
37
+ if (allMatch) {
38
+ console.log(`Key: ${key} - Values match across all files.`);
39
+ } else {
40
+ console.log(`Key: ${key} - Mismatched values:`);
41
+ values.forEach((value, index) => {
42
+ console.log(` File ${index + 1}: ${value}`);
43
+ });
44
+ }
45
+ });
46
+ }
47
+
48
+ /**
49
+ * CLI entry point for comparing properties files.
50
+ */
51
+ function run() {
52
+ const filePaths = process.argv.slice(2);
53
+
54
+ if (filePaths.length === 0) {
55
+ console.error('Please provide the paths to the properties files as command-line arguments.');
56
+ process.exit(1);
57
+ }
58
+
59
+ if (filePaths.every(fs.existsSync)) {
60
+ compareProperties(filePaths);
61
+ } else {
62
+ console.error('One or more properties files are missing. Ensure all specified properties files exist.');
63
+ }
64
+ }
65
+
66
+ module.exports = {
67
+ parsePropertiesFile,
68
+ compareProperties,
69
+ run,
70
+ };
71
+
72
+ // If the script is executed directly, run the CLI
73
+ if (require.main === module) {
74
+ run();
75
+ }
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "properties-comparator",
3
+ "version": "1.0.0",
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
+ "main": "index.js",
6
+ "bin": {
7
+ "properties-comparator": "./index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "node index.js"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/zackria/properties-comparator.git"
15
+ },
16
+ "keywords": [
17
+ "properties",
18
+ "comparator"
19
+ ],
20
+ "author": "Zack Dawood",
21
+ "license": "MIT",
22
+ "bugs": {
23
+ "url": "https://github.com/zackria/properties-comparator/issues"
24
+ },
25
+ "homepage": "https://github.com/zackria/properties-comparator#readme"
26
+ }
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,35 @@
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