vcard API reference
Build and parse vCard (RFC 6350, vCard 4.0): a Card of contact fields encoded to a VCARD and parsed back. The contacts counterpart to ical - it shares the same content-line codec (TEXT escaping, 75-char line folding) through the included ical_vcard_shared.inc.j. Pure Jennifer over strings / lists; both binaries.
A Card carries a formatted name (FN), a full structured name (N: family / given / additional / prefixes / suffixes), a nickname, organisation / title, any number of emails / phones / addresses (each with an optional TYPE like work / home), a birthday, a photo URI, categories, a URL, and a note. encode writes FN and VERSION:4.0 and omits empty fields; parse reads one or many vCard 2.1 / 3.0 / 4.0 VCARDs, including the TYPE parameter on emails / phones / addresses, and throws a VcardError for malformed input. Text values are escaped / unescaped and long lines folded, so parse(encode(card)) round-trips.
Import with import "vcard.j" as vcard;. See the vcard guide for prose and examples.
Contents
| Name | What it is |
|---|---|
addAddress | A copy of the card with a postal address appended. |
addCategory | A copy of the card with a category (CATEGORIES tag) appended. |
addEmail | A copy of the card with an email appended. |
addEmailTyped | A copy of the card with a TYPEd email appended (e.g. |
addPhone | A copy of the card with a phone number appended. |
addPhoneTyped | A copy of the card with a TYPEd phone number appended (e.g. |
address | A postal address. |
addressTyped | A postal address with a TYPE (e.g. |
card | A card with just its formatted name (FN). |
encode | Render a single card to vCard 4.0 text (a VCARD, CRLF-terminated). |
encodeAll | Render many cards to one vCard text (concatenated VCARDs). |
parse | Parse vCard text into a list of Cards (one entry per VCARD). |
withBday | A copy of the card with its birthday (BDAY) set. |
withFullName | A copy of the card with its full structured name (N) set: family, given, additional (middle) name(s), and... |
withName | A copy of the card with its structured name (N family / given) set. |
withNickname | A copy of the card with its nickname (NICKNAME) set. |
withNote | A copy of the card with its note set. |
withOrg | A copy of the card with its organisation and title set. |
withPhoto | A copy of the card with its photo (PHOTO) URI set. |
withUrl | A copy of the card with its URL set. |
Address | struct: A postal address (ADR). |
Card | struct: A contact card. |
Typed | struct: A value with an optional TYPE parameter (e.g. |
VcardError | struct: Malformed vCard text. |
Functions
addAddress
vcard.addAddress(c as Card, a as Address)A copy of the card with a postal address appended.
c- the card
a- the address
- Returns
Card - a fresh card with the address added
addCategory
vcard.addCategory(c as Card, category as string)A copy of the card with a category (CATEGORIES tag) appended.
c- the card
category- the category tag
- Returns
Card - a fresh card with the category added
addEmail
vcard.addEmail(c as Card, email as string)A copy of the card with an email appended.
c- the card
email- the email address
- Returns
Card - a fresh card with the email added
addEmailTyped
vcard.addEmailTyped(c as Card, email as string, type as string)A copy of the card with a TYPEd email appended (e.g. type "work" / "home").
c- the card
email- the email address
type- the
TYPE(e.g. "work" / "home"; "" for none) - Returns
Card - a fresh card with the email added
addPhone
vcard.addPhone(c as Card, phone as string)A copy of the card with a phone number appended.
c- the card
phone- the phone number
- Returns
Card - a fresh card with the phone added
addPhoneTyped
vcard.addPhoneTyped(c as Card, phone as string, type as string)A copy of the card with a TYPEd phone number appended (e.g. type "cell").
c- the card
phone- the phone number
type- the
TYPE(e.g. "work" / "home" / "cell"; "" for none) - Returns
Card - a fresh card with the phone added
address
vcard.address(
street as string,
locality as string,
region as string,
postalCode as string,
country as string)A postal address.
street- the street address
locality- the city / locality
region- the state / province / region
postalCode- the postal / ZIP code
country- the country name
- Returns
Address - the address
addressTyped
vcard.addressTyped(
street as string,
locality as string,
region as string,
postalCode as string,
country as string,
type as string)A postal address with a TYPE (e.g. "work" / "home").
street- the street address
locality- the city / locality
region- the state / province / region
postalCode- the postal / ZIP code
country- the country name
type- the
TYPE("work" / "home"; "" for none) - Returns
Address - the address
card
vcard.card(formattedName as string)A card with just its formatted name (FN). Other fields are empty until set.
formattedName- the display name
- Returns
Card - the card
encode
vcard.encode(c as Card)Render a single card to vCard 4.0 text (a VCARD, CRLF-terminated). Empty optional fields are omitted.
c- the card to encode
- Returns
string - the vCard text
encodeAll
vcard.encodeAll(cards as list of Card)Render many cards to one vCard text (concatenated VCARDs).
cards- the cards to encode
- Returns
string - the vCard text
parse
vcard.parse(text as string)Parse vCard text into a list of Cards (one entry per VCARD). Accepts vCard 2.1, 3.0 and 4.0: unfolds folded lines, strips property group prefixes (item1.EMAIL reads as EMAIL), decodes 2.1 quoted-printable values (with their CHARSET), reads the TYPE parameter on EMAIL / TEL / ADR into Typed.type (other ;KEY=VALUE parameters are ignored), reads the structured N / ADR values, and unescapes text values.
text- the vCard text
- Returns
list of Card - the parsed cards (empty when the text is blank)
- Throws
VcardError - kind "vcard" for malformed input: text outside a
BEGIN:VCARD...END:VCARD, a card withoutEND:VCARD, a nestedBEGIN, a line without a:, an unknownVERSION, a 3.0 / 4.0 card withoutFN, or a bad quoted-printable value
withBday
vcard.withBday(c as Card, bday as string)A copy of the card with its birthday (BDAY) set. The value is stored verbatim (a YYYYMMDD date, or a partial date like --0315).
c- the card
bday- the birthday value
- Returns
Card - a fresh card with the birthday set
withFullName
vcard.withFullName(
c as Card,
family as string,
given as string,
additional as string,
prefixes as string,
suffixes as string)A copy of the card with its full structured name (N) set: family, given, additional (middle) name(s), and honorific prefixes / suffixes.
c- the card
family- the family (last) name
given- the given (first) name
additional- the additional (middle) name(s)
prefixes- the honorific prefixes (e.g. "Dr.")
suffixes- the honorific suffixes (e.g. "Jr.", "PhD")
- Returns
Card - a fresh card with the full name set
withName
vcard.withName(c as Card, family as string, given as string)A copy of the card with its structured name (N family / given) set. The additional (middle) name and honorific prefixes / suffixes are left empty; use withFullName to set all five components.
c- the card
family- the family (last) name
given- the given (first) name
- Returns
Card - a fresh card with the name set
withNickname
vcard.withNickname(c as Card, nickname as string)A copy of the card with its nickname (NICKNAME) set.
c- the card
nickname- the nickname
- Returns
Card - a fresh card with the nickname set
withNote
vcard.withNote(c as Card, note as string)A copy of the card with its note set.
c- the card
note- the note text
- Returns
Card - a fresh card with the note set
withOrg
vcard.withOrg(c as Card, organization as string, title as string)A copy of the card with its organisation and title set.
c- the card
organization- the organisation name
title- the job title
- Returns
Card - a fresh card with the org / title set
withPhoto
vcard.withPhoto(c as Card, photo as string)A copy of the card with its photo (PHOTO) URI set.
c- the card
photo- the photo URI
- Returns
Card - a fresh card with the photo set
withUrl
vcard.withUrl(c as Card, url as string)A copy of the card with its URL set.
c- the card
url- the URL
- Returns
Card - a fresh card with the URL set
Structs
Address
A postal address (ADR). The RFC's PO-box and extended components are not modelled; the five common fields are, plus an optional TYPE.
def struct Address {
street as string,
locality as string,
region as string,
postalCode as string,
country as string,
type as string
};street- the street address
locality- the city / locality
region- the state / province / region
postalCode- the postal / ZIP code
country- the country name
type- the
TYPEparameter ("work" / "home" / ...; "" if none)
Card
A contact card.
def struct Card {
formattedName as string,
family as string,
given as string,
additional as string,
prefixes as string,
suffixes as string,
nickname as string,
organization as string,
title as string,
emails as list of Typed,
phones as list of Typed,
addresses as list of Address,
url as string,
bday as string,
photo as string,
categories as list of string,
note as string
};formattedName- the
FNdisplay name (required by vCard 4.0) family- the
Nfamily (last) name given- the
Ngiven (first) name additional- the
Nadditional (middle) name(s) prefixes- the
Nhonorific prefixes (e.g. "Dr.") suffixes- the
Nhonorific suffixes (e.g. "Jr.", "PhD") nickname- the
NICKNAME("" when unset) organization- the
ORGorganisation ("" when unset) title- the
TITLEjob title ("" when unset) emails- the
EMAILaddresses (each with an optional TYPE) phones- the
TELphone numbers (each with an optional TYPE) addresses- the
ADRpostal addresses url- the
URL("" when unset) bday- the
BDAYbirthday ("" when unset; aYYYYMMDDor partial date) photo- the
PHOTOURI ("" when unset) categories- the
CATEGORIEStags note- the
NOTEfree-text note ("" when unset)
Typed
A value with an optional TYPE parameter (e.g. an email or phone marked work / home). type is "" when unspecified.
def struct Typed {
value as string,
type as string
};value- the property value (the email / phone number)
type- the
TYPEparameter ("work" / "home" / "cell" / ...; "" if none)
VcardError
Malformed vCard text. Every error of kind "vcard" is one, so its fields are safe to read once the kind matches.
def struct VcardError {
kind as string,
message as string,
line as int
};kind- always
"vcard" message- what is wrong, prefixed
line N: line- the 1-based physical line of
parse's input the fault is on (a folded line counts from its first physical line)