vCard Parser

1.0.0 · maintenance · verified Tue Apr 21

The `vcard-parser` library is a utility for parsing vCard data into JavaScript objects and converting JavaScript objects back into vCard strings. It is designed to be a simple, standalone solution compatible with both Node.js environments and web browsers. Currently stable at version 1.0.0, the package primarily targets CommonJS module systems, as indicated by its usage examples. While it offers core vCard parsing and generation capabilities, its 'simple' nature might imply a focus on common vCard patterns rather than full support for every obscure or bleeding-edge vCard specification variant. As a 1.0.0 release, its release cadence is likely stable with infrequent updates, and its key differentiator is its straightforward, no-frills approach to vCard manipulation.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates how to parse a raw vCard string into a JavaScript object and then convert that object back into a vCard string using the `vcard-parser` library.

const vCard = require('vcard-parser');

const raw = 'BEGIN:VCARD\r\n' +
          'FN:Forrest Gump\r\n' +
          'N:Gump;Forrest;;Mr.;\r\n' +
          'TEL;TYPE=HOME:78884545247\r\n' +
          'END:VCARD';

// Parse vCard data into a JavaScript object
const card = vCard.parse(raw);

console.log('Parsed vCard object:', JSON.stringify(card, null, 2));
/* Expected output:
{
  "fn": [
    {
      "value": "Forrest Gump"
    }
  ],
  "n": [
    {
      "value": [
        "Gump",
        "Forrest",
        "",
        "Mr.",
        ""
      ]
    }
  ],
  "tel": [
    {
      "value": "78884545247",
      "meta": {
        "type": [
          "HOME"
        ]
      }
    }
  ]
}
*/

// Generate vCard data from a JavaScript object
const generated = vCard.generate(card);

console.log('\nGenerated vCard string:\n', generated);
// Expected output: BEGIN:VCARD\r\nFN:Forrest Gump\r\nN:Gump;Forrest;;Mr.;\r\nTEL;TYPE=HOME:78884545247\r\nEND:VCARD

view raw JSON →