VCF file creation and download

Example of the code I mentioned above

import vCard from 'vcf';
import { saveAs } from 'file-saver';
import wixLocation from 'wix-location';

// Define a function to create the VCF file
async function createVCF() {
  // Create the VCard data
  const card = new vCard();
  card.firstName = 'John';
  card.lastName = 'Doe';
  card.email = 'john.doe@example.com';
  card.phone = '123-456-7890';

  // Convert the VCard data to a Blob object
  const blob = new Blob([card.toString()], { type: 'text/vcard;charset=utf-8' });

  // Return the Blob object
  return blob;
}

// Add an event listener to the button
$w('#button2').onClick(async () => {
  // Create the VCF file
  const blob = await createVCF();

  // Save the VCF file using the file-saver library
  saveAs(blob, 'contact.vcf');

  // Get the URL of the Blob object
  const blobUrl = URL.createObjectURL(blob);

  // Open the URL in a new window
  window.open(blobUrl, '_blank');

  // Redirect the user to the VCF file using Wix Location
  wixLocation.to(blobUrl);
});