vcf-to-json-converter 1.0.0 → 1.0.1
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/README.md +267 -51
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,36 +1,91 @@
|
|
|
1
|
-
#
|
|
1
|
+
# vcf-to-json-converter
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://badge.fury.io/js/vcf-to-json-converter)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](https://npmjs.org/package/vcf-to-json-converter)
|
|
7
|
+
|
|
8
|
+
A lightweight, fast, and reliable Node.js library to convert VCF (vCard) files to structured JSON format with full CLI support.
|
|
9
|
+
|
|
10
|
+
```javascript
|
|
11
|
+
const { vcfToJsonFromFile } = require("vcf-to-json-converter");
|
|
12
|
+
|
|
13
|
+
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
14
|
+
console.log(contacts);
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Table of Contents
|
|
18
|
+
|
|
19
|
+
- [Features](#features)
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Quick Start](#quick-start)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [Command Line Interface](#command-line-interface)
|
|
24
|
+
- [Programmatic Usage](#programmatic-usage)
|
|
25
|
+
- [TypeScript](#typescript)
|
|
26
|
+
- [API Reference](#api-reference)
|
|
27
|
+
- [Output Format](#output-format)
|
|
28
|
+
- [Supported vCard Fields](#supported-vcard-fields)
|
|
29
|
+
- [Examples](#examples)
|
|
30
|
+
- [Troubleshooting](#troubleshooting)
|
|
31
|
+
- [Contributing](#contributing)
|
|
32
|
+
- [License](#license)
|
|
4
33
|
|
|
5
34
|
## Features
|
|
6
35
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
36
|
+
- **Complete VCF Support** - Convert VCF/vCard files (v2.1, v3.0, v4.0) to structured JSON
|
|
37
|
+
- **Programmatic API** - Easy integration into Node.js applications
|
|
38
|
+
- **CLI Tool** - Command-line interface for quick conversions
|
|
39
|
+
- **Robust Error Handling** - Comprehensive error handling and validation
|
|
40
|
+
- **Rich Data Extraction** - Extracts all contact information including photos, organizations, and notes
|
|
41
|
+
- **TypeScript Ready** - Full TypeScript definitions included
|
|
42
|
+
- **High Performance** - Efficiently processes large VCF files with multiple contacts
|
|
43
|
+
- **Cross Platform** - Works on Windows, macOS, and Linux
|
|
44
|
+
- **Zero Dependencies** - No external dependencies for maximum compatibility
|
|
45
|
+
- **UTF-8 Support** - Handles international characters and emojis correctly
|
|
13
46
|
|
|
14
47
|
## Installation
|
|
15
48
|
|
|
16
|
-
|
|
49
|
+
Using npm:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install vcf-to-json-converter
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For global CLI usage:
|
|
17
56
|
|
|
18
57
|
```bash
|
|
19
58
|
npm install -g vcf-to-json-converter
|
|
20
59
|
```
|
|
21
60
|
|
|
22
|
-
|
|
61
|
+
Using yarn:
|
|
23
62
|
|
|
24
63
|
```bash
|
|
25
|
-
|
|
64
|
+
yarn add vcf-to-json-converter
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
# Install globally for CLI
|
|
71
|
+
npm install -g vcf-to-json-converter
|
|
72
|
+
|
|
73
|
+
# Convert a VCF file
|
|
74
|
+
vcf-to-json contacts.vcf output.json
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
// Use in your Node.js project
|
|
79
|
+
const { vcfToJsonFromFile } = require("vcf-to-json-converter");
|
|
80
|
+
|
|
81
|
+
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
82
|
+
console.log(`Converted ${contacts.length} contacts`);
|
|
26
83
|
```
|
|
27
84
|
|
|
28
85
|
## Usage
|
|
29
86
|
|
|
30
87
|
### Command Line Interface
|
|
31
88
|
|
|
32
|
-
Convert a VCF file to JSON:
|
|
33
|
-
|
|
34
89
|
```bash
|
|
35
90
|
# Convert and display JSON in terminal
|
|
36
91
|
vcf-to-json contacts.vcf
|
|
@@ -38,8 +93,12 @@ vcf-to-json contacts.vcf
|
|
|
38
93
|
# Convert and save to file
|
|
39
94
|
vcf-to-json contacts.vcf output.json
|
|
40
95
|
|
|
41
|
-
# Convert with compact formatting
|
|
96
|
+
# Convert with compact formatting (minified JSON)
|
|
42
97
|
vcf-to-json contacts.vcf output.json --compact
|
|
98
|
+
|
|
99
|
+
# Show help and version
|
|
100
|
+
vcf-to-json --help
|
|
101
|
+
vcf-to-json --version
|
|
43
102
|
```
|
|
44
103
|
|
|
45
104
|
### Programmatic Usage
|
|
@@ -51,57 +110,102 @@ const {
|
|
|
51
110
|
saveJsonToFile,
|
|
52
111
|
} = require("vcf-to-json-converter");
|
|
53
112
|
|
|
54
|
-
// Convert VCF text content
|
|
113
|
+
// Method 1: Convert VCF text content
|
|
55
114
|
const vcfContent = `BEGIN:VCARD
|
|
56
|
-
VERSION:
|
|
115
|
+
VERSION:3.0
|
|
57
116
|
FN:John Doe
|
|
58
|
-
|
|
59
|
-
|
|
117
|
+
N:Doe;John;;;
|
|
118
|
+
TEL;TYPE=CELL:+1234567890
|
|
119
|
+
EMAIL;TYPE=HOME:john@example.com
|
|
120
|
+
ORG:ACME Corp
|
|
121
|
+
TITLE:Software Engineer
|
|
60
122
|
END:VCARD`;
|
|
61
123
|
|
|
62
124
|
const contacts = vcfToJson(vcfContent);
|
|
63
|
-
console.log(contacts);
|
|
125
|
+
console.log("Parsed contacts:", contacts.length);
|
|
64
126
|
|
|
65
|
-
// Convert VCF file
|
|
127
|
+
// Method 2: Convert VCF file directly
|
|
66
128
|
try {
|
|
67
129
|
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
68
130
|
console.log(`Converted ${contacts.length} contacts`);
|
|
69
131
|
|
|
70
|
-
// Save to JSON file
|
|
71
|
-
saveJsonToFile(contacts, "./output.json");
|
|
132
|
+
// Save to JSON file with pretty formatting
|
|
133
|
+
saveJsonToFile(contacts, "./output.json", true);
|
|
134
|
+
|
|
135
|
+
// Access contact data
|
|
136
|
+
contacts.forEach((contact) => {
|
|
137
|
+
console.log(
|
|
138
|
+
`${contact.fullName}: ${contact.phones.length} phones, ${contact.emails.length} emails`
|
|
139
|
+
);
|
|
140
|
+
});
|
|
72
141
|
} catch (error) {
|
|
73
142
|
console.error("Conversion failed:", error.message);
|
|
74
143
|
}
|
|
75
144
|
```
|
|
76
145
|
|
|
146
|
+
### TypeScript
|
|
147
|
+
|
|
148
|
+
```typescript
|
|
149
|
+
import { vcfToJsonFromFile, Contact } from "vcf-to-json-converter";
|
|
150
|
+
|
|
151
|
+
const contacts: Contact[] = vcfToJsonFromFile("./contacts.vcf");
|
|
152
|
+
console.log(contacts);
|
|
153
|
+
```
|
|
154
|
+
|
|
77
155
|
## API Reference
|
|
78
156
|
|
|
79
|
-
### `vcfToJson(vcfText)`
|
|
157
|
+
### `vcfToJson(vcfText: string): Contact[]`
|
|
80
158
|
|
|
81
159
|
Converts VCF text content to JSON.
|
|
82
160
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
-
|
|
86
|
-
|
|
161
|
+
**Parameters:**
|
|
162
|
+
|
|
163
|
+
- `vcfText` _(string)_: The VCF content as a string
|
|
164
|
+
|
|
165
|
+
**Returns:** Array of contact objects
|
|
87
166
|
|
|
88
|
-
|
|
167
|
+
**Throws:** Error if VCF content is invalid
|
|
168
|
+
|
|
169
|
+
**Example:**
|
|
170
|
+
|
|
171
|
+
```javascript
|
|
172
|
+
const contacts = vcfToJson("BEGIN:VCARD\nVERSION:3.0\nFN:John Doe\nEND:VCARD");
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### `vcfToJsonFromFile(filePath: string): Contact[]`
|
|
89
176
|
|
|
90
177
|
Converts a VCF file to JSON.
|
|
91
178
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
-
|
|
95
|
-
|
|
179
|
+
**Parameters:**
|
|
180
|
+
|
|
181
|
+
- `filePath` _(string)_: Path to the VCF file
|
|
182
|
+
|
|
183
|
+
**Returns:** Array of contact objects
|
|
96
184
|
|
|
97
|
-
|
|
185
|
+
**Throws:** Error if file doesn't exist or is invalid
|
|
186
|
+
|
|
187
|
+
**Example:**
|
|
188
|
+
|
|
189
|
+
```javascript
|
|
190
|
+
const contacts = vcfToJsonFromFile("./my-contacts.vcf");
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### `saveJsonToFile(jsonData: Contact[], outputPath: string, prettyPrint?: boolean): void`
|
|
98
194
|
|
|
99
195
|
Saves JSON data to a file.
|
|
100
196
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
197
|
+
**Parameters:**
|
|
198
|
+
|
|
199
|
+
- `jsonData` _(Contact[])_: The JSON data to save
|
|
200
|
+
- `outputPath` _(string)_: Path where to save the JSON file
|
|
201
|
+
- `prettyPrint` _(boolean, optional)_: Whether to format JSON with indentation (default: true)
|
|
202
|
+
|
|
203
|
+
**Example:**
|
|
204
|
+
|
|
205
|
+
```javascript
|
|
206
|
+
saveJsonToFile(contacts, "./output.json", true); // Pretty formatted
|
|
207
|
+
saveJsonToFile(contacts, "./compact.json", false); // Minified
|
|
208
|
+
```
|
|
105
209
|
|
|
106
210
|
## Output Format
|
|
107
211
|
|
|
@@ -174,6 +278,39 @@ contacts.forEach((contact) => {
|
|
|
174
278
|
});
|
|
175
279
|
```
|
|
176
280
|
|
|
281
|
+
### Advanced Usage with Error Handling
|
|
282
|
+
|
|
283
|
+
```javascript
|
|
284
|
+
const { vcfToJsonFromFile, saveJsonToFile } = require("vcf-to-json-converter");
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
// Convert VCF file
|
|
288
|
+
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
289
|
+
|
|
290
|
+
// Filter contacts with email addresses
|
|
291
|
+
const contactsWithEmail = contacts.filter(
|
|
292
|
+
(contact) => contact.emails.length > 0
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
// Extract business contacts
|
|
296
|
+
const businessContacts = contacts.filter((contact) => contact.organization);
|
|
297
|
+
|
|
298
|
+
console.log(
|
|
299
|
+
`Total: ${contacts.length}, With Email: ${contactsWithEmail.length}, Business: ${businessContacts.length}`
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
// Save different formats
|
|
303
|
+
saveJsonToFile(contacts, "./all-contacts.json", true); // Pretty
|
|
304
|
+
saveJsonToFile(businessContacts, "./business-contacts.json", false); // Compact
|
|
305
|
+
} catch (error) {
|
|
306
|
+
if (error.code === "ENOENT") {
|
|
307
|
+
console.error("File not found. Please check the file path.");
|
|
308
|
+
} else {
|
|
309
|
+
console.error("Conversion error:", error.message);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
```
|
|
313
|
+
|
|
177
314
|
### Batch Processing
|
|
178
315
|
|
|
179
316
|
```javascript
|
|
@@ -190,13 +327,53 @@ vcfFiles.forEach((file) => {
|
|
|
190
327
|
const contacts = vcfToJsonFromFile(path.join("./vcf-files", file));
|
|
191
328
|
const outputFile = file.replace(".vcf", ".json");
|
|
192
329
|
saveJsonToFile(contacts, path.join("./json-output", outputFile));
|
|
193
|
-
console.log(
|
|
330
|
+
console.log(`Converted ${file} (${contacts.length} contacts)`);
|
|
194
331
|
} catch (error) {
|
|
195
|
-
console.error(
|
|
332
|
+
console.error(`Failed to convert ${file}:`, error.message);
|
|
196
333
|
}
|
|
197
334
|
});
|
|
198
335
|
```
|
|
199
336
|
|
|
337
|
+
## Troubleshooting
|
|
338
|
+
|
|
339
|
+
### Common Issues
|
|
340
|
+
|
|
341
|
+
**File not found error:**
|
|
342
|
+
|
|
343
|
+
```bash
|
|
344
|
+
Error: ENOENT: no such file or directory
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
- Ensure the VCF file path is correct
|
|
348
|
+
- Use absolute paths if relative paths don't work
|
|
349
|
+
- Check file permissions
|
|
350
|
+
|
|
351
|
+
**Invalid VCF format:**
|
|
352
|
+
|
|
353
|
+
```bash
|
|
354
|
+
Error: Invalid VCF format
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
- Ensure your file starts with `BEGIN:VCARD` and ends with `END:VCARD`
|
|
358
|
+
- Check for corrupted or incomplete vCard entries
|
|
359
|
+
- Validate the VCF file structure
|
|
360
|
+
|
|
361
|
+
**Empty output:**
|
|
362
|
+
|
|
363
|
+
- Check if the VCF file contains properly formatted vCard entries
|
|
364
|
+
- Ensure the file encoding is UTF-8
|
|
365
|
+
- Verify the VCF version is supported (v2.1, v3.0, v4.0)
|
|
366
|
+
|
|
367
|
+
**CLI command not found:**
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
'vcf-to-json' is not recognized as an internal or external command
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
- Reinstall globally: `npm install -g vcf-to-json-converter`
|
|
374
|
+
- Check your PATH environment variable
|
|
375
|
+
- Try using `npx vcf-to-json-converter` instead
|
|
376
|
+
|
|
200
377
|
## CLI Examples
|
|
201
378
|
|
|
202
379
|
```bash
|
|
@@ -216,26 +393,65 @@ vcf-to-json contacts.vcf contacts.json --compact
|
|
|
216
393
|
## Requirements
|
|
217
394
|
|
|
218
395
|
- Node.js 12.0.0 or higher
|
|
219
|
-
- npm or
|
|
396
|
+
- npm 6.0.0 or higher
|
|
220
397
|
|
|
221
398
|
## Contributing
|
|
222
399
|
|
|
400
|
+
We welcome contributions! Please follow these steps:
|
|
401
|
+
|
|
223
402
|
1. Fork the repository
|
|
224
|
-
2. Create a feature branch
|
|
225
|
-
3.
|
|
226
|
-
4.
|
|
227
|
-
5.
|
|
403
|
+
2. Create a feature branch (`git checkout -b feature/amazing-feature`)
|
|
404
|
+
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
|
|
405
|
+
4. Push to the branch (`git push origin feature/amazing-feature`)
|
|
406
|
+
5. Open a Pull Request
|
|
407
|
+
|
|
408
|
+
### Development Setup
|
|
409
|
+
|
|
410
|
+
```bash
|
|
411
|
+
# Clone the repository
|
|
412
|
+
git clone https://github.com/shubhanshurav/vcf-to-json.git
|
|
413
|
+
cd vcf-to-json
|
|
414
|
+
|
|
415
|
+
# Install dependencies (if any)
|
|
416
|
+
npm install
|
|
417
|
+
|
|
418
|
+
# Run tests
|
|
419
|
+
npm test
|
|
420
|
+
|
|
421
|
+
# Test CLI locally
|
|
422
|
+
node index.js contacts.vcf
|
|
423
|
+
```
|
|
228
424
|
|
|
229
425
|
## License
|
|
230
426
|
|
|
231
|
-
MIT License - see LICENSE file for details.
|
|
427
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
428
|
+
|
|
429
|
+
## Author
|
|
232
430
|
|
|
233
|
-
|
|
431
|
+
**Shubhanshu Rao**
|
|
234
432
|
|
|
235
|
-
|
|
433
|
+
- GitHub: [@shubhanshurav](https://github.com/shubhanshurav)
|
|
434
|
+
- Repository: [vcf-to-json](https://github.com/shubhanshurav/vcf-to-json)
|
|
435
|
+
|
|
436
|
+
## Links
|
|
437
|
+
|
|
438
|
+
- [npm package](https://www.npmjs.com/package/vcf-to-json-converter)
|
|
439
|
+
- [GitHub repository](https://github.com/shubhanshurav/vcf-to-json)
|
|
440
|
+
- [Report Issues](https://github.com/shubhanshurav/vcf-to-json/issues)
|
|
441
|
+
- [Changelog](https://github.com/shubhanshurav/vcf-to-json/blob/main/CHANGELOG.md)
|
|
442
|
+
|
|
443
|
+
## Version History
|
|
444
|
+
|
|
445
|
+
### v1.0.0 (Latest)
|
|
236
446
|
|
|
237
447
|
- Initial release
|
|
238
|
-
- CLI support
|
|
239
|
-
- Comprehensive vCard field parsing
|
|
240
|
-
-
|
|
241
|
-
- TypeScript
|
|
448
|
+
- CLI support with global installation
|
|
449
|
+
- Comprehensive vCard field parsing (v2.1, v3.0, v4.0)
|
|
450
|
+
- Robust error handling and validation
|
|
451
|
+
- TypeScript definitions included
|
|
452
|
+
- UTF-8 and international character support
|
|
453
|
+
- Zero dependencies for maximum compatibility
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
**Star this repository if you find it helpful!**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vcf-to-json-converter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "A lightweight Node.js library to convert VCF (vCard) files to JSON format with CLI support",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Shubhanshu Rao",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
],
|
|
27
27
|
"repository": {
|
|
28
28
|
"type": "git",
|
|
29
|
-
"url": "https://github.com/
|
|
29
|
+
"url": "https://github.com/shubhanshurav/vcf-to-json.git"
|
|
30
30
|
},
|
|
31
31
|
"bugs": {
|
|
32
|
-
"url": "https://github.com/
|
|
32
|
+
"url": "https://github.com/shubhanshurav/vcf-to-json.git/issues"
|
|
33
33
|
},
|
|
34
|
-
"homepage": "https://github.com/
|
|
34
|
+
"homepage": "https://github.com/shubhanshurav/vcf-to-json#readme",
|
|
35
35
|
"engines": {
|
|
36
36
|
"node": ">=12.0.0"
|
|
37
37
|
},
|