from pathlib import Path
import yaml
import json


def _read_data_file(path):
    """
    Read the contents of a data file in JSON, YAML or BibTeX format.

    Parameters
    ----------
    path : :class:`pathlib.Path`
        The path of the JSON or YAML data file.

    Returns
    -------
    data : dict
        The contents of the file as a dictionary.
    """
    path = Path(path)
    suffix = path.suffix
    loader = {".yml": yaml.safe_load, ".yaml": yaml.safe_load, ".json": json.loads}
    data = loader[suffix](path.read_text(encoding="utf-8"))
    return data