An open API service indexing awesome lists of open source software.

https://github.com/linusbolls/node-vcf

Fork of the vcf NPM package for parsing vCards
https://github.com/linusbolls/node-vcf

Last synced: about 1 month ago
JSON representation

Fork of the vcf NPM package for parsing vCards

Awesome Lists containing this project

README

        

# VCF / vCard
[![npm](https://img.shields.io/npm/v/vcf.svg?style=flat-square)](https://npmjs.com/package/vcf)
[![npm license](https://img.shields.io/npm/l/vcf.svg?style=flat-square)](https://npmjs.com/package/vcf)
[![npm downloads](https://img.shields.io/npm/dm/vcf.svg?style=flat-square)](https://npmjs.com/package/vcf)
[![build status](https://img.shields.io/travis/jhermsmeier/node-vcf.svg?style=flat-square)](https://travis-ci.org/jhermsmeier/node-vcf)

## Install via [npm](https://npmjs.com)

```sh
$ npm install --save vcf
```

## Index

* [Usage](#usage)
- [Parsing](#parsing-a-vcard)
* [Formats](#formats)
- [jCard](#format-jcard)
- [vCard](#format-vcf)
* [API Reference](#api-reference)
* [Benchmarks](#benchmarks)

## Usage

```javascript
var vCard = require( 'vcf' )
```

### Parsing a Single vCard

```js
var card = new vCard().parse( string )
```

```js
vCard {
version: '4.0',
data: {
version: [String: '4.0'],
n: [String: 'Gump;Forrest;;;'],
fn: [String: 'Forrest Gump'],
org: [String: 'Bubba Gump Shrimp Co.'],
title: [String: 'Shrimp Man'],
photo: { [String: 'http://www.example.com/dir_photos/my_photo.gif'] mediatype: 'image/gif' },
tel: [
{ [String: 'tel:+11115551212'] type: [ 'work', 'voice' ], value: 'uri' },
{ [String: 'tel:+14045551212'] type: [ 'home', 'voice' ], value: 'uri' }
],
adr: [
{ [String: ';;100 Waters Edge;Baytown;LA;30314;United States of America']
type: 'work',
label: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' },
{ [String: ';;42 Plantation St.;Baytown;LA;30314;United States of America']
type: 'home',
label: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"' }
],
email: [String: '[email protected]'],
rev: [String: '20080424T195243Z']
}
}
```

### Parsing Multiple vCards

In order to deal with a string that contains multiple vCards,
you will need to use a different function, which returns an array of cards:

```js
var cards = vCard.parse( string )
```

## Formats

### Format: jCard

```js
var card = vCard.fromJSON( data )
```

```js
var jcard = card.toJSON()
```

```json
[ "vcard",
[
[ "version", {}, "text", "4.0" ],
[ "n", {}, "text", [ "Gump", "Forrest", "", "", "" ] ],
[ "fn", {}, "text", "Forrest Gump" ],
[ "org", {}, "text", "Bubba Gump Shrimp Co." ],
[ "title", {}, "text", "Shrimp Man" ],
[
"photo", { "mediatype": "image/gif" },
"text", "http://www.example.com/dir_photos/my_photo.gif"
],
[ "tel", { "type": [ "work", "voice" ], "value": "uri" }, "uri", "tel:+11115551212" ],
[ "tel", { "type": [ "home", "voice" ], "value": "uri" }, "uri", "tel:+14045551212" ],
[
"adr", { "type": "work", "label":"\"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America\"" },
"text", [ "", "", "100 Waters Edge", "Baytown", "LA", "30314", "United States of America" ]
],
[
"adr", { "type": "home", "label": "\"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica\"" },
"text", [ "", "", "42 Plantation St.", "Baytown", "LA", "30314", "United States of America" ]
],
[ "email", {}, "text", "[email protected]" ],
[ "rev", {}, "text", "20080424T195243Z" ]
]
]
```

### Format: VCF

```js
var vcf = card.toString()
var vcf = card.toString( '4.0' )
```

```vcf
BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+11115551212
TEL;TYPE=home,voice;VALUE=uri:tel:+14045551212
ADR;TYPE=work;LABEL="100 Waters Edge\nBaytown, LA 30314\nUnited States
of America":;;100 Waters Edge;Baytown;LA;30314;United States of America
ADR;TYPE=home;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited
States ofAmerica":;;42 Plantation St.;Baytown;LA;30314;United States of
America
EMAIL:[email protected]
REV:20080424T195243Z
END:VCARD
```

## API Reference

## vCard
**Kind**: global class

* [vCard](#vCard)
* [new vCard()](#new_vCard_new)
* _instance_
* [.version](#vCard+version) : String
* [.data](#vCard+data) : Object
* [.get(key)](#vCard+get) ⇒ Object \| Array
* [.set(key, value, params)](#vCard+set)
* [.add(key, value, params)](#vCard+add)
* [.setProperty(prop)](#vCard+setProperty)
* [.addProperty(prop)](#vCard+addProperty)
* [.parse(value)](#vCard+parse) ⇒ [vCard](#vCard)
* [.toString(version, charset)](#vCard+toString) ⇒ String
* [.toJCard(version)](#vCard+toJCard) ⇒ Array
* [.toJSON()](#vCard+toJSON) ⇒ Array
* _static_
* [.Property](#vCard.Property)
* [new Property(field, value, params)](#new_vCard.Property_new)
* _instance_
* [.is(type)](#vCard.Property+is) ⇒ Boolean
* [.isEmpty()](#vCard.Property+isEmpty) ⇒ Boolean
* [.clone()](#vCard.Property+clone) ⇒ Property
* [.toString(version)](#vCard.Property+toString) ⇒ String
* [.valueOf()](#vCard.Property+valueOf) ⇒ String
* [.toJSON()](#vCard.Property+toJSON) ⇒ Array
* _static_
* [.prototype](#vCard.Property.prototype) : Object
* [.fromJSON(data)](#vCard.Property.fromJSON) ⇒ Property
* [.mimeType](#vCard.mimeType) : String
* [.extension](#vCard.extension) : String
* [.versions](#vCard.versions) : Array
* [.foldLine](#vCard.foldLine) ⇒ String
* [.parseLines](#vCard.parseLines) : function
* [.normalize(input)](#vCard.normalize) ⇒ String
* [.isSupported(version)](#vCard.isSupported) ⇒ Boolean
* [.parse(value)](#vCard.parse) ⇒ [Array.<vCard>](#vCard)
* [.fromJSON(jcard)](#vCard.fromJSON) ⇒ [vCard](#vCard)
* [.format(card, version)](#vCard.format) ⇒ String

* * *

### new vCard()
vCard

* * *

### vCard.version : String
Version number

**Kind**: instance property of [vCard](#vCard)

* * *

### vCard.data : Object
Card data

**Kind**: instance property of [vCard](#vCard)

* * *

### vCard.get(key) ⇒ Object \| Array
Get a vCard property

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| key | String |

* * *

### vCard.set(key, value, params)
Set a vCard property

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| key | String |
| value | String |
| params | Object |

* * *

### vCard.add(key, value, params)
Add a vCard property

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| key | String |
| value | String |
| params | Object |

* * *

### vCard.setProperty(prop)
Set a vCard property from an already
constructed vCard.Property

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| prop | [Property](#vCard.Property) |

* * *

### vCard.addProperty(prop)
Add a vCard property from an already
constructed vCard.Property

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| prop | [Property](#vCard.Property) |

* * *

### vCard.parse(value) ⇒ [vCard](#vCard)
Parse a vcf formatted vCard

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| value | String |

* * *

### vCard.toString(version, charset) ⇒ String
Format the vCard as vcf with given version

**Kind**: instance method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| version | String |
| charset | String |

* * *

### vCard.toJCard(version) ⇒ Array
Format the card as jCard

**Kind**: instance method of [vCard](#vCard)
**Returns**: Array - jCard

| Param | Type | Default |
| --- | --- | --- |
| version | String | '4.0' |

* * *

### vCard.toJSON() ⇒ Array
Format the card as jCard

**Kind**: instance method of [vCard](#vCard)
**Returns**: Array - jCard

* * *

### vCard.Property
**Kind**: static class of [vCard](#vCard)

* [.Property](#vCard.Property)
* [new Property(field, value, params)](#new_vCard.Property_new)
* _instance_
* [.is(type)](#vCard.Property+is) ⇒ Boolean
* [.isEmpty()](#vCard.Property+isEmpty) ⇒ Boolean
* [.clone()](#vCard.Property+clone) ⇒ Property
* [.toString(version)](#vCard.Property+toString) ⇒ String
* [.valueOf()](#vCard.Property+valueOf) ⇒ String
* [.toJSON()](#vCard.Property+toJSON) ⇒ Array
* _static_
* [.prototype](#vCard.Property.prototype) : Object
* [.fromJSON(data)](#vCard.Property.fromJSON) ⇒ Property

* * *

#### new Property(field, value, params)
vCard Property

| Param | Type |
| --- | --- |
| field | String |
| value | String |
| params | Object |

* * *

#### property.is(type) ⇒ Boolean
Check whether the property is of a given type

**Kind**: instance method of [Property](#vCard.Property)

| Param | Type |
| --- | --- |
| type | String |

* * *

#### property.isEmpty() ⇒ Boolean
Check whether the property is empty

**Kind**: instance method of [Property](#vCard.Property)

* * *

#### property.clone() ⇒ Property
Clone the property

**Kind**: instance method of [Property](#vCard.Property)

* * *

#### property.toString(version) ⇒ String
Format the property as vcf with given version

**Kind**: instance method of [Property](#vCard.Property)

| Param | Type |
| --- | --- |
| version | String |

* * *

#### property.valueOf() ⇒ String
Get the property's value

**Kind**: instance method of [Property](#vCard.Property)

* * *

#### property.toJSON() ⇒ Array
Format the property as jCard data

**Kind**: instance method of [Property](#vCard.Property)

* * *

#### Property.prototype : Object
Property prototype

**Kind**: static property of [Property](#vCard.Property)

* * *

#### Property.fromJSON(data) ⇒ Property
Constructs a vCard.Property from jCard data

**Kind**: static method of [Property](#vCard.Property)

| Param | Type |
| --- | --- |
| data | Array |

* * *

### vCard.mimeType : String
vCard MIME type

**Kind**: static property of [vCard](#vCard)

* * *

### vCard.extension : String
vCard file extension

**Kind**: static property of [vCard](#vCard)

* * *

### vCard.versions : Array
vCard versions

**Kind**: static property of [vCard](#vCard)

* * *

### vCard.foldLine ⇒ String
Folds a long line according to the RFC 5322.

**Kind**: static property of [vCard](#vCard)
**See**: http://tools.ietf.org/html/rfc5322#section-2.1.1

| Param | Type |
| --- | --- |
| input | String |
| maxLength | Number |
| hardWrap | Boolean |

* * *

### vCard.parseLines : function
Parse an array of vcf formatted lines

**Kind**: static property of [vCard](#vCard)
**Internal**: used by `vCard#parse()`

* * *

### vCard.normalize(input) ⇒ String
Normalizes input (cast to string, line folding, whitespace)

**Kind**: static method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| input | String |

* * *

### vCard.isSupported(version) ⇒ Boolean
Check whether a given version is supported

**Kind**: static method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| version | String |

* * *

### vCard.parse(value) ⇒ [Array.<vCard>](#vCard)
Parses a string or buffer into a vCard object

**Kind**: static method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| value | String \| Buffer |

* * *

### vCard.fromJSON(jcard) ⇒ [vCard](#vCard)
Constructs a vCard from jCard data

**Kind**: static method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| jcard | Array |

* * *

### vCard.format(card, version) ⇒ String
Format a card object according to the given version

**Kind**: static method of [vCard](#vCard)

| Param | Type |
| --- | --- |
| card | [vCard](#vCard) |
| version | String |

* * *