domain-watchdog/assets/utils/functions/extractDetailsFromJCard.tsx

15 lines
536 B
TypeScript
Raw Normal View History

2024-12-30 23:50:15 +01:00
import vCard from 'vcf'
2024-12-31 13:55:42 +01:00
import type {Entity} from '../api'
2024-12-20 19:41:48 +01:00
export const extractDetailsFromJCard = (e: { entity: Entity }): {
fn?: string
2024-12-30 23:50:15 +01:00
organization?: string
2024-12-20 19:41:48 +01:00
} => {
if (e.entity.jCard.length === 0) return {fn: e.entity.handle}
const jCard = vCard.fromJSON(e.entity.jCard)
const fn = jCard.data.fn && !Array.isArray(jCard.data.fn) ? jCard.data.fn.valueOf() : undefined
const organization = jCard.data.org && !Array.isArray(jCard.data.org) ? jCard.data.org.valueOf() : undefined
return {fn, organization}
2024-12-30 23:50:15 +01:00
}