Element type of the value(s).
An array: [] for nullish input, the input unchanged if already an
array, otherwise a one-element array.
toArray('a.jpg'); // ['a.jpg']
toArray(['a.jpg', 'b.jpg']); // ['a.jpg', 'b.jpg']
toArray(undefined); // []
export function toArray<T = JsonValue>(value: T | T[] | undefined): T[] {
if (value === undefined || value === null) return [];
return Array.isArray(value) ? value : [value];
}
Normalize a possibly-single, possibly-repeated property value to an array. schema.org allows any property to carry one value or many, so wrapping is the safe way to iterate (e.g.
imagemay be a single URL or a list).