@vcard/vcard4-generator v0.1.0-beta.1
@vcard/vcard4-generator
A library for generating v4 vCards
Heads Up!
This is still very much a WIP project and is not feature complete.
Install
npm install @vcard/vcard4-generator
Usage
import Vcard4Generator, { Vcard4GeneratorConfig } from '@vcard/vcard4-generator';
const config: Vcard4GeneratorConfig = {
fn: 'Captain Awesome',
email: 'hello@example.com',
url: 'http://www.example.com/'
};
const vcard = new Vcard4Generator(config);
vcard.toString();
// >> BEGIN:VCARD
// >> VERSION:4.0
// >> EMAIL:hello@example.com
// >> FN:Captain Awesome
// >> URL:http://www.example.com/
// >> END:VCARD
Building
From the monorepo root:
npx lerna --scope @vcard/vcard4-generator run build
Testing
From the monorepo root:
npm test
To-Do
- Properties
ADR
- Line Folding
- Value Escaping
VALUE
ParameterLABEL
ParameterLANGUAGE
ParameterGEO
ParameterTZ
ParameterALTID
ParameterPID
ParameterPREF
ParameterTYPE
Parameter
ANNIVERSARY
- Line Folding
- Value Escaping
VALUE
ParameterALTID
ParameterCALSCALE
Parameter (fordate-and-or-time
type only)
BDAY
- Line Folding
- Value Escaping
VALUE
ParameterALTID
ParameterCALSCALE
Parameter (fordate-and-or-time
type only)LANGUAGE
Parameter (fortext
type only)
BEGIN
- No Parameters
BIRTHPLACE
(RFC6474)- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
Parameter
CALADRURI
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
CALURI
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
CATEGORIES
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterALTID
Parameter- Implement Constructor
Array
Argument Support
CLIENTPIDMAP
- Line Folding
- Value Escaping
- No Parameters
- No
VALUE
Parameter - Implement Constructor
Array
Argument Support
CONTACT-URI
(RFC8605)- Line Folding
- Value Escaping
VALUE
ParameterPREF
Parameter
DEATHDATE
(RFC6474)- Line Folding
- Value Escaping
VALUE
ParameterCALSCALE
Parameter (fordate-and-or-time
type only)LANGUAGE
Parameter (fortext
type only)ALTID
Parameter
DEATHPLACE
(RFC6474)- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterALTID
Parameter
EMAIL
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterALTID
Parameter
END
- No Parameters
EXPERTISE
(RFC6715)- Line Folding
- Value Escaping
LEVEL
ParameterINDEX
ParameterLANGUAGE
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
FBURL
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterALTID
Parameter
FN
- Line Folding
- Value Escaping
VALUE
ParameterTYPE
ParameterLANGUAGE
ParameterALTID
ParameterPID
ParameterPREF
Parameter
GENDER
- Line Folding
- Value Escaping
VALUE
Parameter- Implement Constructor
Array
Argument Support
GEO
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
HOBBY
(RFC6715)- Line Folding
- Value Escaping
LEVEL
ParameterINDEX
ParameterLANGUAGE
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
IMPP
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
INTEREST
(RFC6715)- Line Folding
- Value Escaping
LEVEL
ParameterINDEX
ParameterLANGUAGE
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
KEY
- Line Folding
- Value Escaping
VALUE
ParameterMEDIATYPE
Parameter (forURI
type only)ALTID
ParameterPID
ParameterPREF
ParameterTYPE
Parameter
KIND
- Line Folding
- Value Escaping
VALUE
Parameter
LANG
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
LOGO
- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
MEMBER
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterALTID
ParameterMEDIATYPE
Parameter
N
- Line Folding
- Value Escaping
VALUE
ParameterSORT-AS
ParameterLANGUAGE
ParameterALTID
Parameter
NICKNAME
- Line Folding
- Value Escaping
VALUE
ParameterTYPE
ParameterLANGUAGE
ParameterALTID
ParameterPID
ParameterPREF
Parameter
NOTE
- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterALTID
Parameter
ORG
- Line Folding
- Value Escaping
VALUE
ParameterSORT-AS
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
ORG-DIRECTORY
(RFC6715)- Line Folding
- Value Escaping
INDEX
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
PHOTO
- Line Folding
- Value Escaping
VALUE
ParameterALTID
ParameterTYPE
ParameterMEDIATYPE
ParameterPREF
ParameterPID
Parameter
PRODID
- Line Folding
- Value Escaping
VALUE
Parameter
RELATED
- Line Folding
- Value Escaping
VALUE
ParameterMEDIATYPE
Parameter (forURI
type only)LANGUAGE
Parameter (fortext
type only)PID
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
REV
- Line Folding
- Value Escaping
VALUE
Parameter
ROLE
- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterALTID
Parameter
SOUND
- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
SOURCE
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterALTID
ParameterMEDIATYPE
Parameter
TEL
- Line Folding
- Value Escaping
VALUE
ParameterMEDIATYPE
Parameter (forURI
type only)TYPE
ParameterPID
ParameterPREF
ParameterALTID
Parameter
TITLE
- Line Folding
- Value Escaping
VALUE
ParameterLANGUAGE
ParameterPID
ParameterPREF
ParameterALTID
ParameterTYPE
Parameter
TZ
- Line Folding
- Value Escaping
VALUE
ParameterALTID
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
Parameter
UID
- Line Folding
- Value Escaping
VALUE
Parameter
URL
- Line Folding
- Value Escaping
VALUE
ParameterPID
ParameterPREF
ParameterTYPE
ParameterMEDIATYPE
ParameterALTID
Parameter
VERSION
- No Parameters
XML
- Line Folding
- Value Escaping
VALUE
ParameterALTID
Parameter
- Implement Parameter Value Encoding as Specified in RFC6868
Reference
Property Cardinalities
Property cardinalities are indicated using the following notation, which is based on ABNF (see RFC5234, Section 3.6):
Cardinality | Meaning |
---|---|
1 | Exactly one instance per vCard MUST be present. |
*1 | Exactly one instance per vCard MAY be present. |
1* | One or more instances per vCard MUST be present. |
* | One or more instances per vCard MAY be present. |
Properties defined in a vCard instance may have multiple values depending on the property cardinality. The general rule for encoding multi-valued properties is to simply create a new content line for each value (including the property name). However, it should be noted that some value types support encoding multiple values in a single content line by separating the values with a comma ",". This approach has been taken for several of the content types defined below (date, time, integer, float).
Property Parameters
A property can have attributes associated with it. These "property parameters" contain meta-information about the property or the property value. In some cases, the property parameter can be multi- valued in which case the property parameter value elements are separated by a COMMA (U+002C).
Property parameter value elements that contain the COLON (U+003A), SEMICOLON (U+003B), or COMMA (U+002C) character separators MUST be specified as quoted-string text values. Property parameter values MUST NOT contain the DQUOTE (U+0022) character. The DQUOTE character is used as a delimiter for parameter values that contain restricted characters or URI text.
Applications MUST ignore x-param and iana-param values they don't recognize.
Property Value Escaping
Some properties may contain one or more values delimited by a COMMA character (U+002C). Therefore, a COMMA character in a value MUST be escaped with a BACKSLASH character (U+005C), even for properties that don't allow multiple instances (for consistency).
Some properties (e.g., N and ADR) comprise multiple fields delimited by a SEMICOLON character (U+003B). Therefore, a SEMICOLON in a field of such a "compound" property MUST be escaped with a BACKSLASH character. SEMICOLON characters in non-compound properties MAY be escaped. On input, an escaped SEMICOLON character is never a field separator. An unescaped SEMICOLON character may be a field separator, depending on the property in which it appears.
Furthermore, some fields of compound properties may contain a list of values delimited by a COMMA character. Therefore, a COMMA character in one of a field's values MUST be escaped with a BACKSLASH character, even for fields that don't allow multiple values (for consistency). Compound properties allowing multiple instances MUST NOT be encoded in a single content line.
Finally, BACKSLASH characters in values MUST be escaped with a BACKSLASH character. NEWLINE (U+000A) characters in values MUST be encoded by two characters: a BACKSLASH followed by either an 'n' (U+006E) or an 'N' (U+004E).
In all other cases, escaping MUST NOT be used.
Links
- vCard Format Specification
- vCard KIND:application
- vCard Format Extensions: Place of Birth, Place and Date of Death
- vCard Format Extensions: Representing vCard Extensions Defined by the Open Mobile Alliance (OMA) Converged Address Book (CAB) Group
- Additional Data Related to an Emergency Call § vCard Parameter Value Registration
- vCard Format Extensions: ICANN Extensions for the Registration Data Access Protocol (RDAP)
- vCard Elements (IANA Protocol Registry)
License
The MIT License (Expat). See the license file for details.
2 years ago