# vcard-xml

> This library should simplify handling VCard XML documents.

Latest version **1.1.1** (published 2026-04-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install vcard-xml
pnpm add vcard-xml
yarn add vcard-xml
bun add vcard-xml
```

## Health

**Score 60/100 (C)** — status: stable.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2026-04-07 |
| First published | 2023-04-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 59.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Gabriel Unterholzer |
| Maintainers | gebsl |

## Links

- npm: https://www.npmjs.com/package/vcard-xml
- Repository: https://github.com/dec112/vcard-xml-javascript
- Homepage: https://github.com/dec112/vcard-xml-javascript#readme
- Issues: https://github.com/dec112/vcard-xml-javascript/issues
- npm.io page: https://npm.io/package/vcard-xml

## Recent versions

- 1.1.1 (latest) — 2026-04-07
- 1.1.0 — 2024-08-06
- 1.0.0 — 2023-04-02
- 0.1.0 — 2023-04-02

## README

# vcard-xml - XML VCard parsing and writing

This library should simplify handling VCard XML documents.

This README currently only describes simple usage of this library.

## Important Notices

This library requires `@xmldom/xmldom` as a peer-dependency *only* in node.js environments!
JavaScript browser environments always have a DOM implementation on board, therefore `@xmldom/xmldom` is not needed there.

## Installation

Requires `node.js` and `npm`.

```bash
npm install vcard-xml
```

## Usage

### VCard creation

```typescript
import { 
  VCard,
  Gender,
  KeyId,

  XMLCompat, 
  getNodeImpl,
  getWebImpl,
} from 'vcard-xml';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getWebImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getNodeImpl());

const vcard = new VCard()
  .addFullName('Alice Smith')
  .addFirstname('Alice')
  .addLastname('Smith')
  .addNamePrefix('Dr.')
  .addNameSuffix('MSc.')
  .addBirthday(new Date(Date.UTC(1990, 2, 3)))
  .addGender(Gender.OTHER)
  .addTelephone('+436641234567')
  .addEmail('info@dec112.at')
  .addStreet('Example Street 3')
  .addCode('1234')
  .addLocality('Brunnenthal')
  .addRegion('Upper Austria')
  .addCountry('Austria');

if (!vcard)
  throw 'Something is wrong with this vcard';

const xmlObj = vcard.toXML();
console.log(vcard.toXMLString(vcard));
```

### VCard parsing

```typescript
import { 
  VCard,
  Gender,
  KeyId,

  XMLCompat, 
  getNodeImpl,
  getWebImpl,
} from 'vcard-xml';

// if xmldom interface is available (e.g. on web browsers)
XMLCompat.initialize(getWebImpl());
// if xmldom interface is NOT available (e.g. on node environments)
// also don't forget to install required peer dependency @xmldom/xmldom
XMLCompat.initialize(getNodeImpl());

const parsed = VCard.fromXML('<xml...>');

if (!parsed)
  throw 'Something is wrong with this vcard';

console.log(vcard.fullName);
```

## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

## License
Distributed under the MIT License. See LICENSE for more information.

---
_Source: https://npm.io/package/vcard-xml · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
