vCards JS for use with React Native
React Native vCards -Updated for newer versions of react-native-fs. Now listed as a peerDependency.
Create vCards to import contacts into Outlook, iOS, Mac OS, and Android devices from your website or application.
Install
Note that this package requires react-native-fs for saving files. If you have installed rnpm, the easy way to install react-native-fs is the following:
npm install react-native-fs && rnpm link react-native-fs
Then to install this package, run the following:
npm install react-native-vcards@https://github.com/idxbroker/react-native-vcards.git --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
; //create a new vCardcontact = ; //set propertiescontactfirstName = 'Eric';contactmiddleName = 'J';contactlastName = 'Nesser';contactorganization = 'ACME Corporation';contactphoto;contactworkPhone = '312-555-1212';contactbirthday = '01-01-1985';contacttitle = 'Software Developer';contacturl = 'https://github.com/enesser';contactnote = 'Notes on Eric'; //save to filecontact; //get as formatted stringconsole;
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 formatscontactphoto;contactlogo;
Complete Example
The following shows a vCard with everything filled out.
; //create a new vCardcontact = ; //set basic properties shown beforecontactfirstName = 'Eric';contactmiddleName = 'J';contactlastName = 'Nesser';contactorganization = 'ACME Corporation'; //link to imagecontactphoto; //or embed imagecontactphoto; contactworkPhone = '312-555-1212';contactbirthday = '01-01-1985';contacttitle = 'Software Developer';contacturl = 'https://github.com/enesser';contactworkUrl = 'https://acme-corporation/enesser';contactnote = 'Notes on Eric'; //set other vitalscontactnickname = 'Scarface';contactnamePrefix = 'Mr.';contactnameSuffix = 'JR';contactgender = 'M';contactanniversary = '01-01-2004';contactrole = 'Software Development'; //set other phone numberscontacthomePhone = '312-555-1313';contactcellPhone = '312-555-1414';contactpagerPhone = '312-555-1515'; // set fax/ facsimile numberscontacthomeFax = '312-555-1616';contactworkFax = '312-555-1717'; // set email addressescontactemail = 'e.nesser@emailhost.tld';contactworkEmail = 'e.nesser@acme-corporation.tld'; //set logo of organization or personal logo (also supports embedding, see above)contactlogo; //set URL where the vCard can be foundcontactsource = 'http://mywebpage/myvcard.vcf'; //set address informationcontacthomeAddresslabel = 'Home Address';contacthomeAddressstreet = '123 Main Street';contacthomeAddresscity = 'Chicago';contacthomeAddressstateProvince = 'IL';contacthomeAddresspostalCode = '12345';contacthomeAddresscountryRegion = 'United States of America'; contactworkAddresslabel = 'Work Address';contactworkAddressstreet = '123 Corporate Loop\nSuite 500';contactworkAddresscity = 'Los Angeles';contactworkAddressstateProvince = 'CA';contactworkAddresspostalCode = '54321';contactworkAddresscountryRegion = 'United States of America'; //set social media URLscontactsocialUrls'facebook' = 'https://...';contactsocialUrls'linkedIn' = 'https://...';contactsocialUrls'twitter' = 'https://...';contactsocialUrls'flickr' = 'https://...';contactsocialUrls'custom' = 'https://...'; //you can also embed photos from files instead of attaching via URLcontactphoto;contactlogo; contactversion = '3.0'; //can also support 2.1 and 4.0, certain versions only support certain fields //save to fileconst documentPath = rnfsDocumentDirectoryPath;contact; //get as formatted stringconsole;
Contributions
Contributions are always welcome!
Thanks to mplno, lop-cz, jkrenge.
License
Copyright (c) 2014-2015 Eric J Nesser MIT