mirror of
https://github.com/aleksejs1/obsidian-contact-sync-plugin.git
synced 2026-07-22 05:48:16 +00:00
Add address to array strategy
This commit is contained in:
parent
a9e415ebc6
commit
862a44c426
2 changed files with 43 additions and 0 deletions
|
|
@ -109,4 +109,27 @@ describe('ArrayNamingStrategy Integration', () => {
|
|||
const result = formatter.generateFrontmatter(singleContact, 'contact_');
|
||||
expect(result.contact_relations).toEqual('SingleRel (partner)');
|
||||
});
|
||||
|
||||
it('should format addresses as an array', () => {
|
||||
const contactWithAddresses = {
|
||||
...contact,
|
||||
addresses: [
|
||||
{ formattedValue: '123 Main St' },
|
||||
{ formattedValue: '456 Second St' }
|
||||
]
|
||||
} as GoogleContact;
|
||||
const result = formatter.generateFrontmatter(contactWithAddresses, 'contact_');
|
||||
expect(result.contact_address).toEqual(['123 Main St', '456 Second St']);
|
||||
});
|
||||
|
||||
it('should format single address as string', () => {
|
||||
const contactWithSingleAddress = {
|
||||
...contact,
|
||||
addresses: [
|
||||
{ formattedValue: '123 Main St' }
|
||||
]
|
||||
} as GoogleContact;
|
||||
const result = formatter.generateFrontmatter(contactWithSingleAddress, 'contact_');
|
||||
expect(result.contact_address).toEqual('123 Main St');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -61,6 +61,26 @@ export class AddressAdapter implements FieldAdapter {
|
|||
});
|
||||
|
||||
return results;
|
||||
} else if (context?.namingStrategy === NamingStrategy.Array) {
|
||||
// For Array strategy, return array of formatted values
|
||||
// If only one address, return as string
|
||||
const addressValues = addresses
|
||||
.map((item) => item.formattedValue)
|
||||
.filter((val): val is string => !!val);
|
||||
|
||||
if (addressValues.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const first = addressValues[0];
|
||||
return [
|
||||
{
|
||||
value:
|
||||
addressValues.length === 1 && first !== undefined
|
||||
? first
|
||||
: addressValues,
|
||||
},
|
||||
];
|
||||
} else {
|
||||
// For Default strategy, return formattedValue as before
|
||||
return addresses
|
||||
|
|
|
|||
Loading…
Reference in a new issue