vcard-creator icon indicating copy to clipboard operation
vcard-creator copied to clipboard

Fix issue that unnecessary semicolons being added to the address of the vcf when the addAddress method parameters has empty or null

Open Janith-Umeda opened this issue 4 weeks ago • 0 comments

As you can see in the screenshot below, there is 'null' and unnecessary ';' characters appears when the addAddress method's args has null values.

like this ⬇

.addAddress(
    'name',
    'extended',
    null,
    'worktown',
    'state',
    undefined,
    'Belgium',
)

Image

So i've fixed this issue by pushing all parameters to an array and then filter good values among them and join them to one string with ';'.

  public addAddress(
    name: string = '',
    extended: string = '',
    street: string = '',
    city: string = '',
    region: string = '',
    zip: string = '',
    country: string = '',
    type: string = 'WORK;POSTAL',
  ): this {
    const value = [name, extended, street, city, region, zip, country]
      .filter((part) => part !== null && part !== '')
      .join(';')

    if (value === '') return this

    this.setProperty(
      'address',
      `ADR${type !== '' ? `;${type}` : ''}${this.getCharsetString()}`,
      value,
    )

    return this
  }

Image

Hope this will helpfull for someone

Janith-Umeda avatar Jan 27 '25 19:01 Janith-Umeda