提交学习笔记专用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

16 lines
721 B

  1. /** Returns whether the payload is an iterable (regular or async) */
  2. export function isIterable(payload) {
  3. // oxlint-disable-next-line no-typeof-undefined
  4. if (typeof Symbol === 'undefined' || typeof Symbol.iterator === 'undefined') {
  5. return false;
  6. }
  7. // oxlint-disable-next-line no-null
  8. if (payload === null || payload === undefined)
  9. return false;
  10. // Strings are iterable, even though they're primitives.
  11. if (typeof payload === 'string')
  12. return true;
  13. // For objects, arrays and functions, check if Symbol.iterator is a function.
  14. return ((typeof payload === 'object' || typeof payload === 'function') &&
  15. typeof payload[Symbol.iterator] === 'function');
  16. }