vCard version 4.0 javascript library for creating or parsing vCards, with full implementation of RFC 6350
For use in node or in the browser
See documentation
- Install from npm
npm install vcard4
- Install from github
git clone https://github.com/kelseykm/vcard4.git
BEGIN:VCARD
VERSION:4.0
N:Doe;John;;;
FN:John Doe
ORG:Example.com Inc.;Marketing
TITLE:Imaginary test person
EMAIL;TYPE=work;PREF=1:johnDoe@example.org
TEL;TYPE=cell:tel:+1 781 555 1212
TEL;TYPE=home:tel:+1 202 555 1212
NOTE:John Doe has a long and varied history\, being documented on more poli
ce files than anyone else. Reports of his death are alas numerous.
CATEGORIES:Work,Test group
X-ABUID:5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\:ABPerson
END:VCARD
- To create a vCard like the one above, you would do the following:
import { values, parameters, properties, VCARD } from 'vcard4';
// or if using commonjs
// const { values, parameters, properties, VCARD } = require('vcard4');
// N property
let nameArr = new Array(5);
nameArr[0] = new values.TextType('Doe');
nameArr[1] = new values.TextType('John');
let nPropValue = new values.SpecialValueType(nameArr, 'NProperty');
let nProp = new properties.NProperty([], nPropValue);
// FN property
let fnPropValue = new values.TextType('John Doe');
let fnProp = new properties.FNProperty([], fnPropValue);
// ORG property
let orgArr = [
new values.TextType('Example.com Inc.'),
new values.TextType('Marketing')
];
let orgPropValue = new values.SpecialValueType(orgArr, 'OrgProperty');
let orgProp = new properties.OrgProperty([], orgPropValue);
// Title property
let titlePropValue = new values.TextType('Imaginary test person');
let titleProp = new properties.TitleProperty([], titlePropValue);
// Email property
let emailPropValue = new values.TextType('johnDoe@example.org');
let emailPropTypeParam = new parameters.TypeParameter(
new values.TextType('work'),
'EmailProperty'
);
let emailPropPrefParam = new parameters.PrefParameter(
new values.IntegerType(1)
);
let emailProp = new properties.EmailProperty(
[
emailPropTypeParam,
emailPropPrefParam
],
emailPropValue
);
// Tel properties
let telProp1Value = new values.URIType('tel:+1 781 555 1212');
let telProp1TypeParam = new parameters.TypeParameter(
new values.TextType('cell'),
'TelProperty'
);
let telProp1 = new properties.TelProperty(
[ telProp1TypeParam ],
telProp1Value
);
let telProp2Value = new values.URIType('tel:+1 202 555 1212');
let telProp2TypeParam = new parameters.TypeParameter(
new values.TextType('home'),
'TelProperty'
);
let telProp2 = new properties.TelProperty(
[ telProp2TypeParam ],
telProp2Value
);
// Note property
let notePropValue = new values.TextType('John Doe has a long and varied history, being documented on more police files than anyone else. Reports of his death are alas numerous.');
let noteProp = new properties.NoteProperty([], notePropValue);
// Categories property
let categoriesPropValue = new values.TextListType([
new values.TextType('Work'),
new values.TextType('Test group')
]);
let categoriesProp = new properties.CategoriesProperty([], categoriesPropValue);
// Extended property
let extendedPropValue = new values.TextType('5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE:ABPerson');
let extendedProp = new properties.ExtendedProperty('X-ABUID', [], extendedPropValue);
// Assemble all the properties into a vcard
let vc = new VCARD([
nProp,
fnProp,
orgProp,
titleProp,
emailProp,
telProp1,
telProp2,
noteProp,
categoriesProp,
extendedProp
]);
// calling the following method returns a formatted string with the vcard
vc.repr();
// to see it
console.log(vc.repr());
import { parse } from 'vcard4';
import fs from 'fs';
// or if using commonjs
// const { parse } = require('vcard4');
let vcard = fs.readFileSync('contact.vcf');
let parsedVcard = parse(vcard.toString());
console.log(parsedVcard);
// {
// BEGIN: { parameters: undefined, value: 'VCARD' },
// VERSION: { parameters: undefined, value: '4.0' },
// N: {
// parameters: undefined,
// value: {
// familyNames: 'Stevenson',
// givenNames: 'John',
// additionalNames: [ 'Philip', 'Paul' ],
// honorificPrefixes: 'Dr.',
// honorificSuffixes: [ 'Jr.', 'M.D.', 'A.C.P.' ]
// }
// },
// FN: { parameters: undefined, value: 'John Stevenson' },
// NICKNAME: [
// { parameters: { PREF: '1' }, value: 'Jay' },
// { parameters: undefined, value: [ 'Johnny', 'Stevie', 'Phil' ] },
// { parameters: { TYPE: 'work' }, value: 'Boss' }
// ],
// ORG: { parameters: undefined, value: [ 'Example.com Inc.', 'Marketing' ] },
// TITLE: { parameters: undefined, value: 'Imaginary test person' },
// EMAIL: {
// parameters: [ { TYPE: 'work' }, { PREF: '1' } ],
// value: 'johnDoe@example.org'
// },
// TEL: [
// { parameters: { TYPE: 'cell' }, value: 'tel:+1 781 555 1212' },
// { parameters: { TYPE: 'home' }, value: 'tel:+1 202 555 1212' }
// ],
// NOTE: {
// parameters: undefined,
// value: 'John Doe has a long and varied history\\, being documented on more police files than anyone else. Reports of his death are alas numerous.'
// },
// CATEGORIES: { parameters: undefined, value: [ 'Work', 'Test group' ] },
// ADR: {
// parameters: [
// { GEO: '"geo:12.3457,78.910"' },
// {
// LABEL: '"Mr. John Q. Public, Esq.\\nMail Drop: TNE QB\\n123 Main Street\\nAny Town, CA 91921-1234\\nU.S.A."'
// }
// ],
// value: {
// postOfficeBox: '',
// extendedAddress: '',
// streetAddress: '123 Main Street',
// locality: 'Any Town',
// region: 'CA',
// postalCode: '91921-1234',
// countryName: 'U.S.A.'
// }
// },
// 'X-ABUID': {
// parameters: undefined,
// value: '5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\\:ABPerson'
// },
// END: { parameters: undefined, value: 'VCARD' }
// }
- Introduction
- API overview
- Property Value Data Types
- Property Parameters
- Properties
VCARD
parse
-
This is a vCard JavaScript library that implements RFC 6350 fully
-
That RFC defines the vCard data format for representing and exchanging a variety of information about individuals and other entities (e.g., formatted and structured name and delivery addresses, email address, multiple telephone numbers, photograph, logo, audio clips, etc.)
-
vcard4 may be used for creating or parsing vCards
-
The vCards made or parsed with this library are to be strictly version 4.0 vCards
-
This library may be used in node or in the browser. It supports the latest versions of both out of the box. For use in old browsers or old node versions, you should transpile the code with Babel or any other transpiler of your choice
- NB: vcard4 uses private class fields and methods heavily. This poses a problem for Safari users because Safari does not support private class methods. It is advised to transpile the code using Babel or any other transpiler of your choice
-
vcard4 supports both ES6 module import/export and commonjs require
- vcard4 uses semver for versioning releases
-
vcard4.errors
-
Provides custom errors used by the library
-
The errors include:
-
vcard4.errors.MissingArgument
-
vcard4.errors.InvalidArgument
-
-
-
vcard4.values
- Described here
-
vcard4.parameters
- Described here
-
vcard4.properties
- Described here
-
vcard4.VCARD
- Described here
-
vcard4.parse
- Described here
-
According to the RFC, the standard value data types are:
- text
- text-list
- date
- date-list
- time
- time-list
- date-time
- date-time-list
- date-and-or-time
- date-and-or-time-list
- timestamp
- timestamp-list
- boolean
- integer
- integer-list
- float
- float-list
- URI
- utc-offset
- Language-Tag
- iana-valuespec
-
In the library, these are represented by the following classes:
-
The only accessible method on an instance of one of the classes listed above is
repr
, which returns a string containing the value passed, but formatted as it would be on a vCard. For example,
new TextType('Hello, world!').repr()
//Hello\, world!
- The instance object is frozen and therefore its properties and methods cannot be modified after construction, neither can new ones be added
NB: The actual value type depends on property name and VALUE parameter. For example, the FN
property only accepts text
values.
-
These classes represent the "text" and "text-list" data types respectively
-
TextType
should be called with a single argument of type string.
let greeting = new TextType('Hello, world');
TextListType
should be called with a single argument that is an array ofTextType
s
let person1 = new TextType('Jane');
let person2 = new TextType('John');
let people = new TextListType([ person1, person2 ]);
-
This class represents the "URI" data type
-
URIType
should be called with a single argument of type string, that is formatted as URI as defined in Section 3 of RFC 3986
new URIType('http://www.example.com/my/picture.jpg');
new URIType('ldap://ldap.example.com/cn=babs%20jensen');
-
This class represents the "date", "time", "date-time", "date-and-or-time", "timestamp" and "utc-offset" data types
-
DateTimeType
should be called with two arguments, the first being the value and the second being the target data type. -
Accepted values for the second argument include:
"date"
,"time"
,"datetime"
,"dateandortime"
,"timestamp"
or"utcoffset"
. (Note that it should be of type string) -
The value of the first argument depends on the type specified in the value of the second argument
-
Where
"date"
is the second argument, the value of the first argument should be of the format:
year [month day]
year month day
year "-" month
"--" month [day]
"--" month day
"--" "-" day
where:
year = 4DIGIT ; 0000-9999
month = 2DIGIT ; 01-12
day = 2DIGIT ; 01-28/29/30/31 depending on month and leap year
NB: values surrounded by square brackets ([]) are optional and may be left out
Examples:
19850412
1985-04
1985
--0412
---12
-
Note the use of YYYY-MM in the second example above. YYYYMM is disallowed to prevent confusion with YYMMDD. Note also that YYYY-MM-DD is disallowed.
-
Example for
"date"
:
new DateTimeType('19850412', 'date');
- Where
"time"
is the second argument, the value of the first argument should be of the format:
hour minute second [zone]
hour [minute [second]] [zone]
"-" minute [second] [zone]
"-" "-" second [zone]
where:
hour = 2DIGIT ; 00-23
minute = 2DIGIT ; 00-59
second = 2DIGIT ; 00-58/59/60 depending on leap second
zone = utc-designator / utc-offset
utc-designator = %x5A ; uppercase "Z"
utc-offset = sign hour [minute]
sign = "+" / "-"
Examples:
102200
1022
10
-2200
--00
102200Z
102200-0800
- Example for
"time"
:
new DateTimeType('--00', 'time');
- Where
"datetime"
is the second argument, the value of the first argument should be of the format:
date-noreduc time-designator time-notrunc
where:
date-noreduc = year month day
"--" month day
"--" "-" day
time-designator = %x54 ; uppercase "T"
time-notrunc = hour [minute [second]] [zone]
Examples:
19961022T140000
--1022T1400
---22T14
- Example for
"datetime"
:
new DateTimeType('--1022T1400', 'datetime');
- Where
"dateandortime"
is the second argument, the value of the first argument should be of the format:
datetime / date / time-designator time
where:
datetime = the format specified above under "datetime"
date = the format specified above under "date"
time-designator = %x54 ; uppercase "T"
time = the format specified above under "time"
Examples:
19961022T140000
--1022T1400
---22T14
19850412
1985-04
1985
--0412
---12
T102200
T1022
T10
T-2200
T--00
T102200Z
T102200-0800
- Example for
"dateandortime"
:
new DateTimeType('--1022T1400', 'dateandortime');
- Where
"timestamp"
is the second argument, the value of the first argument should be of the format:
date-complete time-designator time-complete
where:
date-complete = year month day
time-designator = %x54 ; uppercase "T"
time-complete = hour minute second [zone]
Examples:
19961022T140000
19961022T140000Z
19961022T140000-05
19961022T140000-0500
- Example for
"timestamp"
:
new DateTimeType('19961022T140000-0500', 'timestamp');
new DateTimeType('19961022T140000+01', 'timestamp');
- Where
"utcoffset"
is the second argument, the value of the first argument should be of the format:
sign hour [minute]
- Example for
"utcoffset"
:
new DateTimeType('-0500', 'utcoffset');
new DateTimeType('+03', 'utcoffset');
-
This class represents the "date-list", "time-list", "date-time-list", "date-and-or-time-list" and "timestamp-list" data types
-
DateTimeListType
should be called with a single argument that is an array ofDateTimeType
s of the same type
new DateTimeListType([
new DateTimeType('1985-04', 'date'),
new DateTimeType('---12', 'date')
]);
new DateTimeListType([
new DateTimeType('19961022T140000-0500', 'timestamp'),
new DateTimeType('19961022T140000+01', 'timestamp')
]);
- The following will throw an error, since the
DateTimeType
s in the array are not of the same type
new DateTimeListType([
new DateTimeType('---22T14', 'datetime'),
new DateTimeType('---12', 'dateandortime')
]);
// TypeError: Invalid type for value of DateTimeListType. It should be an array of DateTimeTypes of the same type
// at DateTimeListType.#validate (file:///.../vcard4/lib/values.js:213:11)
// at new DateTimeListType (file:///.../vcard4/lib/values.js:226:19)
// at file:///.../vcard4/lib/values.js:592:1
// at ModuleJob.run (node:internal/modules/esm/module_job:183:25)
// at async Loader.import (node:internal/modules/esm/loader:178:24)
// at async Object.loadESM (node:internal/process/esm_loader:68:5)
// at async handleMainPromise (node:internal/modules/run_main:63:12)
-
This class represents the "boolean" data type
-
BooleanType
should be called with a single argument of type boolean
new BooleanType(false);
new BooleanType(true);
-
These classes represent the "integer" and "integer-list" data types respectively
-
IntegerType
should be called with a single argument of type number or bigint. The value may have a sign ("-" or "+")
new IntegerType(1n);
new IntegerType(-30);
new IntegerType(5);
new IntegerType(-45n);
-
The maximum value is
9223372036854775807n
, and the minimum value is-9223372036854775808n
when using bigint values, but when using values of type number, the maximum number isNumber.MAX_SAFE_INTEGER
and the minimum isNumber.MIN_SAFE_INTEGER
-
IntegerListType
should be called with a single argument that is an array ofIntegerType
s
new IntegerListType([
new IntegerType(1),
new IntegerType(4e2),
new IntegerType(33n)
]);
-
These classes represent the "float" and "float-list" data types respectively
-
FloatType
should be called with a single argument of type number or string. The value may have a sign ("-" or "+") -
The value must have a decimal point.
new FloatType('-35.00');
new FloatType(90.234);
FloatListType
should be called with a single argument that is an array ofFloatType
s
new FloatListType([
new FloatType(1.455),
new FloatType(-345),
new FloatType('33.000')
]);
-
This class represents the "language-tag" data type
-
LanguageTagType
should be called with a single argument of type string that is formatted as a language tag as defined in RFC 5646 -
Note that the value submitted will not be checked to make sure it is an actual language tag that conforms to RFC 5646, so ensure that whatever value you pass is a valid language tag
new LanguageTagType('en-us');
-
This class is for use with the
GenderProperty
-
SexType
should be called with a single argument of type string -
The accepted values for the argument include:
M
,F
,O
,N
andU
new SexType('F');
-
This class is for use with properties which do not have values of the types already described. Those properties include:
-
SpecialValueType
should be called with two arguments, both of type string. The first should be the value and the second should be the target property -
The second argument that specifies the target property should have as a value a string with the name of one the eight classes listed above (case insensitive)
-
The value first argument depends on the value of the second argument
-
Where the second argument is either
BeginProperty
orEndProperty
, the only accepted value for the first argument isVCARD
.
new SpecialValueType('VCARD', 'endproperty');
- Where the second argument is
KindProperty
, the only accepted values for the first argument areindividual
,group
,org
,location
or an identifier registered with IANA, e.g.hybridCellSector_AGPS
, "802.11
", e.t.c.
new SpecialValueType('org', 'KindProperty');
-
Where the second argument is
NProperty
, the only accepted value for the first argument is an array of length 5. The items in the array, if present, must be of typeTextType
orTextListType
, otherwise, they must be left empty as demonstrated in the example below -
The 5 items in the array correspond to the following respectively:
- Family Names (also known as surnames)
- Given Names
- Additional Names
- Honorific Prefixes
- Honorific Suffixes
-
Individual text components can include multiple text values (hence the use of
TextListType
). In the example below, the person has multiple honorific prefixes
let nameArr = new Array(5);
nameArr[0] = new TextType('Doe');
nameArr[1] = new TextType('John');
nameArr[3] = new TextListType([
new TextType('Mr.'),
new TextType('Dr.')
]);
new SpecialValueType(nameArr, 'NProperty');
- Where the second argument is
GenderProperty
, the only accepted value for the first argument is an array of length 2. The first item in the array, if present, must be of typeSexType
, while the second, if present, must be of the typeTextType
, otherwise, they must be left empty. Note that only one can be left empty, so if one is left empty, the other must be present
new SpecialValueType(
[
new SexType('O'),
new TextType("intersex")
],
'GenderProperty'
);
-
Where the second argument is
AdrProperty
, the only accepted value for the first argument is an array of length 7. The items in the array, if present, must be of typeTextType
, otherwise, they must be left empty -
The 7 items in the array correspond to the following respectively:
- the post office box
- the extended address (e.g., apartment or suite number)
- the street address
- the locality (e.g., city)
- the region (e.g., state or province)
- the postal code
- the country name (full name)
let adrArr = new Array(7);
adrArr[3] = new TextType('Main street');
new SpecialValueType(adrArr, 'AdrProperty');
- Where the second argument is
OrgProperty
, the only accepted value for the first argument is an array, with at least one item but with no length limit. The items in the array must be of typeTextType
new SpecialValueType(
[
new TextType('Example.com Inc.'),
new TextType('Marketing')
],
'orgproperty'
)
- Where the second argument is
ClientpidmapProperty
, the only accepted value for the first argument is an array of length 2. The first item in the array must be of typeIntegerType
, while the second, must be of the typeURIType
. None of the items can be left empty
new SpecialValueType(
[
new IntegerType(1),
new URIType('uuid:123-asmm-aams')
],
'clientpidmapProperty'
);
-
These "property parameters" contain meta-information about the property or the property value
-
According to the RFC, the property parameters include:
- LANGUAGE
- VALUE
- PREF
- ALTID
- PID
- TYPE
- MEDIATYPE
- CALSCALE
- SORT-AS
- GEO
- TZ
-
In the library, these are represented by:
-
The only accessible method on an instance of one of the classes listed above is
repr
, which returns a string containing the value passed, but formatted as it would be on a vCard. For example,
new LanguageParameter(
new LanguageTagType('en-us')
).repr();
//LANGUAGE=en-us
- The instance object is frozen and therefore its properties and methods cannot be modified after construction, neither can new ones be added
-
This class represents the "LANGUAGE" parameter
-
LanguageParameter
should be called with a single argument of typeLanguageTagType
new LanguageParameter(
new LanguageTagType('tr')
);
-
This class represents the "VALUE" parameter
-
It is used to identify the data type of the value of a property
-
ValueParameter
should be called with a single argument of either one of the following types:TextType
,BooleanType
,DateTimeType
,IntegerType
,FloatType
,LanguageTagType
,URIType
andSpecialValueType
-
Note that the data type specified by the
ValueParameter
must correspond to the value of the property
let propertyValue = new TextType('ahoy');
let vp = new ValueParameter(propertyValue);
//calling repr on vp
vp.repr();
//VALUE=text
-
This class represents the "PREF" parameter
-
PrefParameter
should be called with a single argument of typeIntegerType
, whose value should be between 1 and 100
new PrefParameter(
new IntegerType(1)
);
-
This class represents the "ALTID" parameter
-
AltidParameter
should be called with a single argument of eitherIntegerType
orTextType
new AltidParameter(
new IntegerType(23)
);
new AltidParameter(
new TextType('blah')
);
-
This class represents the "PID" parameter
-
According to the RFC, its value is either a single small positive integer or a pair of small positive integers separated by a dot. Multiple values may be encoded in a single PID parameter by separating the values with a comma ","
-
Therefore,
PIDParameter
should be called with a single argument of either:-
-
If you intend the value to be a single small positive integer
let pid = new PIDParameter( new IntegerType(3) ); // calling repr pid.repr(); // PID=3
-
-
an array of
IntegerType
s-
If you intend to have multiple values encoded in the parameter and separated by a comma
let pid = new PIDParameter([ new IntegerType(3), new IntegerType(7), ]); // calling repr pid.repr(); // PID=3,7
-
-
a nested array of
IntegerType
s-
If you intend to have the value be a pair of small positive integers separated by a dot
let pid = new PIDParameter([ [ new IntegerType(1), new IntegerType(5) ] ]); // calling repr pid.repr(); // PID=1.5
-
-
-
You may also combine all three, as below
let pid = new PIDParameter([
[
new IntegerType(1),
new IntegerType(7),
],
new IntegerType(23),
new IntegerType(24)
]);
// calling repr
pid.repr();
// PID=1.7,23,24
-
This class represents the "TYPE" parameter
-
TypeParameter
should be called with a two arguments, the first being the value and the second being the target property. The value of the first argument depends on the value of the second -
The value of the second argument should be a string with the name of the target property as already mentioned
-
For all target properties, the first argument should be an instance of
TextType
, whose value is either"work"
,"home"
, an identifier registered with IANA or an x-name (names that begin with "x-" or "X-" and are reserved for experimental use, not intended for released products, or for use in bilateral agreements) -
Where the value of the second argument is
"TelProperty"
(case insensitive), the value of the first argument may be"text"
,"voice"
,"fax"
,"cell"
,"video"
,"pager"
or"textphone"
, in addition to the values specified above for all target properties -
Where the value of the second argument is
"RelatedProperty"
(case insensitive), the value of the first argument may be"contact"
,"acquaintance"
,"friend"
,"met"
,"co-worker"
,"colleague"
,"co-resident"
,"neighbor"
,"child"
,"parent"
,"sibling"
,"spouse"
,"kin"
,"muse"
,"crush"
,"date"
,"sweetheart"
,"me"
,"agent"
or"emergency"
, in addition to the values specified above for all target properties -
If you wish to have multiple values for the same TYPE parameter, the value of the first argument may be an instance of
TextListType
, whose values for individualTextType
components are those specified above, according to the rules specified above
new TypeParameter(
new TextType('work'),
'emailproperty'
);
new TypeParameter(
new TextListType([
new TextType('voice'),
new TextType('home')
]),
'telproperty'
);
new TypeParameter(
new TextType('sweetheart'),
'relatedproperty'
);
-
This class represents the "MEDIATYPE" parameter
-
MediatypeParameter
should be called with a single argument that is either aTextType
specifying the media type and subtype, or an array of length 2, whose first item is aTextType
specifying the media type and subtype, and whose second item is also aTextType
specifying the media attribute and values -
The media type and subtype
TextType
value should be of the formattype-name "/" subtype-name
, while the attribute and valueTextType
should be of the formatattribute "=" value
new MediatypeParameter(
new TextType('audio/mp3')
);
new MediatypeParameter([
new TextType('video/jpeg'),
new TextType('someattribute=somevalue')
]);
-
This class represents the "CALSCALE" parameter
-
CalscaleParameter
should be called with a single argument that is an instance ofTextType
, and whose value is eithergregorian
or an x-name (names that begin with "x-" or "X-" and are reserved for experimental use, not intended for released products, or for use in bilateral agreements)
new CalscaleParameter(
new TextType('gregorian')
);
new CalscaleParameter(
new TextType('x-mything')
);
-
This class represents the "SORT-AS" parameter
-
SortAsParameter
should be called with a single argument that is an instance ofTextType
orTextListType
if you wish to specify multiple values, an array of string items
new SortAsParameter(
new TextListType([
new TextType('Harten'),
new TextType('Rene' )
])
);
new SortAsParameter(
new TextType('Pau Shou Chang')
);
-
This class represents the "GEO" parameter
-
GeoParameter
should be called with a single argument of typeURIType
new GeoParameter(
new URIType('geo:37.386013,-122.082932')
);
-
This class represents the "TZ" parameter
-
TzParameter
should be called with a single argument of typeURIType
, orTextType
, orDateTimeType
with the typeutc-offset
new TzParameter(
new TextType('Raleigh/North America')
);
new TzParameter(
new DateTimeType('-0500', 'utcoffset')
);
-
This class is for creating extended parameters
-
AnyParameter
should be called with two arguments of type string. The first argument is the name of the extended parameter, which should be either an identifier registered with IANA or an x-name (names that begin with "x-" or "X-" and are reserved for experimental use, not intended for released products, or for use in bilateral agreements). The second argument is the value
new AnyParameter('X-CAR', 'Volvo');
new AnyParameter('networkTDOA', 'strong');
-
This class represents the "LABEL" parameter for use with the
ADR
property -
It is used to present a delivery address label for the address
-
LabelParameter
should be called with a single argument of type string
let deliveryAddress = `Mr. John Q. Public, Esq.
Mail Drop: TNE QB
123 Main Street
Any Town, CA 91921-1234
U.S.A.`;
new LabelParameter(deliveryAddress);
-
After documenting the property value data types and the property parameters, what follows now is the documentation of the properties themselves
-
According to the RFC, the following are the properties:
-
General Properties
- BEGIN
- END
- SOURCE
- KIND
- XML
-
Identification Properties
- FN
- N
- NICKNAME
- PHOTO
- BDAY
- ANNIVERSARY
- GENDER
-
Delivery Addressing Properties
- ADR
-
Communications Properties
- TEL
- IMPP
- LANG
-
Geographical Properties
- TZ
- GEO
-
Organizational Properties
- TITLE
- ROLE
- LOGO
- ORG
- MEMBER
- RELATED
-
Explanatory Properties
- CATEGORIES
- NOTE
- PRODID
- REV
- SOUND
- UID
- CLIENTPIDMAP
- URL
- VERSION
-
Security Properties
- KEY
-
Calendar Properties
- FBURL
- CALADRURI
- CALURI
-
Extended Properties
-
-
In the library, they are represented by the following classes:
BeginProperty
EndProperty
SourceProperty
KindProperty
XMLProperty
FNProperty
NProperty
NicknameProperty
PhotoProperty
BdayProperty
AnniversaryProperty
GenderProperty
AdrProperty
TelProperty
EmailProperty
IMPPProperty
LangProperty
TzProperty
GeoProperty
TitleProperty
RoleProperty
LogoProperty
OrgProperty
MemberProperty
RelatedProperty
CategoriesProperty
NoteProperty
ProdidProperty
RevProperty
SoundProperty
UIDProperty
ClientpidmapProperty
URLProperty
VersionProperty
KeyProperty
FburlProperty
CaladruriProperty
CaluriProperty
ExtendedProperty
-
The only accessible method on an instance of one of the classes listed above is
repr
, which returns a string containing the value passed, but formatted as it would be on a vCard. For example,
let genderPropValue = new SpecialValueType(
[
new SexType('M'),
new TextType('Male')
],
'GenderProperty'
);
let genderPropValueParam = new ValueParameter(genderPropValue);
new GenderProperty(
[ genderPropValueParam ],
genderPropValue
).repr();
//GENDER;VALUE=text:M;Male
-
The instance object is frozen and therefore its properties and methods cannot be modified after construction, neither can new ones be added
-
All of the classes, with the exception of a few, should generally be called with two arguments, the first being an array whose items are the parameters of the property and the second argument being the property's value. This can be seen in the example above
-
This class represents the "BEGIN" property
-
There should be no need of creating an instance of this class, as it is done automatically
-
BeginProperty
takes no arguments -
It's value is of type
SpecialValueType
new BeginProperty;
-
This class represents the "END" property
-
There should be no need of creating an instance of this class, as it is done automatically
-
EndProperty
takes no arguments -
It's value is of type
SpecialValueType
new EndProperty;
-
This class represents the "SOURCE" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
SourceProperty
areValueParameter
,PIDParameter
,PrefParameter
,AltidParameter
,MediatypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
SourceProperty
should be of typeURIType
new SourceProperty(
[],
new URIType('ldap://ldap.example.com/cn=Babs%20Jensen,%20o=Babsco,%20c=US')
);
-
This class represents the "KIND" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
KindProperty
areValueParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
KindProperty
should be of typeSpecialValueType
new KindProperty(
[],
new SpecialValueType('individual', 'kindproperty')
);
-
This class represents the "XML" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
XMLProperty
areValueParameter
andAltidParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
XMLProperty
should be of typeTextType
let xmlPropValue = `<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>`;
new XMLProperty([], xmlPropValue );
-
This class represents the "FN" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
FNProperty
areValueParameter
,TypeParameter
,LanguageParameter
,AltidParameter
,PIDParameter
,PrefParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
FNProperty
should be of typeTextType
new FNProperty(
[],
new TextType('James Bond')
);
-
This class represents the "N" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
NProperty
areValueParameter
,SortAsParameter
,LanguageParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
NProperty
should be of typeSpecialValueType
let nArr = [
new TextType('Stevenson'),
new TextType('John'),
new TextListType([
new TextType('Phillip'),
new TextType('Paul')
]),
new TextType('Dr.'),
new TextListType([
new TextType('Jr.'),
new TextType('M.D.'),
new TextType('A.C.P.')
])
];
let nPropVal = new SpecialValueType(
nArr,
'nproperty'
);
new NProperty(
[],
nPropVal
);
-
This class represents the "NICKNAME" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
NicknameProperty
areValueParameter
,TypeParameter
,LanguageParameter
,AltidParameter
,PIDParameter
,PrefParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
NicknameProperty
should be of typeTextType
orTextListType
new NicknameProperty(
[],
new TextType('Robbie')
);
new NicknameProperty(
[],
new TextListType([
new TextType('Jim'),
new TextType('Jimmie')
])
);
new NicknameProperty(
[
new TypeParameter(
new TextType('work'),
'nicknameproperty'
)
],
new TextType('Boss')
);
-
This class represents the "PHOTO" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
PhotoProperty
areValueParameter
,AltidParameter
,TypeParameter
,MediatypeParameter
,PrefParameter
,PIDParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
PhotoProperty
should be of typeURIType
new PhotoProperty(
[],
new URIType('data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhvAQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0')
);
new PhotoProperty(
[],
new URIType('http://www.example.com/pub/photos/jqpublic.gif')
);
-
This class represents the "BDAY" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
BdayProperty
areValueParameter
,LanguageParameter
,AltidParameter
,CalscaleParameter
andAnyParameter
-
CalscaleParameter
may only be used when the value is of typeDateTimeType
-
LanguageParameter
may only be used when the value is of typeTextType
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
BdayProperty
should be of typeDateTimeType
of the typedateandortime
orTextType
new BdayProperty(
[],
new DateTimeType('19960415', 'dateandortime')
);
let bday2val = new TextType('circa 1800');
new BdayProperty(
[
new ValueParameter(bday2val)
],
bday2val
);
-
This class represents the "ANNIVERSARY" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
AnniversaryProperty
areValueParameter
,AltidParameter
,CalscaleParameter
andAnyParameter
-
CalscaleParameter
may only be used when the value is of typeDateTimeType
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
AnniversaryProperty
should be of typeDateTimeType
of the typedateandortime
orTextType
new AnniversaryProperty(
[],
new DateTimeType('19960415', 'dateandortime')
);
-
This class represents the "GENDER" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
GenderProperty
areValueParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
GenderProperty
should be of typeSexType
orSpecialValueType
new GenderProperty(
[],
new SexType('M')
);
new GenderProperty(
[],
new SpecialValueType(
[
new SexType('O'),
new TextType('intersex')
],
'genderproperty'
)
);
let gpArr = new Array(2)
gpArr[1] = new TextType("it's complicated")
new GenderProperty(
[],
new SpecialValueType(
gpArr,
'genderproperty'
)
);
-
This class represents the "ADR" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
AdrProperty
areLabelParameter
,ValueParameter
,LanguageParameter
,GeoParameter
,TzParameter
,AltidParameter
,PIDParameter
,PrefParameter
,TypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
AdrProperty
should be of typeSpecialValueType
let addrArr = new Array(7);
addrArr[2] = new TextType('123 Main Street');
addrArr[3] = new TextType('Any Town');
addrArr[4] = new TextType('CA');
addrArr[5] = new TextType('91921-1234');
addrArr[6] = new TextType('U.S.A.');
new AdrProperty(
[
new GeoParameter(
new URIType('geo:12.3457,78.910')
)
],
new SpecialValueType(addrArr, 'AdrProperty')
);
-
This class represents the "TEL" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
TelProperty
areValueParameter
,MediatypeParameter
,TypeParameter
,PIDParameter
,PrefParameter
,AltidParameter
andAnyParameter
-
The
MediatypeParameter
may only be used if the value is of typeURIType
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
TelProperty
should be of typeURIType
orTextType
new TelProperty(
[],
new URIType('tel:+33-01-23-45-67')
);
-
This class represents the "EMAIL" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
EmailProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
EmailProperty
should be of typeTextType
new EmailProperty(
[
new PrefParameter(
new IntegerType(1)
)
],
new TextType('jane_doe@example.com')
);
-
This class represents the "IMPP" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
IMPPProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
IMPPProperty
should be of typeURIType
new IMPPProperty(
[],
new URIType('xmpp:alice@example.com')
);
-
This class represents the "LANG" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
LangProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
LangProperty
should be of typeLanguageTagType
new LangProperty(
[],
new LanguageTagType('fr')
);
-
This class represents the "TZ" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
TzProperty
areValueParameter
,AltidParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
TzProperty
should be of typeTextType
,URIType
orDateTimeType
new TzProperty(
[],
new TextType('Raleigh/North America')
);
new TzProperty(
[],
new DateTimeType('-0500', 'utcoffset')
);
-
This class represents the "GEO" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
GeoProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
GeoProperty
should be of typeURIType
new GeoProperty(
[],
new URIType('geo:37.386013,-122.082932')
);
-
This class represents the "TITLE" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
TitleProperty
areValueParameter
,LanguageParameter
,PIDParameter
,PrefParameter
,AltidParameter
,TypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
TitleProperty
should be of typeTextType
new TitleProperty(
[],
new TextType('Research Scientist')
);
-
This class represents the "ROLE" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
RoleProperty
areValueParameter
,LanguageParameter
,PIDParameter
,PrefParameter
,TypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
RoleProperty
should be of typeTextType
new RoleProperty(
[],
new TextType('Project Leader')
);
-
This class represents the "LOGO" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
LogoProperty
areValueParameter
,LanguageParameter
,PIDParameter
, PrefParameter,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
LogoProperty
should be of typeURIType
new LogoProperty(
[],
new URIType('http://www.example.com/pub/logos/abccorp.jpg')
);
new LogoProperty(
[],
new URIType('data:image/jpeg;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhvcAQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0')
);
-
This class represents the "ORG" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
OrgProperty
areValueParameter
,SortAsParameter
,LanguageParameter
,PIDParameter
,PrefParameter
,AltidParameter
,TypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
OrgProperty
should be of typeSpecialValueType
new OrgProperty(
[],
new SpecialValueType(
[
new TextType('ABC, Inc.'),
new TextType('North American Division'),
new TextType('Marketing')
],
'orgproperty'
)
);
- This class represents the "MEMBER" property
This property should only be used if the value of the "KIND" (
KindProperty
) property is "group"
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
MemberProperty
areValueParameter
,PIDParameter
,PrefParameter
,AltidParameter
,MediatypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
MemberProperty
should be of typeURIType
new MemberProperty(
[],
new URIType('urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af')
);
-
This class represents the "RELATED" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
RelatedProperty
areValueParameter
,LanguageParameter
,MediatypeParameter
,PIDParameter
,PrefParameter
,AltidParameter
,TypeParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
RelatedProperty
should be of typeURIType
orTextType
new RelatedProperty(
[
new TypeParameter(
new TextType('friend'),
'relatedproperty'
)
],
new URIType('uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
);
let relPropVal = new TextType('Please contact my assistant Jane Doe for any inquiries.');
new RelatedProperty(
[
new TypeParameter(
new TextType('co-worker'),
'relatedproperty'
),
new ValueParameter(relPropVal)
],
relPropVal
);
-
This class represents the "CATEGORIES" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
CategoriesProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
CategoriesProperty
should be of typeTextType
orTextListType
new CategoriesProperty(
[],
new TextType('TRAVEL AGENT')
);
new CategoriesProperty(
[],
new TextListType([
new TextType('INTERNET'),
new TextType('IETF'),
new TextType('INDUSTRY')
])
);
-
This class represents the "NOTE" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
NoteProperty
areValueParameter
,LanguageParameter
,PIDParameter
,PrefParameter
,TypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
NoteProperty
should be of typeTextType
new NoteProperty(
[],
new TextType('This fax number is operational 0800 to 1715 EST, Mon-Fri.')
);
-
This class represents the "PRODID" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
ProdidProperty
areValueParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
ProdidProperty
should be of typeTextType
new ProdidProperty(
[],
new TextType('-//ONLINE DIRECTORY//NONSGML Version 1//EN')
);
-
This class represents the "REV" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
RevProperty
areValueParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
RevProperty
should be of typeDateTimeType
of typetimestamp
new RevProperty(
[],
new DateTimeType('19951031T222710Z', 'timestamp')
);
-
This class represents the "SOUND" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
SoundProperty
areValueParameter
,LanguageParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
SoundProperty
should be of typeURIType
new SoundProperty(
[],
new URIType('CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com')
);
new SoundProperty(
[],
new URIType('data:audio/basic;base64,MIICajCCAdOgAwIBAgICBEUwDQYJKoZIhAQEEBQAwdzELMAkGA1UEBhMCVVMxLDAqBgNVBAoTI05ldHNjYXBlIENvbW11bmljYXRpb25zIENvcnBvcmF0aW9uMRwwGgYDVQQLExNJbmZvcm1hdGlvbiBTeXN0')
);
-
This class represents the "UID" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
UIDProperty
areValueParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
UIDProperty
should be of typeURIType
orTextType
new UIDProperty(
[],
new URIType('urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6')
);
-
This class represents the "CLIENTPIDMAP" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameter of
ClientpidmapProperty
isAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
ClientpidmapProperty
should be of typeSpecialValueType
new ClientpidmapProperty(
[],
new SpecialValueType(
[
new IntegerType(1),
new URIType('urn:uuid:3df403f4-5924-4bb7-b077-3c711d9eb34b')
],
'clientpidmapproperty'
)
);
-
This class represents the "URL" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
URLProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
URLProperty
should be of typeURIType
new URLProperty(
[],
new URIType('http://example.org/restaurant.french/chezchic.html')
);
-
This class represents the "VERSION" property
-
There should be no need of creating an instance of this class, as it is done automatically
-
VersionProperty
takes no arguments -
It's value is of type
TextType
new VersionProperty;
-
This class represents the "KEY" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
KeyProperty
areValueParameter
,MediatypeParameter
,AltidParameter
,PIDParameter
,PrefParameter
,TypeParameter
andAnyParameter
-
The
MediatypeParameter
may only be used if the value is of typeURIType
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
KeyProperty
should be of typeURIType
orTextType
new KeyProperty(
[
new MediatypeParameter(
new TextType('application/pgp-keys')
)
],
new URIType('ftp://example.com/keys/jdoe')
);
-
This class represents the "FBURL" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
FburlProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
FburlProperty
should be of typeURIType
new FburlProperty(
[
new MediatypeParameter(
new TextType('text/calendar')
)
],
new URIType('ftp://example.com/busy/project-a.ifb')
);
-
This class represents the "CALADRURI" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
CaladruriProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
CaladruriProperty
should be of typeURIType
new CaladruriProperty(
[],
new URIType('http://example.com/calendar/jdoe')
);
-
This class represents the "CALURI" property
-
This class should be called with two arguments, the first an array of the parameters, and the second the value of the property
-
The only acceptable parameters of
CaluriProperty
areValueParameter
,PIDParameter
,PrefParameter
,TypeParameter
,MediatypeParameter
,AltidParameter
andAnyParameter
-
If you do not wish that the property have any parameters, leave the first argument array empty
-
The value of
CaluriProperty
should be of typeURIType
new CaluriProperty(
[
new MediatypeParameter(
new TextType('text/calendar')
)
],
new URIType('ftp://ftp.example.com/calA.ics')
);
-
This class is for creating extended properties
-
This class should be called with three argument. The first argument, a string, should be the name of the extended parameter and it must be an x-name (names that begin with "x-" or "X-" and are reserved for experimental use, not intended for released products, or for use in bilateral agreements). The second should be an array of the parameters, and the third the value of the property
-
All the afore documented parameters and values are valid
-
If you do not wish that the property have any parameters, leave the second argument array empty
new ExtendedProperty(
'X-CAR',
[],
new TextType('Volvo')
);
-
This class is for assembling all the properties into one vCard object
-
VCARD
should be called with a single argument that is an array whose items are the properties you want on the vCard -
BeginProperty
,VersionProperty
andEndProperty
instances must not be supplied in the array. These will be created automatically -
There must be at least one instance of
FNProperty
supplied -
There must not be more than one instance of the following classes supplied:
AnniversaryProperty
,BdayProperty
,GenderProperty
,KindProperty
,NProperty
,ProdidProperty
,RevProperty
andUIDProperty
-
The only accessible method on an instance of
VCARD
isrepr
, which returns a string containing the properly formatted vCard -
The instance object is frozen and therefore its properties and methods cannot be modified after construction, neither can new ones be added
let vc = new VCARD([
new FNProperty(
[],
new TextType('James Bond')
)
]);
//calling repr, returns a properly formatted vCard
vc.repr();
// BEGIN:VCARD
// VERSION:4.0
// FN:James Bond
// END:VCARD
//
-
This function is for parsing version 4.0 vCards
-
It returns an object containing the parsed vCard
-
parse
should be called with a single argument of type string, that is a properly formatted version 4.0 vCard
-
The keys of the returned object are the names of the properties, e.g. N, ADR, etc.
{ BEGIN: { parameters: undefined, value: 'VCARD' }, VERSION: { parameters: undefined, value: '4.0' }, FN: { parameters: undefined, value: 'Matt Hugh' }, TEL: { parameters: { PREF: '1' }, value: '0129 635043' }, END: { parameters: undefined, value: 'VCARD' } }
-
The top-level values are objects with two keys, the first being
parameters
and the second,value
. The top-level values may also be an array of objects if the vCard contained more than one instance of a given property, e.g. more than one TEL// FN:John Stevenson { ..., FN: { parameters: undefined, value: 'John Stevenson' } ..., } // TEL;TYPE=cell:tel:+1 781 555 1212 // TEL;TYPE=home:tel:+1 202 555 1212 { ..., TEL: [ { parameters: { TYPE: 'cell' }, value: 'tel:+1 781 555 1212' }, { parameters: { TYPE: 'home' }, value: 'tel:+1 202 555 1212' } ] ..., }
-
parameters
may either be an object or an array of objects if the content line contained more than one parameters. The object will have a single key which will be the name of the parameter. The value of the key will be the value of the parameter// TEL;TYPE=home:tel:+1 202 555 1212 { parameters: { TYPE: 'home' }, ..., } // EMAIL;TYPE=work;PREF=1:johnDoe@example.org { parameters: [ { TYPE: 'work' }, { PREF: '1' } ], ... }
-
value
may be either a string or an array of strings, depending on whether the value of the content line was a single value or it was comma/semi-colon delimited. Properties for which this is not followed are mentioned below// ORG:Example.com Inc.;Marketing { ..., value: [ 'Example.com Inc.', 'Marketing' ] } // ORG:ABC { ..., value: 'ABC' }
-
For "N" property, the value is an object with the following keys:
familyNames
givenNames
additionalNames
honorificPrefixes
honorificSuffixes
-
For "ADR" property, the value is an object with the following keys:
postOfficeBox
extendedAddress
streetAddress
locality
region
postalCode
countryName
-
For "GENDER" property, the value is an object with the following keys:
sex
gender
-
-
Note that values of object keys at all levels/depths are of type string. The object keys themselves are obviously strings. So, at all times, at any level/depth, the data types you will be dealing with are either strings, arrays of objects, or objects (whose values of object keys are of type string, or either arrays of objects, or objects...and so on...)
import { parse } from 'vcard4';
import fs from 'fs';
// or if using commonjs
// const { parse } = require('vcard4');
let vcard = fs.readFileSync('contact.vcf');
let parsedVcard = parse(vcard.toString());
console.log(parsedVcard);
// {
// BEGIN: { parameters: undefined, value: 'VCARD' },
// VERSION: { parameters: undefined, value: '4.0' },
// N: {
// parameters: undefined,
// value: {
// familyNames: 'Stevenson',
// givenNames: 'John',
// additionalNames: [ 'Philip', 'Paul' ],
// honorificPrefixes: 'Dr.',
// honorificSuffixes: [ 'Jr.', 'M.D.', 'A.C.P.' ]
// }
// },
// FN: { parameters: undefined, value: 'John Stevenson' },
// NICKNAME: [
// { parameters: { PREF: '1' }, value: 'Jay' },
// { parameters: undefined, value: [ 'Johnny', 'Stevie', 'Phil' ] },
// { parameters: { TYPE: 'work' }, value: 'Boss' }
// ],
// ORG: { parameters: undefined, value: [ 'Example.com Inc.', 'Marketing' ] },
// TITLE: { parameters: undefined, value: 'Imaginary test person' },
// EMAIL: {
// parameters: [ { TYPE: 'work' }, { PREF: '1' } ],
// value: 'johnDoe@example.org'
// },
// TEL: [
// { parameters: { TYPE: 'cell' }, value: 'tel:+1 781 555 1212' },
// { parameters: { TYPE: 'home' }, value: 'tel:+1 202 555 1212' }
// ],
// NOTE: {
// parameters: undefined,
// value: 'John Doe has a long and varied history\\, being documented on more police files than anyone else. Reports of his death are alas numerous.'
// },
// CATEGORIES: { parameters: undefined, value: [ 'Work', 'Test group' ] },
// ADR: {
// parameters: [
// { GEO: '"geo:12.3457,78.910"' },
// {
// LABEL: '"Mr. John Q. Public, Esq.\\nMail Drop: TNE QB\\n123 Main Street\\nAny Town, CA 91921-1234\\nU.S.A."'
// }
// ],
// value: {
// postOfficeBox: '',
// extendedAddress: '',
// streetAddress: '123 Main Street',
// locality: 'Any Town',
// region: 'CA',
// postalCode: '91921-1234',
// countryName: 'U.S.A.'
// }
// },
// 'X-ABUID': {
// parameters: undefined,
// value: '5AD380FD-B2DE-4261-BA99-DE1D1DB52FBE\\:ABPerson'
// },
// END: { parameters: undefined, value: 'VCARD' }
// }