Git Product home page Git Product logo

vcard-generator's Introduction

vcard-generator

Build Status Coverage Status npm version Dependency Status License

VCard v4.0 rfc6350 compliant generator from JSON.

Install

npm install --save vcard-generator

Usage

import vcard from 'vcard-generator';

const vcardContent = vcard.generate({
  name: {
    familyName: 'Doe',
    givenName: 'John',
    middleName: 'Philip',
    prefix: 'Dr.',
    suffix: 'Jr.',
  },
  formattedNames: [{
    text: 'Mr. Johny',
  }],
  nicknames: [{
    text: 'Phil',
  }],
  extraName: {
    maidenName: 'MaidenName',
    phoneticFirstName: 'PhoneticFirstName',
    phoneticMiddleName: 'PhoneticMiddleName',
    phoneticLastName: 'PhoneticLastName',

    pronunciationFirstName: 'PronunciationFirstName',
    pronunciationMiddleName: 'PronunciationMiddleName',
    pronunciationLastName: 'PronunciationLastName',
  },

  works: [{
    organization: 'My Company, Inc.',
    title: 'CEO',
    role: 'Executive',
  }],
  emails: [{
    type: 'work',
    text: '[email protected]',
  }, {
    type: 'home',
    text: '[email protected]',
  }],
  phones: [{
    type: 'work',
    text: '1 (234) 567-8901',
  }, {
    text: '(123) 123-1234',
  }, {
    uri: 'tel:1234567890',
  }],
  addresses: [{
    type: 'work',
    street: '123 Forbes Ave, Apt 1',
    locality: 'San Francisco',
    region: 'CA',
    code: '12345',
    country: 'USA',
  }, {
    type: 'home',
    street: '456 Home St',
    locality: 'Homeland',
    region: 'CA',
    code: '23456',
    country: 'USA',
  }],
  socialProfiles: [{
    type: 'facebook',
    uri: 'http://www.facebook.com/johndoe',
  }, {
    type: 'twitter',
    user: 'johnie',
  }],
  urls: [{
    type: 'internet',
    uri: 'http://www.mycompany.com',
  }, {
    type: 'personal',
    uri: 'http://www.johndoe.com',
  }],

  photos: [{
    type: 'work',
    uri: 'https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg',
  }, {
    type: 'home',
    dataUri: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC',
  }],

  birthday: {
    year: 2000,
    month: 1,
    day: 31,
  },
  gender: {
    sex: 'male',
  },
  notes: [{
    text: 'John Doe has a long and varied history, being documented on more police files that anyone else.\nReports of his death are alas numerous.',
  }, {
    text: 'Another note.',
  }],
});

// returns
BEGIN:VCARD
VERSION:4.0
N:Doe;John;Philip;Dr.;Jr.
FN:Mr. Johny
NICKNAME:Phil
X-MAIDENNAME:MaidenName
X-PHONETIC-FIRST-NAME:PhoneticFirstName
X-PHONETIC-MIDDLE-NAME:PhoneticMiddleName
X-PHONETIC-LAST-NAME:PhoneticLastName
X-PRONUNCIATION-FIRST-NAME:PronunciationFirstName
X-PRONUNCIATION-MIDDLE-NAME:PronunciationMiddleName
X-PRONUNCIATION-LAST-NAME:PronunciationLastName
ORG:My Company\, Inc.
TITLE:CEO
ROLE:Executive
EMAIL;PREF=1;TYPE=work:john@mycompany.com
EMAIL;PREF=2;TYPE=home:johndoe@example.com
TEL;PREF=1;TYPE=work:1 (234) 567-8901
TEL;PREF=2:(123) 123-1234
TEL;VALUE=uri;PREF=3:tel:1234567890
ADR;PREF=1;TYPE=work:;;123 Forbes Ave\, Apt 1;San Francisco;CA;12345;USA
ADR;PREF=2;TYPE=home:;;456 Home St;Homeland;CA;23456;USA
X-SOCIALPROFILE;PREF=1;TYPE=facebook:http://www.facebook.com/johndoe
X-SOCIALPROFILE;PREF=2;TYPE=twitter;x-user=johnie:x-apple:johnie
URL;PREF=1;TYPE=internet:http://www.mycompany.com
URL;PREF=2;TYPE=personal:http://www.johndoe.com
PHOTO;PREF=1;TYPE=work:https://upload.wikimedia.org/wikipedia/en/8/80/Wikipedia-logo-v2.svg
PHOTO;PREF=2;TYPE=home:data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC
BDAY:20000131
GENDER:M
NOTE;PREF=1:John Doe has a long and varied history\, being documented on more police files that anyone else.\nReports of his death are alas numerous.
NOTE;PREF=2:Another note.
END:VCARD

vcard-generator's People

Contributors

joonhocho avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

vcard-generator's Issues

Can't specify label parameter

while creating multiple URL's, cant specify the label parameter. when we specify it, will not reflect in the response.

    const vcardContent = vcard.generate({

        name: {
            familyName: 'test',
        },
        emails: [{
            type: 'work',
            text: '[email protected]',
        }],
        phones: [{
            type: 'SMS',
            text: '+1408338',
        }],
        urls: [{
            type:'whatsapp',
           label:'Whatsapp'
            uri: 'https://api.whatsapp.com/send?phone=+4915',
        }]

    });

getting without label responce

BEGIN:VCARD
VERSION:4.0
N:test;;;;
EMAIL;TYPE=work:[email protected]
TEL;TYPE=SMS:+1408338
URL;TYPE=whatsapp:https://api.whatsapp.com/send?phone=+4915
END:VCARD

vcard is not a function

When I using this npm it shows like

vcard is not a function at Vcardgenerator.generate (/home/jose/VCardApp/vcardgenerator.js:32:30) at /home/jose/VCardApp/app.js:62:20 at Layer.handle [as handle_request] (/home/jose/VCardApp/node_modules/express/lib/router/layer.js:95:5) at next (/home/jose/VCardApp/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/jose/VCardApp/node_modules/express/lib/router/route.js:112:3) at Layer.handle [as handle_request] (/home/jose/VCardApp/node_modules/express/lib/router/layer.js:95:5) at /home/jose/VCardApp/node_modules/express/lib/router/index.js:281:22 at Function.process_params (/home/jose/VCardApp/node_modules/express/lib/router/index.js:335:12) at next (/home/jose/VCardApp/node_modules/express/lib/router/index.js:275:10) at /home/jose/VCardApp/node_modules/body-parser/lib/read.js:130:5 at invokeCallback (/home/jose/VCardApp/node_modules/raw-body/index.js:262:16) at done (/home/jose/VCardApp/node_modules/raw-body/index.js:251:7) at IncomingMessage.onEnd (/home/jose/VCardApp/node_modules/raw-body/index.js:307:7) at emitNone (events.js:86:13) at IncomingMessage.emit (events.js:185:7)

The npm is successfully installed..but shows like this...

VCard not compatible with Android

I made a web app that allows users to download a VCard on their phone.

Here's the code to generate the VCard:

const buildVCard = someone =>
  vCard.generate({
    name: {
      familyName: someone.name.split(' ').slice(1).join(' '),
      givenName: someone.name.split(' ')[0],
    },
    works: [{
      organisation: 'MyOrg',
    }],
    phones: [{
      type: 'work',
      text: someone.phone,
    }],
    emails: [{
      type: 'work',
      text: someone.email,
    }],
    photos: [{
      type: 'work',
      uri: someone.avatar,
    }],
  });

Here is example data for someone:

{
  "name": "Jane Doe",
  "avatar": "https://example.com/048636_n.jpg",
  "phone": "+33606060606",
  "email": "[email protected]"
}

The problem is that on Android phones, the contacts app cannot import the resulting vCard : "The format is not supported". It's working fine on iOS.
Are there any specificities to vCards on Android?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.