properties-comparator 1.0.1 → 1.0.3
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 +189 -0
- package/PUBLISH.MD +26 -0
- package/README.md +4 -14
- package/package.json +1 -1
package/DOCUMENTATION.md
ADDED
|
@@ -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,26 @@
|
|
|
1
|
+
|
|
2
|
+
## Link your package locally for testing:
|
|
3
|
+
|
|
4
|
+
### Test Locally
|
|
5
|
+
`npm link`
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
## Now you can run the script globally using:
|
|
9
|
+
|
|
10
|
+
```properties-comparator <filePath1> <filePath2>```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## Publish the Package
|
|
15
|
+
### Login to npm (if you haven't already):
|
|
16
|
+
`npm login`
|
|
17
|
+
|
|
18
|
+
### Publish the package:
|
|
19
|
+
`npm publish`
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Install the Package Globally
|
|
23
|
+
Once published, you (or anyone) can install the package globally using:
|
|
24
|
+
`npm install -g properties-comparator`
|
|
25
|
+
|
|
26
|
+
### Check [Documentation](DOCUMENTATION.md) for more details
|
package/README.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
3
|
|
|
4
|
+
Utility is available as NPM Package [https://www.npmjs.com/package/properties-comparator](https://www.npmjs.com/package/properties-comparator)
|
|
4
5
|
|
|
5
|
-
## Link your package locally for testing:
|
|
6
6
|
|
|
7
|
-
###
|
|
8
|
-
`npm
|
|
7
|
+
### Install the Package
|
|
8
|
+
`npm install -g properties-comparator`
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
## Now you can run the script globally using:
|
|
@@ -13,14 +13,4 @@ This utility provides functionality to parse and compare properties files in the
|
|
|
13
13
|
```properties-comparator <filePath1> <filePath2>```
|
|
14
14
|
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
### Login to npm (if you haven't already):
|
|
18
|
-
`npm login`
|
|
19
|
-
|
|
20
|
-
### Publish the package:
|
|
21
|
-
`npm publish`
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
### Install the Package Globally
|
|
25
|
-
Once published, you (or anyone) can install the package globally using:
|
|
26
|
-
`npm install -g properties-comparator`
|
|
16
|
+
### 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.
|
|
3
|
+
"version": "1.0.3",
|
|
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": {
|