Changeset View
Changeset View
Standalone View
Standalone View
swh/loader/package/npm/loader.py
Show First 20 Lines • Show All 181 Lines • ▼ Show 20 Lines | |||||
def _author_str(author_data): | def _author_str(author_data): | ||||
"""Parse author from package.json author fields | """Parse author from package.json author fields | ||||
""" | """ | ||||
if type(author_data) is dict: | if type(author_data) is dict: | ||||
author_str = "" | author_str = "" | ||||
if "name" in author_data: | name = author_data.get("name") | ||||
author_str += author_data["name"] | if name is not None: | ||||
if "email" in author_data: | if type(name) is str: | ||||
author_str += " <%s>" % author_data["email"] | author_str += name | ||||
return author_str | elif type(name) is list: | ||||
author_str += name[0] if len(name) > 0 else "" | |||||
email = author_data.get("email") | |||||
if email is not None: | |||||
author_str += f" <{email}>" | |||||
result = author_str | |||||
elif type(author_data) is list: | elif type(author_data) is list: | ||||
return _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: | ||||
return author_data | result = author_data | ||||
return result | |||||
def extract_npm_package_author(package_json) -> Person: | def extract_npm_package_author(package_json) -> Person: | ||||
""" | """ | ||||
Extract package author from a ``package.json`` file content and | Extract package author from a ``package.json`` file content and | ||||
return it in swh format. | return it in swh format. | ||||
Args: | Args: | ||||
▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines |