vcard-creator
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
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',
)
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
}
Hope this will helpfull for someone