lib/vcard.js
function( value ) {

    // Normalize & split
    var lines = vCard.normalize( value )
      .split( /\r?\n/g )

    // Keep begin and end markers
    // for eventual error messages
    var begin = lines[0]
    var version = lines[1]
    var end = lines[ lines.length - 1 ]

    if( !/BEGIN:VCARD/i.test( begin ) )
      throw new SyntaxError( 'Invalid vCard: Expected "BEGIN:VCARD" but found "'+ begin +'"' )

    if( !/END:VCARD/i.test( end ) )
      throw new SyntaxError( 'Invalid vCard: Expected "END:VCARD" but found "'+ end +'"' )

    // TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END
    if( !/VERSION:\d\.\d/i.test( version ) )
      throw new SyntaxError( 'Invalid vCard: Expected "VERSION:\\d.\\d" but found "'+ version +'"' )

    this.version = version.substring( 8, 11 )

    if( !vCard.isSupported( this.version ) )
      throw new Error( 'Unsupported version "' + this.version + '"' )

    this.data = vCard.parseLines( lines )

    return this

  }
function( value ) {

    // Normalize & split
    var lines = vCard.normalize( value )
      .split( /\r?\n/g )

    // Keep begin and end markers
    // for eventual error messages
    var begin = lines[0]
    var version = lines[1]
    var end = lines[ lines.length - 1 ]

    if( !/BEGIN:VCARD/i.test( begin ) )
      throw new SyntaxError( 'Invalid vCard: Expected "BEGIN:VCARD" but found "'+ begin +'"' )

    if( !/END:VCARD/i.test( end ) )
      throw new SyntaxError( 'Invalid vCard: Expected "END:VCARD" but found "'+ end +'"' )

    // TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END
    if( !/VERSION:\d\.\d/i.test( version ) )
      throw new SyntaxError( 'Invalid vCard: Expected "VERSION:\\d.\\d" but found "'+ version +'"' )

    this.version = version.substring( 8, 11 )

    if( !vCard.isSupported( this.version ) )
      throw new Error( 'Unsupported version "' + this.version + '"' )

    this.data = vCard.parseLines( lines )

    return this

  }
function ( value ) { // Normalize & split var lines = vCard . normalize ( value ) . split ( / \r?\n / g ) // Keep begin and end markers // for eventual error messages var begin = lines [ 0 ] var version = lines [ 1 ] var end = lines [ lines . length - 1 ] if ( ! / BEGIN:VCARD / i . test ( begin ) ) throw new SyntaxError ( 'Invalid vCard: Expected "BEGIN:VCARD" but found "' + begin + '"' ) if ( ! / END:VCARD / i . test ( end ) ) throw new SyntaxError ( 'Invalid vCard: Expected "END:VCARD" but found "' + end + '"' ) // TODO: For version 2.1, the VERSION can be anywhere between BEGIN & END if ( ! / VERSION:\d\.\d / i . test ( version ) ) throw new SyntaxError ( 'Invalid vCard: Expected "VERSION:\\d.\\d" but found "' + version + '"' ) this . version = version . substring ( 8 , 11 ) if ( ! vCard . isSupported ( this . version ) ) throw new Error ( 'Unsupported version "' + this . version + '"' ) this . data = vCard . parseLines ( lines ) return this }
Parse a vcf formatted vCard
@param  {String} value
@return {vCard}
Parse a vcf formatted vCard