Move getHeaderValueAsString to separate utils file

This commit is contained in:
Sander Declerck 2025-11-24 15:08:31 +01:00
parent 78c8da6fae
commit 9a1092199d
No known key found for this signature in database
2 changed files with 20 additions and 18 deletions

View file

@ -0,0 +1,17 @@
/**
* @param {NodeJS.Dict<string | string[]> | undefined} headers
* @param {string} headerName
*/
export function getHeaderValueAsString(headers, headerName) {
if (!headers) {
return undefined;
}
let header = headers[headerName];
if (Array.isArray(header)) {
return header.join(", ");
}
return header;
}

View file

@ -1,5 +1,6 @@
import { getMinimumPackageAgeHours } from "../../../config/settings.js"; import { getMinimumPackageAgeHours } from "../../../config/settings.js";
import { ui } from "../../../environment/userInteraction.js"; import { ui } from "../../../environment/userInteraction.js";
import { getHeaderValueAsString } from "../../http-utils.js";
const state = { const state = {
hasSuppressedVersions: false, hasSuppressedVersions: false,
@ -80,6 +81,8 @@ export function modifyNpmInfoResponse(body, headers) {
continue; continue;
} }
// Timestamps are compared as strings.
// This can be done because they are formatted in ISO8601, which is sortable.
if (timestamp > cutOff) { if (timestamp > cutOff) {
deleteVersionFromJson(bodyJson, version); deleteVersionFromJson(bodyJson, version);
if (headers) { if (headers) {
@ -173,21 +176,3 @@ function getMostRecentTag(tagList) {
export function getHasSuppressedVersions() { export function getHasSuppressedVersions() {
return state.hasSuppressedVersions; return state.hasSuppressedVersions;
} }
/**
* @param {NodeJS.Dict<string | string[]> | undefined} headers
* @param {string} headerName
*/
function getHeaderValueAsString(headers, headerName) {
if (!headers) {
return undefined;
}
let header = headers[headerName];
if (Array.isArray(header)) {
return header.join(", ");
}
return header;
}