Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/loader.py
Show First 20 Lines • Show All 183 Lines • ▼ Show 20 Lines | |||||
def _author_str(author_data: Union[Dict, List, str]) -> str: | def _author_str(author_data: Union[Dict, List, str]) -> str: | ||||
"""Parse author from package.json author fields | """Parse author from package.json author fields | ||||
""" | """ | ||||
if isinstance(author_data, dict): | if isinstance(author_data, dict): | ||||
author_str = "" | author_str = "" | ||||
name = author_data.get("name") | name = author_data.get("name") | ||||
if name is not None: | if name is not None: | ||||
if isinstance(name, str): | |||||
author_str += name | author_str += name | ||||
elif isinstance(name, list): | |||||
author_str += _author_str(name[0]) if len(name) > 0 else "" | |||||
email = author_data.get("email") | email = author_data.get("email") | ||||
if email is not None: | if email is not None: | ||||
author_str += f" <{email}>" | author_str += f" <{email}>" | ||||
result = author_str | result = author_str | ||||
elif isinstance(author_data, list): | elif isinstance(author_data, list): | ||||
result = _author_str(author_data[0]) if len(author_data) > 0 else "" | result = _author_str(author_data[0]) if len(author_data) > 0 else "" | ||||
else: | else: | ||||
result = author_data | result = author_data | ||||
▲ Show 20 Lines • Show All 93 Lines • Show Last 20 Lines |