Logos DX
    Preparing search index...

    Function itemsToArray

    • Returns an array of items, wrapping single items in an array.

      Normalizes input to always return an array, whether the input was a single item or already an array.

      Type Parameters

      • T

      Parameters

      • items: T | T[]

        single item or array of items

      Returns T[]

      array containing the items

      itemsToArray('single') // ['single']
      itemsToArray(['already', 'array']) // ['already', 'array']
      itemsToArray(42) // [42]
      itemsToArray([]) // []
      function processFiles(files: string | string[]) {
      const fileArray = itemsToArray(files);

      for (const file of fileArray) {
      console.log(`Processing: ${file}`);
      }
      }

      processFiles('single.txt'); // Works with single file
      processFiles(['file1.txt', 'file2.txt']); // Works with multiple files