vCards JS
Create vCards to import contacts into Outlook, iOS, Mac OS, and Android devices from your website or application.
Install
npm install vcards-js --save
Usage
Below is a simple example of how to create a basic vCard and how to save it to a file, or view its contents from the console.
Basic vCard
var vCardsJS = ; //create a new vCardvar vCard = ; //set propertiesvCardfirstName = 'Eric';vCardmiddleName = 'J';vCardlastName = 'Nesser';vCardorganization = 'ACME Corporation';vCardphoto;vCardworkPhone = '312-555-1212';vCardbirthday = 1985 0 1;vCardtitle = 'Software Developer';vCardurl = 'https://github.com/enesser';vCardnote = 'Notes on Eric'; //save to filevCard; //get as formatted stringconsole;
On the Web
You can use vCards JS on your website. Below is an example of how to get it working on Express 4.
var express = ;var router = express; module { app;}; router;
Embedding Images
You can embed images in the photo or logo field instead of linking to them from a URL using base64 encoding.
//can be Windows or Linux/Unix path structures, and JPEG, PNG, GIF formatsvCardphoto;vCardlogo;
//can also embed images via base-64 encoded stringsvCardphoto;vCardlogo;
Date Reference
MDN reference on how to use the Date
object for birthday and anniversary can be found at https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date.
Complete Example
The following shows a vCard with everything filled out.
var vCardJS = ; //create a new vCardvar vCard = ; //set basic properties shown beforevCardfirstName = 'Eric';vCardmiddleName = 'J';vCardlastName = 'Nesser';vCarduid = '69531f4a-c34d-4a1e-8922-bd38a9476a53';vCardorganization = 'ACME Corporation'; //link to imagevCardphoto; //or embed imagevCardphoto; vCardworkPhone = '312-555-1212';vCardbirthday = 1985 0 1;vCardtitle = 'Software Developer';vCardurl = 'https://github.com/enesser';vCardworkUrl = 'https://acme-corporation/enesser';vCardnote = 'Notes on Eric'; //set other vitalsvCardnickname = 'Scarface';vCardnamePrefix = 'Mr.';vCardnameSuffix = 'JR';vCardgender = 'M';vCardanniversary = 2004 0 1;vCardrole = 'Software Development'; //set other phone numbersvCardhomePhone = '312-555-1313';vCardcellPhone = '312-555-1414';vCardpagerPhone = '312-555-1515'; //set fax/facsimile numbersvCardhomeFax = '312-555-1616';vCardworkFax = '312-555-1717'; //set email addressesvCardemail = 'e.nesser@emailhost.tld';vCardworkEmail = 'e.nesser@acme-corporation.tld'; //set logo of organization or personal logo (also supports embedding, see above)vCardlogo; //set URL where the vCard can be foundvCardsource = 'http://mywebpage/myvcard.vcf'; //set address informationvCardhomeAddresslabel = 'Home Address';vCardhomeAddressstreet = '123 Main Street';vCardhomeAddresscity = 'Chicago';vCardhomeAddressstateProvince = 'IL';vCardhomeAddresspostalCode = '12345';vCardhomeAddresscountryRegion = 'United States of America'; vCardworkAddresslabel = 'Work Address';vCardworkAddressstreet = '123 Corporate Loop\nSuite 500';vCardworkAddresscity = 'Los Angeles';vCardworkAddressstateProvince = 'CA';vCardworkAddresspostalCode = '54321';vCardworkAddresscountryRegion = 'United States of America'; //set social media URLsvCardsocialUrls'facebook' = 'https://...';vCardsocialUrls'linkedIn' = 'https://...';vCardsocialUrls'twitter' = 'https://...';vCardsocialUrls'flickr' = 'https://...';vCardsocialUrls'custom' = 'https://...'; //you can also embed photos from files instead of attaching via URLvCardphoto;vCardlogo; vCardversion = '3.0'; //can also support 2.1 and 4.0, certain versions only support certain fields //save to filevCard; //get as formatted stringconsole;
Multiple Email, Fax, & Phone Examples
email
, otherEmail
, cellPhone
, pagerPhone
, homePhone
, workPhone
, homeFax
, workFax
, otherPhone
all support multiple entries in an array format.
Examples are provided below:
var vCardsJS = ; //create a new vCardvar vCard = ; //multiple email entryvCardemail = 'e.nesser@emailhost.tld' 'e.nesser@emailhost2.tld' 'e.nesser@emailhost3.tld'; //multiple cellphonevCardcellPhone = '312-555-1414' '312-555-1415' '312-555-1416';
Apple AddressBook Extensions
You can mark as a contact as an organization with the following Apple AddressBook extension property:
var vCardsJS = ; var vCard = ; vCardisOrganization = true;
React Native
A React Native version exists here at this repository -- https://github.com/idxbroker/vCards-js/tree/react-native
Testing
You can run the vCard unit tests via npm
:
npm test
Contributions
Contributions are always welcome!
Additional thanks to --
- Tobias Müller (https://github.com/webdepp)
- Julian Krenge (https://github.com/jkrenge)
- Charlie Hulcher (https://github.com/c-h-)
- Jimmy Tsao (https://github.com/jimmytsao)
- Michael Polino (https://github.com/mplno)
- Randy Stevens (https://github.com/RandyStevens)
Donations
BTC 18N1g2o1b9u2jNPbSpGHhV6x5xs6Qou3EV
License
Copyright (c) 2014-2019 Eric J Nesser MIT