Git Product home page Git Product logo

node-vcf's Introduction

VCF / vCard

npm npm license npm downloads

Install via npm

$ npm install --save vcf

Index

Usage

var vCard = require( 'vcf' )

Parsing a Single vCard

var card = new vCard().parse( string )
vCard {
  version: '4.0',
  data: {
    version: [String: '4.0'],
    n: [String: 'Gump;Forrest;;;'],
    fn: [String: 'Forrest Gump'],
    org: [String: 'Bubba Gump Shrimp Co.'],
    title: [String: 'Shrimp Man'],
    photo: { [String: 'http://www.example.com/dir_photos/my_photo.gif'] mediatype: 'image/gif' },
    tel: [
      { [String: 'tel:+11115551212'] type: [ 'work', 'voice' ], value: 'uri' },
      { [String: 'tel:+14045551212'] type: [ 'home', 'voice' ], value: 'uri' }
    ],
    adr: [
      { [String: ';;100 Waters Edge;Baytown;LA;30314;United States of America']
        type: 'work',
        label: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' },
      { [String: ';;42 Plantation St.;Baytown;LA;30314;United States of America']
        type: 'home',
        label: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"' }
    ],
    email: [String: '[email protected]'],
    rev: [String: '20080424T195243Z']
  }
}

Parsing Multiple vCards

In order to deal with a string that contains multiple vCards, you will need to use a different function, which returns an array of cards:

var cards = vCard.parse( string )

Formats

Format: jCard

var card = vCard.fromJSON( data )
var jcard = card.toJSON()
[ "vcard",
  [
    [ "version", {}, "text", "4.0" ],
    [ "n", {}, "text", [ "Gump", "Forrest", "", "", "" ] ],
    [ "fn", {}, "text", "Forrest Gump" ],
    [ "org", {}, "text", "Bubba Gump Shrimp Co." ],
    [ "title", {}, "text", "Shrimp Man" ],
    [
      "photo", { "mediatype": "image/gif" },
      "text", "http://www.example.com/dir_photos/my_photo.gif"
    ],
    [ "tel", { "type": [ "work", "voice" ], "value": "uri" }, "uri", "tel:+11115551212" ],
    [ "tel", { "type": [ "home", "voice" ], "value": "uri" }, "uri", "tel:+14045551212" ],
    [
      "adr", { "type": "work", "label":"\"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America\"" },
      "text", [ "", "", "100 Waters Edge", "Baytown", "LA", "30314", "United States of America" ]
    ],
    [
      "adr", { "type": "home", "label": "\"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica\"" },
      "text", [ "", "", "42 Plantation St.", "Baytown", "LA", "30314", "United States of America" ]
    ],
    [ "email", {}, "text", "[email protected]" ],
    [ "rev", {}, "text", "20080424T195243Z" ]
  ]
]

Format: VCF

var vcf = card.toString()
var vcf = card.toString( '4.0' )
BEGIN:VCARD
VERSION:4.0
N:Gump;Forrest;;;
FN:Forrest Gump
ORG:Bubba Gump Shrimp Co.
TITLE:Shrimp Man
PHOTO;MEDIATYPE=image/gif:http://www.example.com/dir_photos/my_photo.gif
TEL;TYPE=work,voice;VALUE=uri:tel:+11115551212
TEL;TYPE=home,voice;VALUE=uri:tel:+14045551212
ADR;TYPE=work;LABEL="100 Waters Edge\nBaytown, LA 30314\nUnited States
  of America":;;100 Waters Edge;Baytown;LA;30314;United States of America
ADR;TYPE=home;LABEL="42 Plantation St.\nBaytown, LA 30314\nUnited
  States ofAmerica":;;42 Plantation St.;Baytown;LA;30314;United States of
 America
EMAIL:[email protected]
REV:20080424T195243Z
END:VCARD

API Reference

vCard

Kind: global class


new vCard()

vCard


vCard.version : String

Version number

Kind: instance property of vCard


vCard.data : Object

Card data

Kind: instance property of vCard


vCard.get(key) ⇒ Object | Array

Get a vCard property

Kind: instance method of vCard

Param Type
key String

vCard.set(key, value, params)

Set a vCard property

Kind: instance method of vCard

Param Type
key String
value String
params Object

vCard.add(key, value, params)

Add a vCard property

Kind: instance method of vCard

Param Type
key String
value String
params Object

vCard.setProperty(prop)

Set a vCard property from an already constructed vCard.Property

Kind: instance method of vCard

Param Type
prop Property

vCard.addProperty(prop)

Add a vCard property from an already constructed vCard.Property

Kind: instance method of vCard

Param Type
prop Property

vCard.parse(value) ⇒ vCard

Parse a vcf formatted vCard

Kind: instance method of vCard

Param Type
value String

vCard.toString(version, charset) ⇒ String

Format the vCard as vcf with given version

Kind: instance method of vCard

Param Type
version String
charset String

vCard.toJCard(version) ⇒ Array

Format the card as jCard

Kind: instance method of vCard
Returns: Array - jCard

Param Type Default
version String '4.0'

vCard.toJSON() ⇒ Array

Format the card as jCard

Kind: instance method of vCard
Returns: Array - jCard


vCard.Property

Kind: static class of vCard


new Property(field, value, params)

vCard Property

Param Type
field String
value String
params Object

property.is(type) ⇒ Boolean

Check whether the property is of a given type

Kind: instance method of Property

Param Type
type String

property.isEmpty() ⇒ Boolean

Check whether the property is empty

Kind: instance method of Property


property.clone() ⇒ Property

Clone the property

Kind: instance method of Property


property.toString(version) ⇒ String

Format the property as vcf with given version

Kind: instance method of Property

Param Type
version String

property.valueOf() ⇒ String

Get the property's value

Kind: instance method of Property


property.toJSON() ⇒ Array

Format the property as jCard data

Kind: instance method of Property


Property.prototype : Object

Property prototype

Kind: static property of Property


Property.fromJSON(data) ⇒ Property

Constructs a vCard.Property from jCard data

Kind: static method of Property

Param Type
data Array

vCard.mimeType : String

vCard MIME type

Kind: static property of vCard


vCard.extension : String

vCard file extension

Kind: static property of vCard


vCard.versions : Array

vCard versions

Kind: static property of vCard


vCard.foldLine ⇒ String

Folds a long line according to the RFC 5322.

Kind: static property of vCard
See: http://tools.ietf.org/html/rfc5322#section-2.1.1

Param Type
input String
maxLength Number
hardWrap Boolean

vCard.parseLines : function

Parse an array of vcf formatted lines

Kind: static property of vCard
Internal: used by vCard#parse()


vCard.normalize(input) ⇒ String

Normalizes input (cast to string, line folding, whitespace)

Kind: static method of vCard

Param Type
input String

vCard.isSupported(version) ⇒ Boolean

Check whether a given version is supported

Kind: static method of vCard

Param Type
version String

vCard.parse(value) ⇒ Array.<vCard>

Parses a string or buffer into a vCard object

Kind: static method of vCard

Param Type
value String | Buffer

vCard.fromJSON(jcard) ⇒ vCard

Constructs a vCard from jCard data

Kind: static method of vCard

Param Type
jcard Array

vCard.format(card, version) ⇒ String

Format a card object according to the given version

Kind: static method of vCard

Param Type
card vCard
version String

node-vcf's People

Contributors

1ec5 avatar adamduren avatar ajmas avatar apehaenger avatar arnezsng avatar danielepiccone avatar jhermsmeier avatar mishkx avatar mlandes avatar sseide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar

node-vcf's Issues

Uppercasing of property type labels

I'm trying to set custom type labels on my tel properties although they're being uppercased. Is there any reason for this?

I'm setting the property with card.add('tel', '1234567', { type: 'personal' });

I can see the uppercasing is happening in the lib here.

Is there any quick fix to get around this? I'm using vCard version 3.0

Here's what's happening:
Screen Shot 2021-11-09 at 10 50 56 am

and this is what I'm hoping for:
Screen Shot 2021-11-09 at 10 50 25 am

Thanks!

Make "vCard.get" Generic

Hi 👋,

I'm using this excellent library with typescript, and I have a request regarding the type definitions. Currently fetching a value looks like this:

// Must assert the type, since get returns string | object. 
const photo: string = <string>card.get('photo').valueOf();

It starts looking funny when you need to perform more actions on the value:

const categories = (<string>card.get('photo').valueOf()).split(',');

I propose that Property be generic, maybe still constrain it to just strings and objects with <Type extends string | object> so that I'm able to do:

const categories = card.get<string>('photo').valueOf().split(',');

The above would also make it possibe to type-hint against specific interfaces.

I'm willing to submit a pull request for this.

EDIT:

Also having this for Property | Property[] would be useful, so maybe something like:

const categories = card.get<Property<string>[]>('photo').valueOf().split(',');

EDIT 2:

Even better, it would be nice if get could return a single type (e.g just Property[]) so that we do not have to check if the returned value is a string or an array.

Expected VERSION

I am testing the parsing of vcard files with a bunch of sample vcard examples I found online.
The birthday on them seems to come up before the version number, which I would assumed wouldn't break the parse.

I'm just concerned if one of my users uploads a similar vcard with this similar format of NOT having the version number as the first data field, this parser cannot parse it and will fail.

Is this a standardized failure by the example site I got these sample vcards from that is never to be expected with a vcard? I was thinking that this package would still parse through and search for a version number, but it appears not.

Let me know what y'all think. For right now, I'm just going to move the BDAY below the VERSION for now.

Error:

SyntaxError: Invalid vCard: Expected "VERSION:\d.\d" but found "BDAY;VALUE=DATE:1963-09-21"

This is the one I'm trying to parse:

BEGIN:VCARD
BDAY;VALUE=DATE:1963-09-21
VERSION:3.0
N:Stenerson;Derik
FN:Derik Stenerson
ORG:Microsoft Corporation
ADR;TYPE=WORK,POSTAL,PARCEL:;;One Microsoft Way;Redmond;WA;98052-6399;USA
TEL;TYPE=WORK,MSG:+1-425-936-5522
TEL;TYPE=WORK,FAX:+1-425-936-7329
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD

BEGIN:VCARD
VERSION:3.0
N:Ganguly;Anik
FN:Anik Ganguly
ORG: Open Text Inc.
ADR;TYPE=WORK,POSTAL,PARCEL:;Suite 101;38777 West Six Mile Road;Livonia;MI;48152;USA
TEL;TYPE=WORK,MSG:+1-734-542-5955
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD

BEGIN:VCARD
VERSION:3.0
N:Moskowitz;Robert
FN:Robert Moskowitz
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD

Structured Property Values with empty/missing components

At first specifications :P --> https://tools.ietf.org/html/rfc7095#section-3.3.1.3:

The vCard specification defines properties with structured values,
for example, "GENDER" or "ADR". In vCard, a structured text value
consists of one or multiple text components, delimited by the
SEMICOLON character. Its equivalent in jCard is a structured
property value, which is an array containing one element for each
text component, with empty/missing text components represented by
zero-length strings
.

[...]

Per Section 6.3.1 of [RFC6350], the component separator MUST be
specified even if the component value is missing. Similarly, the
jCard array containing the structured data MUST contain all required
elements, even if they are empty
.

vCard Example:

ADR;LABEL="123 Maple Ave\nSuite 901\nVancouver BC\nA1B 2C9\nCan
ada":;;;;;;

jCard Example:

["adr",
{"label":"123 Maple Ave\nSuite 901\nVancouver BC\nA1B 2C9\nCanada"},
"text",
["", "", "", "", "", "", ""]
]

My Problem is using new vCard().parse(vcfString).toJCard() with following vcfString:

BEGIN:VCARD
VERSION:2.1
ADR;CHARSET=utf-8;WORK:Postfach 9999
END:VCARD

results in:

[
    "vcard",
    [
        ["version", {}, "text", "4.0"],
        ["adr", {"charset": "utf-8", "type": "work"}, "text", 
            ["Postfach 9999"]
        ]
    ]
]

whereas I think for "adr" it should be:

[
    "vcard",
    [
        ["version", {}, "text", "4.0"],
        ["adr", {"charset": "utf-8", "type": "work"}, "text", 
            ["Postfach 9999", "", "", "", "", "", ""]
        ]
    ]
]

Parameter value containing a colon ':' leads to incorrect parsing

Here is a small snippet which allows to reproduce the issue:

const Vcf = require('vcf')
const data = `BEGIN:VCARD
VERSION:4.0
NAME;PARAMETER="parameter value contains a :colon":value also contains a :colon
END:VCARD`.replace(/\n/g, '\r\n')

const vCard = new Vcf().parse(data)

console.log(vCard.get('name').valueOf())

This returns:

colon":value also contains a :colon

instead of:

value also contains a :colon

According to the RFC, the colon is allowed in the parameter value as long as its within double quotes.

   param-value = *SAFE-CHAR / DQUOTE *QSAFE-CHAR DQUOTE

   any-param  = (iana-token / x-name) "=" param-value *("," param-value)

   NON-ASCII = UTF8-2 / UTF8-3 / UTF8-4
     ; UTF8-{2,3,4} are defined in [RFC3629]

   QSAFE-CHAR = WSP / "!" / %x23-7E / NON-ASCII
     ; Any character except CTLs, DQUOTE

   SAFE-CHAR = WSP / "!" / %x23-39 / %x3C-7E / NON-ASCII
     ; Any character except CTLs, DQUOTE, ";", ":"

Labels not matched up with addresses in older vCard versions

Using the vCard 2.1 example at https://en.wikipedia.org/wiki/VCard, the adr and label properties are split apart, instead of the expected result of labels being a property of each address. Using a v4.0 card works as expected.

Version 2.1

vCard {
  version: '2.1',
  data: {
    adr: [
      { _data: ';;100 Waters Edge;Baytown;LA;30314;United States of America',
        type: 'work'},
      { _data: ';;42 Plantation St.;Baytown;LA;30314;United States of America',
        type: 'home'}
    ],
    label: [
      { _data: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' },
      { _data: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"'}
    ]
  }
}

Version 4.0

vCard {
  version: '4.0',
  data: {
    adr: [
      { _data: ';;100 Waters Edge;Baytown;LA;30314;United States of America',
        type: 'work',
        label: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' },
      { _data: ';;42 Plantation St.;Baytown;LA;30314;United States of America',
        type: 'home',
        label: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"' }
    ]
  }
}

Non-Primitive Values

I've had to do a lot of extra parsing because parse() uses the new keyword to create what should be primitive values. I'm sure there is a good reason for this, though I'm not sure what it coudl be. Perhaps it would be better to adjust the parse() method to output primitives?

Maybe something like this:

{
	version: '4.0',
	data: {
		version: '4.0',
		n: ['Gump','Forrest','',''],
		fn: 'Forrest Gump',
		org: 'Bubba Gump Shrimp Co.',
		title: 'Shrimp Man',
		photo: { 
			text: 'http://www.example.com/dir_photos/my_photo.gif'
			mediatype: 'image/gif' 
		},
		tel: [
			{ uri: 'tel:+11115551212', type: [ 'work', 'voice' ] },
			{ uri: 'tel:+14045551212', type: [ 'home', 'voice' ] }
		],
		adr: [
			{ 
				text: ['', '', '100 Waters Edge','Baytown','LA','30314','United States of America'],
				type: 'work',
				label: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' 
			},
			{ 
				text: ['', '', '42 Plantation St.','Baytown','LA','30314','United States of America'],
				type: 'home',
				label: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"'
			}
		],
		email: '[email protected]',
		rev: '20080424T195243Z'
	}
}

Here is a fiddle

Unfolding lines with more than one whitespace at the beginning

According to (https://tools.ietf.org/html/rfc6350#section-3.2) line folding is supposed to have only one space/tab character at the beginning of each folded line.

The current regex for normalizing the values does not handle it properly, it is visible also on the main readme.md file where United States ofAmerica is missing a space.

adr: [
      { [String: ';;100 Waters Edge;Baytown;LA;30314;United States of America']
        type: 'work',
        label: '"100 Waters Edge\\nBaytown, LA 30314\\nUnited States of America"' },
      { [String: ';;42 Plantation St.;Baytown;LA;30314;United States of America']
        type: 'home',
        label: '"42 Plantation St.\\nBaytown, LA 30314\\nUnited States ofAmerica"' }

Update documentation to clarify parse() vs parseMultiple()

Reading the documentation as it is currently you could easily miss the fact there is a parseMultiple() function that can be used to parse a string that contains multiple vCards. Updated the documentation is clarify this.

This is a result of the discussion in issue #11.

What is get returning?

I'm absolutely bumfuzzled by what get returns.

My code looks something like:

    var photo = card.get( 'photo' );

If I console.log( photo ), I get:

{ [String: '<bunch of base64 data>'] encoding: 'BASE64', type: 'jpeg' }

What throws me so severely is that this is supposedly an object (starts with {) but it's made up of an array which doesn't have a property as a key, then no comma between that array's end and the property 'encoding'. Huh?

So I do a JSON.stringify( photo, null, 4 ) and get:

[
    "photo",
    {
        "encoding": "BASE64",
        "type": "jpeg"
    },
    "text",
    "<bunch of base64 data>"
]

Why that's different, I don't know, but it at least looks like a proper JavaScript data structure. It's an array, yet when I console.log( photo[0] ) I get "undefined".

I've stuck debug console.logs in the source and so know it's returning this.data[ key ].clone() (confirmed with typeof), but that's not helping me make sense of this, or get my photo data!

I also know, from test/photo.js, that it's a vCard.Property. Still confused :)

Never seen anything like this! My JS must improve!

parsing error when trying to process multiple vcard entries that was exported from icloud

I exported a set of contacts from my icloud.com account. This file appears to be correct but when importing using the multiple imports method I get this error:

SyntaxError: Invalid vCard: Expected "VERSION:\d.\d" but found "undefined"

Here is how read and import the file:

var contactData = fs.readFileSync("./samples/multiple-contacts-from-icloud.vcf","utf8", "utf8");
var contacts = vCard.parse(contactData); //multiple

I've attached my sample file here, i appended the '.txt' extension to allow attach here.
multiple-contacts-from-icloud.vcf.txt

Encoding issues?

I am trying to use your plugin to split a big vcard into chunks of 100.

Here is my source code:

let fs = require('fs');
let vCard = require( 'vcf' );

fs.readFile('contacts.vcf', 'utf8', (err, data) => {
    if (err) throw err;
    
    let cards = vCard.parse( data );
    console.log(cards.length);

    perChunk = 100 // items per chunk    

    inputArray = cards;
    
    let chunks = inputArray.reduce((resultArray, item, index) => { 
      const chunkIndex = Math.floor(index/perChunk)
    
      if(!resultArray[chunkIndex]) {
        resultArray[chunkIndex] = [] // start a new chunk
      }
    
      resultArray[chunkIndex].push(item)
    
      return resultArray
    }, [])
    
    console.log(chunks.length);

    let part = 1;
    for(let chunk of chunks){
        let filename = `part${part}.vcf`;

        let data = '';
        for(let card of chunk){
            data += card.toString();
            data += '\n'; 
        }
        fs.writeFile(filename, data, 'utf8');

        part++;
    }

  });

All is well, except for something strange happening with the encoding.

For example there is a contact named "Déborah Garçon". In VSCode I can see the name correctly, however as soon as I import it into Google Contacts, it appears as "Déborah Garçon".

I

  1. Export a big VCF from Apple Contacts
  2. Run it through the above script
  3. Import the resulting VCF to Google Contacts

When I skip step 2, it imports the name correctly...

Any ideas?

Version 2.0.6 fails to parse vcard files created by 2.0.4

2.0.6 fixed the bug introduced in 2.0.5 that prevented it from parsing its own output.
But 2.0.6 fails to parse its own output generated by version 2.0.4

2.0.4 on the other hand is able to parse output from versions 2.0.4, 2.0.5 and 2.0.6

Normalize Values

I've notice that when there is one value for email address and phone numbers the ouput is an Object but if they are multiple it's an Array. Should always be an Array.

I am not able to parse below file , its giving error like expected version but found BDAY

I am trying to parse below vcf file , its giving error of expected version but found BDAY.

This file is having birthday property on the second line of the file which is making issue I think . The tool is expecting version to be at second line compulsory .

However this file import easily in the mobile so this file should be parse by this tool also .

I am attaching the file , please check and let me know .

File is as below

BEGIN:VCARD
BDAY;VALUE=DATE:1963-09-21
VERSION:3.0
N:Stenerson;Derik
FN:Derik Stenerson
ORG:Microsoft Corporation
ADR;TYPE=WORK,POSTAL,PARCEL:;;One Microsoft Way;Redmond;WA;98052-6399;USA
TEL;TYPE=WORK,MSG:+1-425-936-5522
TEL;TYPE=WORK,FAX:+1-425-936-7329
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Ganguly;Anik
FN:Anik Ganguly
ORG: Open Text Inc.
ADR;TYPE=WORK,POSTAL,PARCEL:;Suite 101;38777 West Six Mile Road;Livonia;MI;48152;USA
TEL;TYPE=WORK,MSG:+1-734-542-5955
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD
BEGIN:VCARD
VERSION:3.0
N:Moskowitz;Robert
FN:Robert Moskowitz
EMAIL;TYPE=INTERNET:[email protected]
END:VCARD

Thanks[](url)

Export with es module syntax

Hey, we are integrating your lib in our Angular project, which lately reported us that vcf is a cjs lib. Would it be possible to provide an esm export, so it can be optimized by the compiler? From what I see vcf isn't that heavy, so it would just require a small refactor. You could use esbuild to compile it into different formats.

Issues if dealing with vcf with multiple cards

The library appears to run into issues if a vcf file contains multiple vCards. What I see is the records from all the vCards are merged into one entry.

For example (trimmed):

vCard {
  version: '3.0',
  data: 
   { version: 
      [ [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'],
        [String: '3.0'] ],
     prodid: 
      [ [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'],
        [String: '-//Apple Inc.//Mac OS X 10.12.1//EN'] ],
     n: 
      [ [String: 'Matters;Sylvie;;;'],
        [String: 'Dawson;Jesse;;;'],
        [String: 'Kelsdaughter;Jen;;;'],
        [String: ';;;;'],
        [String: 'Jameson;Jen;;;'],
        [String: ';;;;'],
        [String: 'Dawson;Marc;;;'],
        [String: ';Agathe;;;'],
        [String: ';;;;'],
        [String: 'Doe;John;;;'],
        [String: 'Vino;Vito;;;'],
        [String: ';Alexei;;;'],
        [String: 'Boucher;Marie-Claude;;;'],
        [String: ';;;;'] ],
...

It would be useful to have this scenario supported, even if it via a new function parseMulti() , as to not break assumptions of code depending on current design.

capitalDashCase not behaving as expected

card.add('MEMBER', '1a7935722bfa2289da2934b87769cd14')

This generates:

-M-E-M-B-E-R:1a7935722bfa2289da2934b87769cd14

I expected:

MEMBER:1a7935722bfa2289da2934b87769cd14

I fiddled with the following line to remove the case translation, but have not got a definitive fix:

return value.replace( /([A-Z])/g, '-$1' ).toUpperCase()

Unsupported version ARD

Hi,
When loading v4 vcard as a new vCard.parse failed with return code:

Error: Unsupported version \"ARD\"

ToJSON returns original vcf version number and not 4.0

running the following on a vcf 2.1 will return version 2.1 attribute in the jcard.

var card = vCard.parse(string);
var jcard = card.toJSON();

I assume we can get a 4.0 version by doing:

var card = vCard.parse(string);
card = vCard.parse(card.toString('4.0'));
var jcard = card.toJSON();

If that's the case, then it might be more obvious for a user to call a function like toJCard() that will do that.

camelcase dependency browser support

Hi!

Author of camelcase library decided to support only modern browsers since 4.0 version.
sindresorhus/camelcase#19
Therefore node-vcf requires the use of transpiler to make it work in old browsers.

Do you consider downgrading camelcase to 3.0 that exports es5 code? :)

Photo base64 data?

Does node-vcf intentionally dispose of the base64 photo data? I don't see it treated specially in the source. If this is a bug, I'll drum up a testcase...

e.g.

PHOTO;ENCODING=BASE64;JPEG:/9j/4AAQSkZJRgABAQAAAQ
 CAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAs
 2wBDAQICAgICAgUDAwUKBwYHCgoKCgoKCgoKCgoKCgoKCgoK
 goKCgoKCgoKCgoKCgr/wAARCABgAGADASIAAhEBAxEB/8QAH

Incorrect handle of value lists

According to the RFC:

The default type is "voice". These type parameter values can be
specified as a parameter list (e.g., TYPE=text;TYPE=voice) or as a
value list (e.g., TYPE="text,voice")
. The default can be
overridden to another set of values by specifying one or more
alternate values. For example, the default TYPE of "voice" can be
reset to a VOICE and FAX telephone number by the value list
TYPE="voice,fax".

Unfortunately the parse is invalid of such arguments, "text,voice" gets parsed to ["\"text", "voice\""].
For example use:

TEL;VALUE=uri;PREF=1;TYPE="voice,home":tel:+1-555-555-5555;ext=5555

The parser should eliminate the double quotes. I will make a pull request.

toString() produces cards with `\n`, not `\r\n`

Code to reproduce:

let vcf = <a card>

// Parse into vCard
const card = new vCard().parse(vcf);

// Serialize back to string
vcf = card.toString()

// Throws an exception because newlines in new vcf string are `\n` and the parser expects `\r\n`
const card = new vCard().parse(vcf);

Parsing Android contacts

Hi Jonas,

Is this the output you expect?

vCard {
  version: '2.1',
  end: [ { data: 'VCARD' }, { data: 'VCARD' } ],
  begin: [ { data: 'VCARD' }, { data: 'VCARD' } ],
  n: [ { data: 'Bawrie;Allie;;;' }, { data: 'Mickley;Andrew;;;' } ],
  fn: 'Andrew Mickley',
  tel: 
   [ { data: 'CELL;PREF:0427240757' },
     { data: 'HOME:55875233' },
     { data: 'CELL:0429015624' } ] }

For this input?

BEGIN:VCARD
VERSION:2.1
END:VCARD
BEGIN:VCARD
VERSION:2.1
N:Bawrie;Allie;;;
FN:Allie Bawrie
TEL;CELL;PREF:0427240757
TEL;HOME:55875233
END:VCARD
BEGIN:VCARD
VERSION:2.1
N:Mickley;Andrew;;;
FN:Andrew Mickley
TEL;CELL:0429015624
END:VCARD

It seems there's more raw data (and semicolons) and less being recognized/parsed than in your example.

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.