Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I use this libraries on cdn or other way, instead npm install #36

Open
bosemian opened this issue Feb 24, 2019 · 7 comments
Open

Can I use this libraries on cdn or other way, instead npm install #36

bosemian opened this issue Feb 24, 2019 · 7 comments

Comments

@bosemian
Copy link

Hi enesser, my project is very small. I don't create that via npm, So I can use this vCards-js on CDN ?,
Thank you :)

@enesser
Copy link
Owner

enesser commented Feb 25, 2019

@bosemian Yes, that shouldn't be a problem.

@bosemian
Copy link
Author

@enesser Great, but I can not see this libraries on https://cdnjs.com/libraries.

@alt-win
Copy link

alt-win commented Jul 18, 2019

Yesss. CDN support please!
What's the link to the CDN @enesser?

@vijaysolankiii
Copy link

@enesser Any update ?

@pascalwengerter
Copy link

Does https://unpkg.com/browse/vcards-js@2.10.0/index.js work for any of y'all?

@vesper8
Copy link

vesper8 commented Apr 18, 2024

I think this is the correct url to use: https://unpkg.com/vcards-js@2.10.0/index.js

but I can't figure out how to actually use that inside my Vue component

@pascalwengerter
Copy link

@vesper8 I ended up rolling my own solution, not exactly proud of it but it works. It lives in a composable and gets called via a @click handler

interface Profile {
  id: string;
  address: string;
  email: string;
  firstName: string;
  lastName: string;
  title: string;
  titleEn: string;
  phoneCell?: string;
  phoneWork?: string;
  profilePicture?: string;

  expand: {
    works_at: {
      street: string;
      city: string;
      country: string;
    };
    works_in: {
      id: string;
      name: string;
    };
  };
}


const makeVCardInfo = (info: string) => `N:${info}\r\n`;
const makeVCardName = (name: string) => `FN:${name}\r\n`;
const makeVCardOrg = (org: string) => `ORG:${org}\r\n`;
const makeVCardTitle = (title: string) => `TITLE:${title}\r\n`;
const makeVCardTel = (type: string, number: string | undefined) =>
  number && `TEL;TYPE=${type}:${number}\r\n`;
const makeVCardAdr = (address: string) => `ADR;TYPE=WORK,PREF:;;${address}\r\n`;
const makeVCardEmail = (email: string) => `EMAIL:${email}\r\n`;
const makeVCardTimeStamp = () => `REV:${new Date().toISOString()}\r\n`;

export default function (profile: Profile) {
  const vcard =
    "BEGIN:VCARD\r\nVERSION:3.0\r\n" +
    makeVCardInfo(`${profile.lastName};${profile.firstName};`) +
    makeVCardName(`${profile.firstName} ${profile.lastName}`) +
    makeVCardOrg(profile.expand.works_in.name) +
    makeVCardTitle(profile.title) +
    makeVCardAdr(
      `${profile.expand.works_at.street}, ${profile.expand.works_at.city}, ${profile.expand.works_at.country}`
    ) +
    makeVCardEmail(profile.email) +
    makeVCardTel("WORK", profile.phoneWork) +
    makeVCardTel("CELL", profile.phoneCell) +
    makeVCardTimeStamp() +
    "END:VCARD";

  const a = document.createElement("a");
  const file = new Blob([vcard], { type: "text/vcard" });
  const sanitizedName = sanitizeName(profile.firstName, profile.lastName);

  a.href = URL.createObjectURL(file);
  a.download = `vcard-${sanitizedName}.vcf`;
  a.click();

  URL.revokeObjectURL(a.href);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants