Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Janith-Umeda opened this issue Jan 27, 2025 · 0 comments

Comments

@Janith-Umeda
Copy link

Janith-Umeda commented Jan 27, 2025

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 added a commit to Janith-Umeda/vcard-creator that referenced this issue Jan 27, 2025
…he vcf when the addAddress method parameters has empty or null (joaocarmo#60)
Janith-Umeda added a commit to Janith-Umeda/vcard-creator that referenced this issue Jan 27, 2025
…he vcf when the addAddress method parameters has empty or null (joaocarmo#60)
Janith-Umeda added a commit to Janith-Umeda/vcard-creator that referenced this issue Jan 28, 2025
…he vcf when the addAddress method parameters has empty or null joaocarmo#60
Janith-Umeda added a commit to Janith-Umeda/vcard-creator that referenced this issue Jan 28, 2025
…he vcf when the addAddress method parameters has empty or null joaocarmo#60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant