Move isDefined from start-proxy to util

This commit is contained in:
Michael B. Gale
2025-09-01 15:14:57 +01:00
parent 244e04cc4a
commit 811aef84cb
3 changed files with 13 additions and 13 deletions

View File

@@ -2,7 +2,7 @@ import * as core from "@actions/core";
import { KnownLanguage } from "./languages";
import { Logger } from "./logging";
import { ConfigurationError } from "./util";
import { ConfigurationError, isDefined } from "./util";
export type Credential = {
type: string;
@@ -65,15 +65,6 @@ const LANGUAGE_TO_REGISTRY_TYPE: Partial<Record<KnownLanguage, string>> = {
go: "goproxy_server",
} as const;
/**
* Checks that `value` is neither `undefined` nor `null`.
* @param value The value to test.
* @returns Narrows the type of `value` to exclude `undefined` and `null`.
*/
function isDefined<T>(value: T | null | undefined): value is T {
return value !== undefined && value !== null;
}
// getCredentials returns registry credentials from action inputs.
// It prefers `registries_credentials` over `registry_secrets`.
// If neither is set, it returns an empty array.

View File

@@ -1278,3 +1278,12 @@ export async function asyncSome<T>(
const results = await Promise.all(array.map(predicate));
return results.some((result) => result);
}
/**
* Checks that `value` is neither `undefined` nor `null`.
* @param value The value to test.
* @returns Narrows the type of `value` to exclude `undefined` and `null`.
*/
export function isDefined<T>(value: T | null | undefined): value is T {
return value !== undefined && value !== null;
}