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

vcard-creator

v0.7.1

Published

A JavaScript vCard creator library for both node.js and the web

Downloads

22,634

Readme

vcard-creator

npm version jest tests Total alerts Language grade: JavaScript

A JavaScript vCard 3.0 creator library for both node.js and the web. It outputs the vCard text that should be saved as a *.vcf file.

Origin

This is based on jeroendesloovere's vCard for PHP.

Installation

pnpm add vcard-creator

# or

npm install vcard-creator

Usage

As an ESM module (web)

Load vcard-creator directly from skypack (CDN).

<script type="module">
  import VCard from 'https://cdn.skypack.dev/vcard-creator'
</script>

Demo available in codepen.

On the web (self-hosted)

It's exposed through the window global object as explained below.

index.html

<head>
  <script type="text/javascript" src="./js/vcard-creator.js"></script>
  <script type="text/javascript" src="./js/main.js"></script>
</head>

main.js

// Define a new vCard
var VCard = window.vcardcreator.default
var myVCard = new VCard()

// ...rest of the code

With a bundler / Node.js

With a bundler (e.g. webpack) or in Node.js you can just require / import it.

const VCard = require('vcard-creator').default

// Define a new vCard
const myVCard = new VCard()

Or...

import VCard from 'vcard-creator'

// Define a new vCard
const myVCard = new VCard()

Including an image

You need to provide the image already properly encoded (base64). Note that most applications will probably ignore a photo URL, even if it adheres to the specification.

// Example in Node.js

const fs = require('fs')
const VCard = require('vcard-creator').default

const imagePath = './path/to/my/assets/sample.jpg'
const image = fs.readFileSync(imagePath, { encoding: 'base64', flag: 'r' })

const vCard = new VCard()

vCard.addPhoto(image, 'JPEG')

Include the proper MIME type (defaults to JPEG).

[DEPRECATED] iCalendar format

For Apple devices that don't support the vcf file format, there is a workaround. Specify the format of the output as vcalendar and then save it with a ics file extension instead.

The trick is to create an iCalendar file with a vCard attached.

// Define a new vCard as 'vcalendar'
const myVCalendar = new VCard('vcalendar')

// ...or set it afterwards
const myOtherVCalendar = new VCard()
myOtherVCalendar.setFormat('vcalendar')

Example

import VCard from 'vcard-creator'

// Define a new vCard
const myVCard = new VCard()

// Some variables
const lastname = 'Desloovere'
const firstname = 'Jeroen'
const additional = ''
const prefix = ''
const suffix = ''

myVCard
  // Add personal data
  .addName(lastname, firstname, additional, prefix, suffix)
  // Add work data
  .addCompany('Siesqo')
  .addJobtitle('Web Developer')
  .addRole('Data Protection Officer')
  .addEmail('[email protected]')
  .addPhoneNumber(1234121212, 'PREF;WORK')
  .addPhoneNumber(123456789, 'WORK')
  .addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium')
  .addSocial('https://twitter.com/desloovere_j', 'Twitter', 'desloovere_j')
  .addURL('http://www.jeroendesloovere.be')

console.log(myVCard.toString())

Output

BEGIN:VCARD
VERSION:3.0
REV:2017-08-31T17:00:15.850Z
N;CHARSET=utf-8:Desloovere;Jeroen;;;
FN;CHARSET=utf-8:Jeroen Desloovere
ORG;CHARSET=utf-8:Siesqo
TITLE;CHARSET=utf-8:Web Developer
ROLE;CHARSET=utf-8:Data Protection Officer
EMAIL;INTERNET:[email protected]
TEL;PREF;WORK:1234121212
TEL;WORK:123456789
ADR;WORK;POSTAL;CHARSET=utf-8:name;extended;street;worktown;state;workpos
 tcode;Belgium
X-SOCIALPROFILE;type=Twitter;x-user=desloovere_j:https://twitter.com/desl
oovere_j
URL:http://www.jeroendesloovere.be
END:VCARD

Forking / Contributing

If you're interested in the development of this project, you can run some ready to use commands to compile and test your changes.

# Build
pnpm build

# Test
pnpm test:unit

pnpm test:functional

pnpm test:web-build

pnpm test:web-export