change-string-case/node_modules/@octokit/plugin-paginate-rest/dist-src/normalize-paginated-list-response.js

32 lines
1.0 KiB
JavaScript
Raw Normal View History

2023-10-26 04:27:07 +08:00
function normalizePaginatedListResponse(response) {
if (!response.data) {
return {
...response,
data: []
};
}
const responseNeedsNormalization = "total_count" in response.data && !("url" in response.data);
if (!responseNeedsNormalization)
2022-11-04 00:55:07 +08:00
return response;
2023-10-26 04:27:07 +08:00
const incompleteResults = response.data.incomplete_results;
const repositorySelection = response.data.repository_selection;
const totalCount = response.data.total_count;
delete response.data.incomplete_results;
delete response.data.repository_selection;
delete response.data.total_count;
const namespaceKey = Object.keys(response.data)[0];
const data = response.data[namespaceKey];
response.data = data;
if (typeof incompleteResults !== "undefined") {
response.data.incomplete_results = incompleteResults;
}
if (typeof repositorySelection !== "undefined") {
response.data.repository_selection = repositorySelection;
}
response.data.total_count = totalCount;
return response;
2022-11-04 00:55:07 +08:00
}
2023-10-26 04:27:07 +08:00
export {
normalizePaginatedListResponse
};