Skip to content

Commit

Permalink
Fix issue that unnecessary semicolons being added to the address of t…
Browse files Browse the repository at this point in the history
…he vcf when the addAddress method parameters has empty or null #60
  • Loading branch information
Janith-Umeda committed Jan 28, 2025
1 parent 36f975a commit 6139892
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
9 changes: 6 additions & 3 deletions lib/VCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,12 @@ export default class VCard {
country: string = '',
type: string = 'WORK;POSTAL',
): this {
const value = `\
${name};${extended};${street};${city};${region};${zip};${country}\
`
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()}`,
Expand Down
10 changes: 1 addition & 9 deletions test-functional/test-export.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,7 @@ vcard
.addEmail('[email protected]')
.addPhoneNumber(1234121212, 'PREF;WORK')
.addPhoneNumber(123456789, 'WORK')
.addAddress(
'name',
'extended',
'street',
'worktown',
'state',
'workpostcode',
'Belgium',
)
.addAddress()
.addURL('http://www.jeroendesloovere.be')
.addPhotoURL(
'https://cdn.jsdelivr.net/gh/joaocarmo/vcard-creator@main/lib/assets/sample.jpg',
Expand Down

0 comments on commit 6139892

Please sign in to comment.