Parse and construct vCards, jCards
npm install vcf``sh`
$ npm install --save vcf
* Usage
- Parsing
* Formats
- jCard
- vCard
* API Reference
* Benchmarks
`javascript`
var vCard = require( 'vcf' )
`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: 'forrestgump@example.com'],
rev: [String: '20080424T195243Z']
}
}
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 )
`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", "forrestgump@example.com" ],
[ "rev", {}, "text", "20080424T195243Z" ]
]
]
`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:forrestgump@example.com
REV:20080424T195243Z
END:VCARD
* vCard
* new vCard()
* _instance_
* .version : String
* .data : Object
* .get(key) ⇒ Object \| Array
* .set(key, value, params)
* .add(key, value, params)
* .setProperty(prop)
* .addProperty(prop)
* .parse(value) ⇒ vCard
* .toString(version, charset) ⇒ String
* .toJCard(version) ⇒ Array
* .toJSON() ⇒ Array
* _static_
* .Property
* new Property(field, value, params)
* _instance_
* .is(type) ⇒ Boolean
* .isEmpty() ⇒ Boolean
* .clone() ⇒ Property
* .toString(version) ⇒ String
* .valueOf() ⇒ String
* .toJSON() ⇒ Array
* _static_
* .prototype : Object
* .fromJSON(data) ⇒ Property
* .mimeType : String
* .extension : String
* .versions : Array
* .foldLine ⇒ String
* .parseLines : function
* .normalize(input) ⇒ String
* .isSupported(version) ⇒ Boolean
* .parse(value) ⇒ Array.<vCard>
* .fromJSON(jcard) ⇒ vCard
* .format(card, version) ⇒ String
*
*
Kind: instance property of vCard
*
Kind: instance property of vCard
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| key | String |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| key | String |
| value | String |
| params | Object |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| key | String |
| value | String |
| params | Object |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| prop | Property |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| prop | Property |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| value | String |
*
Kind: instance method of vCard
| Param | Type |
| --- | --- |
| version | String |
| charset | String |
*
Kind: instance method of vCard
Returns: Array - jCard
| Param | Type | Default |
| --- | --- | --- |
| version | String | '4.0' |
*
Kind: instance method of vCard
Returns: Array - jCard
*
vCard * .Property
* new Property(field, value, params)
* _instance_
* .is(type) ⇒ Boolean
* .isEmpty() ⇒ Boolean
* .clone() ⇒ Property
* .toString(version) ⇒ String
* .valueOf() ⇒ String
* .toJSON() ⇒ Array
* _static_
* .prototype : Object
* .fromJSON(data) ⇒ 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
| Param | Type |
| --- | --- |
| type | String |
*
#### property.isEmpty() ⇒ Boolean
Check whether the property is empty
Kind: instance method of Property
*
#### property.clone() ⇒ Property
Clone the property
Kind: instance method of Property
*
#### property.toString(version) ⇒ String
Format the property as vcf with given version
Kind: instance method of Property
| Param | Type |
| --- | --- |
| version | String |
*
#### property.valueOf() ⇒ String
Get the property's value
Kind: instance method of Property
*
#### property.toJSON() ⇒ Array
Format the property as jCard data
Kind: instance method of Property
*
#### Property.prototype : Object
Property prototype
Kind: static property of Property
*
#### Property.fromJSON(data) ⇒ Property
Constructs a vCard.Property from jCard data
Kind: static method of Property
| Param | Type |
| --- | --- |
| data | Array |
*
Kind: static property of vCard
*
Kind: static property of vCard
*
Kind: static property of vCard
*
Kind: static property of vCard
See: http://tools.ietf.org/html/rfc5322#section-2.1.1
| Param | Type |
| --- | --- |
| input | String |
| maxLength | Number |
| hardWrap | Boolean |
*
Kind: static property of vCard
Internal: used by vCard#parse()`
*
Kind: static method of vCard
| Param | Type |
| --- | --- |
| input | String |
*
Kind: static method of vCard
| Param | Type |
| --- | --- |
| version | String |
*
Kind: static method of vCard
| Param | Type |
| --- | --- |
| value | String \| Buffer |
*
Kind: static method of vCard
| Param | Type |
| --- | --- |
| jcard | Array |
*
Kind: static method of vCard
| Param | Type |
| --- | --- |
| card | vCard |
| version | String |
*