cal.pub0.org/lib/ensureArray.ts

10 lines
180 B
TypeScript

export function ensureArray<T>(val: unknown): T[] {
if (Array.isArray(val)) {
return val;
}
if (typeof val === "undefined") {
return [];
}
return [val] as T[];
}