vcard-utf8-parser
v1.0.1
Published
Modern TypeScript CommonJS parser for VCF/vCard files with a simple, promise-first API that produces easy-to-read JSON.
Readme
vcard-utf8-parser
Modern TypeScript CommonJS parser for VCF/vCard files with a simple, promise-first API that produces easy-to-read JSON.
Features
- Promise-first async API
- Decodes
QUOTED-PRINTABLEandBASE64 - Handles
CHARSETwithiconv-lite - Line unfolding and structured fields (
N,ADR,ORG) - Keeps all properties in a normalized map
Supported vCard versions
Parses vCard 2.1, 3.0, and 4.0 style property lines. It is lenient and does not validate against the full RFCs.
Install
npm install vcard-utf8-parserUsage
const { parseFile, parseVcf } = require("vcard-utf8-parser");
async function run() {
const contacts = await parseFile("contacts.vcf");
console.log(contacts[0]);
}
run().catch(console.error);Parse from a string:
const vcfText = "BEGIN:VCARD\nVERSION:2.1\nFN:John Doe\nEND:VCARD";
const contacts = await parseVcf(vcfText);API
parseFile(path, options)
Reads a VCF file and returns an array of parsed contacts.
Options:
fileEncoding: file encoding for the entire VCF (default:utf8)defaultCharset: charset used for encoded values when not specifieddecodeBase64: returnBufferfor base64 values (default:false)includeRaw: include raw vCard lines incard.raw
parseVcf(input, options)
Parses a VCF string (or Buffer) and returns an array of contacts.
Options:
inputEncoding: when input is aBuffer, how to decode it (default:utf8)defaultCharset: charset used for encoded values when not specifieddecodeBase64: returnBufferfor base64 values (default:false)includeRaw: include raw vCard lines incard.raw
Output shape
Each card includes normalized fields and all raw properties:
formattedName,name,phones,emails,addresses,photosproperties: map of property name -> array of detailed entries
This lets you consume a clean JSON shape while still keeping full vCard data.
Field mappings
FN->formattedNameN->name(family,given,additional,prefix,suffix)ORG->organization(array of components)TITLE->titleTEL->phonesEMAIL->emailsURL->urlsADR->addressesNOTE->notesPHOTO->photos
JSON example
[
{
"version": "4.0",
"formattedName": "Valid User",
"name": {
"family": "User",
"given": "Valid"
},
"organization": ["Example", "Org"],
"phones": [{ "value": "+123456", "types": ["cell"], "pref": true }],
"emails": [{ "value": "[email protected]", "types": ["work"], "pref": false }],
"addresses": [
{
"street": "Street",
"locality": "City",
"region": "Region",
"postalCode": "12345",
"country": "Country",
"types": ["work"],
"pref": false
}
],
"photos": [],
"properties": {
"FN": [{ "name": "FN", "params": {}, "value": "Valid User", "rawValue": "Valid User" }]
}
}
]Limitations
- Lenient parser; it does not validate full vCard conformance.
- Unknown properties are preserved under
propertiesbut are not normalized. - Base64 values are returned as strings unless
decodeBase64is enabled.
