ChemPal Documentation - v1.6.0
    Preparing search index...
    • 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. image may be a single URL or a list).

      Type Parameters

      Parameters

      • value: undefined | T | T[]

        A single value, an array of values, undefined, or null.

      Returns T[]

      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];
      }