Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,27 @@ vCard.email = [
'e.nesser@emailhost3.tld'
];

//multiple custom labelled email entry
vCard.customEmails = [
['type' => 'Friend', 'email' => 'e.nesser@emailhost.tld'],
['type' => 'Father', 'email' => 'e.nesser@emailhost2.tld'],
['type' => 'Mother', 'email' => 'e.nesser@emailhost3.tld']
];

//multiple cellphone
vCard.cellPhone = [
'312-555-1414',
'312-555-1415',
'312-555-1416'
];

//multiple custom labelled phone entry
vCard.customPhones = [
['type' => 'Friend', 'phone' => '312-555-1417'],
['type' => 'Father', 'phone' => '312-555-1418'],
['type' => 'Mother', 'phone' => '312-555-1419']
];

```

### Apple AddressBook Extensions
Expand Down
108 changes: 108 additions & 0 deletions lib/vCardFormatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,66 @@
);
}

if (vCard.customEmails) {
if(!Array.isArray(vCard.customEmails)){
formattedVCardString += '';
}
vCard.customEmails.forEach(
function(customEmails) {
if(!Array.isArray(customEmails)){
formattedVCardString += '';
} else {
customEmails.forEach(function(customEmail) {
let customType = '';
let customEmailVal = e(customEmail.email);
if(!customEmail.type) {
formattedVCardString += '';
} else {
if (majorVersion >= 4) {
customType = 'type='+e(customEmail.type);
} else if (majorVersion >= 3 && majorVersion < 4) {
customType = 'type='+e(customEmail.type);
} else {
customType = e(customEmail.type)+',INTERNET';
}
formattedVCardString += 'EMAIL' + encodingPrefix + ';' + customType + ':' + customEmailVal + nl();
}
});
}
}
);
}

if (vCard.customAddresses) {
if(!Array.isArray(vCard.customAddresses)){
formattedVCardString += '';
}
vCard.customAddresses.forEach(
function(customAddresses) {
if(!Array.isArray(customAddresses)){
formattedVCardString += '';
} else {
customAddresses.forEach(function(customAddress) {
let customType = e(customAddress.type ?? 'HOME');
const customTypeVal = customType.toString().toLocaleUpperCase();
if(!customAddress.type) {
formattedVCardString += '';
} else {
[{
details: customAddress.address,
type: customTypeVal
}].forEach(
function(customAddress) {
formattedVCardString += getFormattedAddress(encodingPrefix, customAddress);
}
);
}
});
}
}
);
}

if (vCard.logo.url) {
formattedVCardString += getFormattedPhoto('LOGO', vCard.logo.url, vCard.logo.mediaType, vCard.logo.base64);
}
Expand Down Expand Up @@ -256,6 +316,30 @@
);
}

if (vCard.customPhones) {
if(!Array.isArray(vCard.customPhones)){
formattedVCardString += '';
}
vCard.customPhones.forEach(
function(customPhones) {
if(!Array.isArray(customPhones)){
formattedVCardString += '';
} else {
customPhones.forEach(function(customPhone) {
let customType = '';
let customPhoneVal = e(customPhone.phone);
if(!customPhone.type) {
formattedVCardString += '';
} else {
customType = 'TYPE=' + e(customPhone.type);
formattedVCardString += 'TEL;' + customType + ':' + customPhoneVal + nl();
}
});
}
}
);
}

if (vCard.homePhone) {
if(!Array.isArray(vCard.homePhone)){
vCard.homePhone = [vCard.homePhone];
Expand Down Expand Up @@ -363,6 +447,30 @@
formattedVCardString += 'URL' + encodingPrefix + ':' + e(vCard.url) + nl();
}

if (vCard.customUrls) {
if(!Array.isArray(vCard.customUrls)){
formattedVCardString += '';
}
vCard.customUrls.forEach(
function(customUrls) {
if(!Array.isArray(customUrls)){
formattedVCardString += '';
} else {
customUrls.forEach(function(customUrl) {
let customType = '';
let customWebVal = e(customUrl.web);
if(!customUrl.type) {
formattedVCardString += '';
} else {
customType = 'TYPE=' + e(customUrl.type);
formattedVCardString += 'URL;' + customType + encodingPrefix + ':' + customWebVal + nl();
}
});
}
}
);
}

if (vCard.workUrl) {
formattedVCardString += 'URL;type=WORK' + encodingPrefix + ':' + e(vCard.workUrl) + nl();
}
Expand Down
Loading