flattenArray.js 350 B

12345678910111213141516
  1. 'use strict';
  2. /**
  3. * Convert the specified value to an array. If an array is specified, the array is returned as-is.
  4. *
  5. * @template T
  6. * @param {T | T[] | undefined | null} value
  7. * @returns {T[] | undefined}
  8. */
  9. module.exports = function flattenArray(value) {
  10. if (value == null) {
  11. return;
  12. }
  13. return Array.isArray(value) ? value : [value];
  14. };