# khard.formatter

Formatting and sorting of contacts

## Classes

`Formatter` | A formatter for Contact.

## Module Contents

class khard.formatter.Formatter(display: str, preferred_email: list[str], preferred_phone: list[str], show_nicknames: bool, parsable: bool)

  A formatter for Contact.

  It receives some settings on initialisation which influence the formatting of the contact.

  FIRST = 'first_name'
  LAST = 'last_name'
  FORMAT = 'formatted_name'
  _display
  _preferred_email
  _preferred_phone
  _show_nicknames
  _parsable
  static format_labeled_field(field: dict[str, list[str]], preferred: list[str]) → str

    Format a labeled field from a vCard for display, the first entry under the preferred label will be returned

    Parameters:

      - field – the labeled field, this must not be empty!

      - preferred – the order of preferred labels

    Returns:

      the formatted field entry

  get_special_field(vcard: khard.contacts.Contact, field: str) → str

    Returns certain fields with specific formatting options (for support of some list command options).

  static get_nested_field(vcard: khard.contacts.Contact, field: str) → str

    Returns the value of a nested field from a string

    get_nested_field(vcard,’emails.home.1’) is equivalent to vcard.emails[‘home’][1].

    Parameters:

      - vcard – the contact from which to get the field

      - field – a field specification

    Returns:

      the nested field, or the empty string if it didn’t exist