@@ -11,8 +11,7 @@ It outputs the vCard text that should be saved as a `*.vcf` file.
1111
1212## Origin
1313
14- This is based on _ jeroendesloovere_ 's
15- [ vCard] ( https://github.com/jeroendesloovere/vcard ) for PHP.
14+ This is based on _ jeroendesloovere_ 's [ vCard] [ jeroendesloovere ] for PHP.
1615
1716## Installation
1817
@@ -28,15 +27,15 @@ npm install vcard-creator
2827
2928### As an ESM module (web)
3029
31- Load ** vcard-creator** directly from [ skypack] ( https:// skypack.dev ) (CDN).
30+ Load ** vcard-creator** directly from [ skypack] [ skypack ] (CDN).
3231
3332``` html
3433<script type =" module" >
3534 import VCard from ' https://cdn.skypack.dev/vcard-creator'
3635 </script >
3736```
3837
39- Demo available in [ codepen] ( https:// codepen.io/joaocarmo/pen/PozdprL ) .
38+ Demo available in [ codepen] [ codepen ] .
4039
4140### On the web (self-hosted)
4241
@@ -54,33 +53,54 @@ It's exposed through the _window_ global object as explained below.
5453` main.js `
5554
5655``` js
57- // define vCard
56+ // Define a new vCard
5857var VCard = window .vcardcreator .default
5958var myVCard = new VCard ()
6059
61- // ...
60+ // ...rest of the code
6261```
6362
6463### With a bundler / Node.js
6564
6665With a bundler (e.g. webpack) or in Node.js you can just require / import it.
6766
6867``` js
69- var VCard = require (' vcard-creator' ).default
68+ const VCard = require (' vcard-creator' ).default
7069
71- // define a new vCard
72- var myVCard = new VCard ()
70+ // Define a new vCard
71+ const myVCard = new VCard ()
7372```
7473
7574Or...
7675
7776``` js
7877import VCard from ' vcard-creator'
7978
80- // define vCard
79+ // Define a new vCard
8180const myVCard = new VCard ()
8281```
8382
83+ ### Including an image
84+
85+ You need to provide the image already properly encoded (base64). Most software
86+ will probably ignore a photo URL, even if it adheres to the specification.
87+
88+ ``` js
89+ // Example in Node.js
90+
91+ const fs = require (' fs' )
92+ const VCard = require (' vcard-creator' ).default
93+
94+ const imagePath = ' ./lib/__tests__/assets/sample.jpg'
95+ const image = fs .readFileSync (imagePath, { encoding: ' base64' , flag: ' r' })
96+
97+ const vCard = new VCard ()
98+
99+ vCard .addPhoto (image, ' JPEG' )
100+ ```
101+
102+ Include the proper [ MIME type] [ mime-types ] (defaults to ` JPEG ` ).
103+
84104### iCalendar format
85105
86106For Apple devices that don't support the ` vcf ` file format, there is a
@@ -90,11 +110,11 @@ with a `ics` file extension instead.
90110The trick is to create an iCalendar file with a vCard attached.
91111
92112``` js
93- // define a new vCard as 'vcalendar'
94- var myVCalendar = new VCard (' vcalendar' )
113+ // Define a new vCard as 'vcalendar'
114+ const myVCalendar = new VCard (' vcalendar' )
95115
96- // or set it afterwards
97- var myOtherVCalendar = new VCard ()
116+ // ... or set it afterwards
117+ const myOtherVCalendar = new VCard ()
98118myOtherVCalendar .setFormat (' vcalendar' )
99119```
100120
@@ -103,20 +123,20 @@ myOtherVCalendar.setFormat('vcalendar')
103123``` js
104124import VCard from ' vcard-creator'
105125
106- // define a new vCard
126+ // Define a new vCard
107127const myVCard = new VCard ()
108128
109- // define variables
129+ // Some variables
110130const lastname = ' Desloovere'
111131const firstname = ' Jeroen'
112132const additional = ' '
113133const prefix = ' '
114134const suffix = ' '
115135
116136myVCard
117- // add personal data
137+ // Add personal data
118138 .addName (lastname, firstname, additional, prefix, suffix)
119- // add work data
139+ // Add work data
120140 .addCompany (' Siesqo' )
121141 .addJobtitle (' Web Developer' )
122142 .addRole (' Data Protection Officer' )
@@ -167,3 +187,10 @@ yarn test:web-build
167187
168188yarn test:web-export
169189```
190+
191+ <!-- References -->
192+
193+ [ codepen ] : https://codepen.io/joaocarmo/pen/PozdprL
194+ [ jeroendesloovere ] : https://github.com/jeroendesloovere/vcard
195+ [ mime-types ] : https://www.iana.org/assignments/media-types/media-types.xhtml#image
196+ [ skypack ] : https://skypack.dev
0 commit comments