vcf-to-json-converter 1.0.1 → 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.
- package/LICENSE +21 -21
- package/README.md +457 -457
- package/index.d.ts +32 -32
- package/index.js +252 -252
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,457 +1,457 @@
|
|
|
1
|
-
# vcf-to-json-converter
|
|
2
|
-
|
|
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)
|
|
33
|
-
|
|
34
|
-
## Features
|
|
35
|
-
|
|
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
|
|
46
|
-
|
|
47
|
-
## Installation
|
|
48
|
-
|
|
49
|
-
Using npm:
|
|
50
|
-
|
|
51
|
-
```bash
|
|
52
|
-
npm install vcf-to-json-converter
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
For global CLI usage:
|
|
56
|
-
|
|
57
|
-
```bash
|
|
58
|
-
npm install -g vcf-to-json-converter
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
Using yarn:
|
|
62
|
-
|
|
63
|
-
```bash
|
|
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`);
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
## Usage
|
|
86
|
-
|
|
87
|
-
### Command Line Interface
|
|
88
|
-
|
|
89
|
-
```bash
|
|
90
|
-
# Convert and display JSON in terminal
|
|
91
|
-
vcf-to-json contacts.vcf
|
|
92
|
-
|
|
93
|
-
# Convert and save to file
|
|
94
|
-
vcf-to-json contacts.vcf output.json
|
|
95
|
-
|
|
96
|
-
# Convert with compact formatting (minified JSON)
|
|
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
|
|
102
|
-
```
|
|
103
|
-
|
|
104
|
-
### Programmatic Usage
|
|
105
|
-
|
|
106
|
-
```javascript
|
|
107
|
-
const {
|
|
108
|
-
vcfToJson,
|
|
109
|
-
vcfToJsonFromFile,
|
|
110
|
-
saveJsonToFile,
|
|
111
|
-
} = require("vcf-to-json-converter");
|
|
112
|
-
|
|
113
|
-
// Method 1: Convert VCF text content
|
|
114
|
-
const vcfContent = `BEGIN:VCARD
|
|
115
|
-
VERSION:3.0
|
|
116
|
-
FN:John Doe
|
|
117
|
-
N:Doe;John;;;
|
|
118
|
-
TEL;TYPE=CELL:+1234567890
|
|
119
|
-
EMAIL;TYPE=HOME:john@example.com
|
|
120
|
-
ORG:ACME Corp
|
|
121
|
-
TITLE:Software Engineer
|
|
122
|
-
END:VCARD`;
|
|
123
|
-
|
|
124
|
-
const contacts = vcfToJson(vcfContent);
|
|
125
|
-
console.log("Parsed contacts:", contacts.length);
|
|
126
|
-
|
|
127
|
-
// Method 2: Convert VCF file directly
|
|
128
|
-
try {
|
|
129
|
-
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
130
|
-
console.log(`Converted ${contacts.length} contacts`);
|
|
131
|
-
|
|
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
|
-
});
|
|
141
|
-
} catch (error) {
|
|
142
|
-
console.error("Conversion failed:", error.message);
|
|
143
|
-
}
|
|
144
|
-
```
|
|
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
|
-
|
|
155
|
-
## API Reference
|
|
156
|
-
|
|
157
|
-
### `vcfToJson(vcfText: string): Contact[]`
|
|
158
|
-
|
|
159
|
-
Converts VCF text content to JSON.
|
|
160
|
-
|
|
161
|
-
**Parameters:**
|
|
162
|
-
|
|
163
|
-
- `vcfText` _(string)_: The VCF content as a string
|
|
164
|
-
|
|
165
|
-
**Returns:** Array of contact objects
|
|
166
|
-
|
|
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[]`
|
|
176
|
-
|
|
177
|
-
Converts a VCF file to JSON.
|
|
178
|
-
|
|
179
|
-
**Parameters:**
|
|
180
|
-
|
|
181
|
-
- `filePath` _(string)_: Path to the VCF file
|
|
182
|
-
|
|
183
|
-
**Returns:** Array of contact objects
|
|
184
|
-
|
|
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`
|
|
194
|
-
|
|
195
|
-
Saves JSON data to a file.
|
|
196
|
-
|
|
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
|
-
```
|
|
209
|
-
|
|
210
|
-
## Output Format
|
|
211
|
-
|
|
212
|
-
Each contact is converted to the following JSON structure:
|
|
213
|
-
|
|
214
|
-
```json
|
|
215
|
-
{
|
|
216
|
-
"fullName": "John Doe",
|
|
217
|
-
"firstName": "John",
|
|
218
|
-
"lastName": "Doe",
|
|
219
|
-
"phones": [
|
|
220
|
-
{
|
|
221
|
-
"value": "+1234567890",
|
|
222
|
-
"type": "CELL"
|
|
223
|
-
}
|
|
224
|
-
],
|
|
225
|
-
"emails": [
|
|
226
|
-
{
|
|
227
|
-
"value": "john@example.com",
|
|
228
|
-
"type": "HOME"
|
|
229
|
-
}
|
|
230
|
-
],
|
|
231
|
-
"organization": "ACME Corp",
|
|
232
|
-
"title": "Software Engineer",
|
|
233
|
-
"note": "Important contact",
|
|
234
|
-
"photo": "",
|
|
235
|
-
"url": "",
|
|
236
|
-
"raw": {
|
|
237
|
-
/* Original parsed vCard object */
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
```
|
|
241
|
-
|
|
242
|
-
## Supported vCard Fields
|
|
243
|
-
|
|
244
|
-
- **Name:** Full name, first name, last name
|
|
245
|
-
- **Phone:** Multiple phone numbers with types
|
|
246
|
-
- **Email:** Multiple email addresses with types
|
|
247
|
-
- **Organization:** Company/organization name
|
|
248
|
-
- **Title:** Job title
|
|
249
|
-
- **Note:** Notes/comments
|
|
250
|
-
- **Photo:** Photo data (base64)
|
|
251
|
-
- **URL:** Website URLs
|
|
252
|
-
- **Raw:** Complete original vCard data
|
|
253
|
-
|
|
254
|
-
## Error Handling
|
|
255
|
-
|
|
256
|
-
The library provides comprehensive error handling for:
|
|
257
|
-
|
|
258
|
-
- Invalid file paths
|
|
259
|
-
- Missing files
|
|
260
|
-
- Permission errors
|
|
261
|
-
- Malformed VCF content
|
|
262
|
-
- Invalid input parameters
|
|
263
|
-
|
|
264
|
-
## Examples
|
|
265
|
-
|
|
266
|
-
### Basic Conversion
|
|
267
|
-
|
|
268
|
-
```javascript
|
|
269
|
-
const { vcfToJsonFromFile } = require("vcf-to-json-converter");
|
|
270
|
-
|
|
271
|
-
const contacts = vcfToJsonFromFile("my-contacts.vcf");
|
|
272
|
-
console.log(`Found ${contacts.length} contacts`);
|
|
273
|
-
|
|
274
|
-
contacts.forEach((contact) => {
|
|
275
|
-
console.log(
|
|
276
|
-
`${contact.fullName}: ${contact.phones.map((p) => p.value).join(", ")}`
|
|
277
|
-
);
|
|
278
|
-
});
|
|
279
|
-
```
|
|
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
|
-
|
|
314
|
-
### Batch Processing
|
|
315
|
-
|
|
316
|
-
```javascript
|
|
317
|
-
const fs = require("fs");
|
|
318
|
-
const path = require("path");
|
|
319
|
-
const { vcfToJsonFromFile, saveJsonToFile } = require("vcf-to-json-converter");
|
|
320
|
-
|
|
321
|
-
const vcfFiles = fs
|
|
322
|
-
.readdirSync("./vcf-files")
|
|
323
|
-
.filter((f) => f.endsWith(".vcf"));
|
|
324
|
-
|
|
325
|
-
vcfFiles.forEach((file) => {
|
|
326
|
-
try {
|
|
327
|
-
const contacts = vcfToJsonFromFile(path.join("./vcf-files", file));
|
|
328
|
-
const outputFile = file.replace(".vcf", ".json");
|
|
329
|
-
saveJsonToFile(contacts, path.join("./json-output", outputFile));
|
|
330
|
-
console.log(`Converted ${file} (${contacts.length} contacts)`);
|
|
331
|
-
} catch (error) {
|
|
332
|
-
console.error(`Failed to convert ${file}:`, error.message);
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
```
|
|
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
|
-
|
|
377
|
-
## CLI Examples
|
|
378
|
-
|
|
379
|
-
```bash
|
|
380
|
-
# Show help
|
|
381
|
-
vcf-to-json --help
|
|
382
|
-
|
|
383
|
-
# Convert single file
|
|
384
|
-
vcf-to-json contacts.vcf
|
|
385
|
-
|
|
386
|
-
# Convert and save to specific file
|
|
387
|
-
vcf-to-json contacts.vcf my-contacts.json
|
|
388
|
-
|
|
389
|
-
# Compact output
|
|
390
|
-
vcf-to-json contacts.vcf contacts.json --compact
|
|
391
|
-
```
|
|
392
|
-
|
|
393
|
-
## Requirements
|
|
394
|
-
|
|
395
|
-
- Node.js 12.0.0 or higher
|
|
396
|
-
- npm 6.0.0 or higher
|
|
397
|
-
|
|
398
|
-
## Contributing
|
|
399
|
-
|
|
400
|
-
We welcome contributions! Please follow these steps:
|
|
401
|
-
|
|
402
|
-
1. Fork the repository
|
|
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
|
-
```
|
|
424
|
-
|
|
425
|
-
## License
|
|
426
|
-
|
|
427
|
-
MIT License - see [LICENSE](LICENSE) file for details.
|
|
428
|
-
|
|
429
|
-
## Author
|
|
430
|
-
|
|
431
|
-
**Shubhanshu Rao**
|
|
432
|
-
|
|
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)
|
|
446
|
-
|
|
447
|
-
- Initial release
|
|
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!**
|
|
1
|
+
# vcf-to-json-converter
|
|
2
|
+
|
|
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)
|
|
33
|
+
|
|
34
|
+
## Features
|
|
35
|
+
|
|
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
|
|
46
|
+
|
|
47
|
+
## Installation
|
|
48
|
+
|
|
49
|
+
Using npm:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
npm install vcf-to-json-converter
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
For global CLI usage:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install -g vcf-to-json-converter
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
Using yarn:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
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`);
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Usage
|
|
86
|
+
|
|
87
|
+
### Command Line Interface
|
|
88
|
+
|
|
89
|
+
```bash
|
|
90
|
+
# Convert and display JSON in terminal
|
|
91
|
+
vcf-to-json contacts.vcf
|
|
92
|
+
|
|
93
|
+
# Convert and save to file
|
|
94
|
+
vcf-to-json contacts.vcf output.json
|
|
95
|
+
|
|
96
|
+
# Convert with compact formatting (minified JSON)
|
|
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
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Programmatic Usage
|
|
105
|
+
|
|
106
|
+
```javascript
|
|
107
|
+
const {
|
|
108
|
+
vcfToJson,
|
|
109
|
+
vcfToJsonFromFile,
|
|
110
|
+
saveJsonToFile,
|
|
111
|
+
} = require("vcf-to-json-converter");
|
|
112
|
+
|
|
113
|
+
// Method 1: Convert VCF text content
|
|
114
|
+
const vcfContent = `BEGIN:VCARD
|
|
115
|
+
VERSION:3.0
|
|
116
|
+
FN:John Doe
|
|
117
|
+
N:Doe;John;;;
|
|
118
|
+
TEL;TYPE=CELL:+1234567890
|
|
119
|
+
EMAIL;TYPE=HOME:john@example.com
|
|
120
|
+
ORG:ACME Corp
|
|
121
|
+
TITLE:Software Engineer
|
|
122
|
+
END:VCARD`;
|
|
123
|
+
|
|
124
|
+
const contacts = vcfToJson(vcfContent);
|
|
125
|
+
console.log("Parsed contacts:", contacts.length);
|
|
126
|
+
|
|
127
|
+
// Method 2: Convert VCF file directly
|
|
128
|
+
try {
|
|
129
|
+
const contacts = vcfToJsonFromFile("./contacts.vcf");
|
|
130
|
+
console.log(`Converted ${contacts.length} contacts`);
|
|
131
|
+
|
|
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
|
+
});
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.error("Conversion failed:", error.message);
|
|
143
|
+
}
|
|
144
|
+
```
|
|
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
|
+
|
|
155
|
+
## API Reference
|
|
156
|
+
|
|
157
|
+
### `vcfToJson(vcfText: string): Contact[]`
|
|
158
|
+
|
|
159
|
+
Converts VCF text content to JSON.
|
|
160
|
+
|
|
161
|
+
**Parameters:**
|
|
162
|
+
|
|
163
|
+
- `vcfText` _(string)_: The VCF content as a string
|
|
164
|
+
|
|
165
|
+
**Returns:** Array of contact objects
|
|
166
|
+
|
|
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[]`
|
|
176
|
+
|
|
177
|
+
Converts a VCF file to JSON.
|
|
178
|
+
|
|
179
|
+
**Parameters:**
|
|
180
|
+
|
|
181
|
+
- `filePath` _(string)_: Path to the VCF file
|
|
182
|
+
|
|
183
|
+
**Returns:** Array of contact objects
|
|
184
|
+
|
|
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`
|
|
194
|
+
|
|
195
|
+
Saves JSON data to a file.
|
|
196
|
+
|
|
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
|
+
```
|
|
209
|
+
|
|
210
|
+
## Output Format
|
|
211
|
+
|
|
212
|
+
Each contact is converted to the following JSON structure:
|
|
213
|
+
|
|
214
|
+
```json
|
|
215
|
+
{
|
|
216
|
+
"fullName": "John Doe",
|
|
217
|
+
"firstName": "John",
|
|
218
|
+
"lastName": "Doe",
|
|
219
|
+
"phones": [
|
|
220
|
+
{
|
|
221
|
+
"value": "+1234567890",
|
|
222
|
+
"type": "CELL"
|
|
223
|
+
}
|
|
224
|
+
],
|
|
225
|
+
"emails": [
|
|
226
|
+
{
|
|
227
|
+
"value": "john@example.com",
|
|
228
|
+
"type": "HOME"
|
|
229
|
+
}
|
|
230
|
+
],
|
|
231
|
+
"organization": "ACME Corp",
|
|
232
|
+
"title": "Software Engineer",
|
|
233
|
+
"note": "Important contact",
|
|
234
|
+
"photo": "",
|
|
235
|
+
"url": "",
|
|
236
|
+
"raw": {
|
|
237
|
+
/* Original parsed vCard object */
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
## Supported vCard Fields
|
|
243
|
+
|
|
244
|
+
- **Name:** Full name, first name, last name
|
|
245
|
+
- **Phone:** Multiple phone numbers with types
|
|
246
|
+
- **Email:** Multiple email addresses with types
|
|
247
|
+
- **Organization:** Company/organization name
|
|
248
|
+
- **Title:** Job title
|
|
249
|
+
- **Note:** Notes/comments
|
|
250
|
+
- **Photo:** Photo data (base64)
|
|
251
|
+
- **URL:** Website URLs
|
|
252
|
+
- **Raw:** Complete original vCard data
|
|
253
|
+
|
|
254
|
+
## Error Handling
|
|
255
|
+
|
|
256
|
+
The library provides comprehensive error handling for:
|
|
257
|
+
|
|
258
|
+
- Invalid file paths
|
|
259
|
+
- Missing files
|
|
260
|
+
- Permission errors
|
|
261
|
+
- Malformed VCF content
|
|
262
|
+
- Invalid input parameters
|
|
263
|
+
|
|
264
|
+
## Examples
|
|
265
|
+
|
|
266
|
+
### Basic Conversion
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
const { vcfToJsonFromFile } = require("vcf-to-json-converter");
|
|
270
|
+
|
|
271
|
+
const contacts = vcfToJsonFromFile("my-contacts.vcf");
|
|
272
|
+
console.log(`Found ${contacts.length} contacts`);
|
|
273
|
+
|
|
274
|
+
contacts.forEach((contact) => {
|
|
275
|
+
console.log(
|
|
276
|
+
`${contact.fullName}: ${contact.phones.map((p) => p.value).join(", ")}`
|
|
277
|
+
);
|
|
278
|
+
});
|
|
279
|
+
```
|
|
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
|
+
|
|
314
|
+
### Batch Processing
|
|
315
|
+
|
|
316
|
+
```javascript
|
|
317
|
+
const fs = require("fs");
|
|
318
|
+
const path = require("path");
|
|
319
|
+
const { vcfToJsonFromFile, saveJsonToFile } = require("vcf-to-json-converter");
|
|
320
|
+
|
|
321
|
+
const vcfFiles = fs
|
|
322
|
+
.readdirSync("./vcf-files")
|
|
323
|
+
.filter((f) => f.endsWith(".vcf"));
|
|
324
|
+
|
|
325
|
+
vcfFiles.forEach((file) => {
|
|
326
|
+
try {
|
|
327
|
+
const contacts = vcfToJsonFromFile(path.join("./vcf-files", file));
|
|
328
|
+
const outputFile = file.replace(".vcf", ".json");
|
|
329
|
+
saveJsonToFile(contacts, path.join("./json-output", outputFile));
|
|
330
|
+
console.log(`Converted ${file} (${contacts.length} contacts)`);
|
|
331
|
+
} catch (error) {
|
|
332
|
+
console.error(`Failed to convert ${file}:`, error.message);
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
```
|
|
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
|
+
|
|
377
|
+
## CLI Examples
|
|
378
|
+
|
|
379
|
+
```bash
|
|
380
|
+
# Show help
|
|
381
|
+
vcf-to-json --help
|
|
382
|
+
|
|
383
|
+
# Convert single file
|
|
384
|
+
vcf-to-json contacts.vcf
|
|
385
|
+
|
|
386
|
+
# Convert and save to specific file
|
|
387
|
+
vcf-to-json contacts.vcf my-contacts.json
|
|
388
|
+
|
|
389
|
+
# Compact output
|
|
390
|
+
vcf-to-json contacts.vcf contacts.json --compact
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
## Requirements
|
|
394
|
+
|
|
395
|
+
- Node.js 12.0.0 or higher
|
|
396
|
+
- npm 6.0.0 or higher
|
|
397
|
+
|
|
398
|
+
## Contributing
|
|
399
|
+
|
|
400
|
+
We welcome contributions! Please follow these steps:
|
|
401
|
+
|
|
402
|
+
1. Fork the repository
|
|
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
|
+
```
|
|
424
|
+
|
|
425
|
+
## License
|
|
426
|
+
|
|
427
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
428
|
+
|
|
429
|
+
## Author
|
|
430
|
+
|
|
431
|
+
**Shubhanshu Rao**
|
|
432
|
+
|
|
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)
|
|
446
|
+
|
|
447
|
+
- Initial release
|
|
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!**
|