asserts.cjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.isReadableStream = exports.isThenable = exports.isGenerator = exports.isIteratorLike = exports.isAsyncIterable = void 0;
  4. exports.isPromiseMethod = isPromiseMethod;
  5. exports.isKVMap = isKVMap;
  6. function isPromiseMethod(x) {
  7. if (x === "then" || x === "catch" || x === "finally") {
  8. return true;
  9. }
  10. return false;
  11. }
  12. function isKVMap(x) {
  13. if (typeof x !== "object" || x == null) {
  14. return false;
  15. }
  16. const prototype = Object.getPrototypeOf(x);
  17. return ((prototype === null ||
  18. prototype === Object.prototype ||
  19. Object.getPrototypeOf(prototype) === null) &&
  20. !(Symbol.toStringTag in x) &&
  21. !(Symbol.iterator in x));
  22. }
  23. const isAsyncIterable = (x) => x != null &&
  24. typeof x === "object" &&
  25. // eslint-disable-next-line @typescript-eslint/no-explicit-any
  26. typeof x[Symbol.asyncIterator] === "function";
  27. exports.isAsyncIterable = isAsyncIterable;
  28. const isIteratorLike = (x) => x != null &&
  29. typeof x === "object" &&
  30. "next" in x &&
  31. typeof x.next === "function";
  32. exports.isIteratorLike = isIteratorLike;
  33. const GeneratorFunction = function* () { }.constructor;
  34. const isGenerator = (x) =>
  35. // eslint-disable-next-line no-instanceof/no-instanceof
  36. x != null && typeof x === "function" && x instanceof GeneratorFunction;
  37. exports.isGenerator = isGenerator;
  38. const isThenable = (x) => x != null &&
  39. typeof x === "object" &&
  40. "then" in x &&
  41. typeof x.then === "function";
  42. exports.isThenable = isThenable;
  43. const isReadableStream = (x) => x != null &&
  44. typeof x === "object" &&
  45. "getReader" in x &&
  46. typeof x.getReader === "function";
  47. exports.isReadableStream = isReadableStream;