npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@covve/easy-vcard

v1.1.1

Published

Simple vcard formatter

Downloads

1,046

Readme

Easy-vcard

Create vcards and format to strings to export in .vcf or .vcard files. This is an implementation of the version 4.0 vcard in Typescript according to RFC6350. This is an early version an many vcard fields or properties might not be supported. Check below for what's included.

Installation

npm install --save @covve/easy-vcard

Usage

Examples are written with Typescript in mind but you should be able to use it in nodejs projects as well. Below we construct a simple vcard and export it.

  let vcard = new VCard();
  vcard.setFullName('Johnny D. Doe-Smith')
    .addFirstName('John')
    .addLastName('Doe')
    .addLastName('Smith')
    .addPrefixName('Dr.')
    .addNickname('Jonny')
    .addPhone('+1 1221112', { pref: '1', type: 'home' })
    .addEmail('[email protected]')
    .addTitle('Senior Engineer')
    .addOrganization('Jdoecomp co.', ['North Division']);

  let formatter = new Formatter();
  let formattedText = formatter.format(vcard);
  \\ This should output the following
  \\ "BEGIN:VCARD
  \\  VERSION:4.0
  \\  FN:Johnny D. Doe-Smith
  \\  N:Doe,Smith;John;;Dr.;
  \\  NICKNAME:Jonny
  \\  TEL;PREF=1;TYPE=home:+1 1221112
  \\  EMAIL:[email protected]
  \\  TITLE:Senior Engineer
  \\  ORG:Jdoecomp co.;North Division
  \\  END:VCARD
  \\
  \\ which you can save to a filesystem as .vcf or encode it in a barcode or whatever

VCard methods

Note: IParams refers to a javascript object containing parameters used in certain vCard properties. Some methods support this, some don't. Refer to the RFC aforementioned or source/examples of this project for more details.

setFullName(fullName: string)

Set the FN property of the vcard. This is mandatory and unique. If it doesn't exist, one will be created from name components from the N property.


addFirstName(firstName: string): VCard

addMiddleName(middleName: string): VCard

addLastName(lastName: string): VCard

addPrefixName(pre: string): VCard

addSuffixName(suf: string): VCard

Add a first name, middle name, last name, honorific prefix or honorific suffix respectively in the N property. The N property is unique if it exists.


addNickname(nickname: string, params?: IParams): VCard

Add a nickname to a NICKNAME property.


addPhoto(data: string, params?: IParams): VCard

Add a photo to a PHOTO property. data can be either a link to a site where the photo is hosted or a base64 data representation.


addAddress(street: string, locality: string, region: string, postCode: string, country: string, params?: IParams): VCard

Add an address as an ADR property. Fields not available should be null or undefined.


addPhone(number: string, params?: IParams): VCard

Add a phone number to a TEL property.


addEmail(email: string, params?: IParams): VCard

Add an email to an EMAIL property.


addTitle(title: string, params?: IParams): VCard

Add a title in the list of the TITLE property.


addRole(role: string, params?: IParams): VCard

Add a role in the list of the ROLE property.


addOrganization(organization: string, organizationUnits: string[], params?: IParams): VCard

Add an organization to an ORG property. Organization refers to the main name of the company and organizationUnits to second or more unit names.


addNotes(notes: string, params?: IParams): VCard

Add a notes entry in a NOTE property.


addUrl(url: string, params?: IParams): VCard

Add a url entry in a URL property


setRevision(rev: string, params?: IParams): VCard

Set the revision for this vcard.


setUID(uid: string, params?: IParams): VCard

Set the user id for this vcard.


toString(forceV3 = false): string

Takes a VCard object as created above and formats it into a string. Note that a forceV3 argument is included, which if true, sets the VERSION property to 3.0 . This doesn't mean that this plugin supports 3.0 vcards or earlier, it's just a workaround to get your simple vcards read by older parsers found in various devices. Care should be taken using this as the card might not be readable by 3.0 or older parsers.

Not yet supported

The following vCard properties are not yet included but might be in the future.

SOURCE, KIND, XML, BDAY, ANNIVERSARY, GENDER, IMPP, LANG, TZ, GEO,
LOGO, MEMBER, RELATED, CATEGORIES, PRODID, SOUND, CLIENTPIDMAP, KEY, FBURL, CALADRURI, CALURI

Contribute

Feel free to submit PRs or open issues with improvements or bug fixes.

LICENSE

MIT