is.cjs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.isArrayBuffer = isArrayBuffer;
  6. exports.isCanonicalIntegerIndexString = isCanonicalIntegerIndexString;
  7. exports.isNativeBigIntTypedArray = isNativeBigIntTypedArray;
  8. exports.isNativeTypedArray = isNativeTypedArray;
  9. exports.isObject = isObject;
  10. exports.isObjectLike = isObjectLike;
  11. exports.isOrdinaryArray = isOrdinaryArray;
  12. exports.isOrdinaryNativeTypedArray = isOrdinaryNativeTypedArray;
  13. exports.isSharedArrayBuffer = isSharedArrayBuffer;
  14. var _primordials = require("./primordials.cjs");
  15. function isObject(value) {
  16. return value !== null && typeof value === "object" || typeof value === "function";
  17. }
  18. function isObjectLike(value) {
  19. return value !== null && typeof value === "object";
  20. }
  21. function isNativeTypedArray(value) {
  22. return (0, _primordials.TypedArrayPrototypeGetSymbolToStringTag)(value) !== undefined;
  23. }
  24. function isNativeBigIntTypedArray(value) {
  25. const typedArrayName = (0, _primordials.TypedArrayPrototypeGetSymbolToStringTag)(value);
  26. return typedArrayName === "BigInt64Array" || typedArrayName === "BigUint64Array";
  27. }
  28. function isArrayBuffer(value) {
  29. try {
  30. (0, _primordials.ArrayBufferPrototypeGetByteLength)(value);
  31. return true;
  32. } catch (e) {
  33. return false;
  34. }
  35. }
  36. function isSharedArrayBuffer(value) {
  37. if (_primordials.NativeSharedArrayBuffer === null) {
  38. return false;
  39. }
  40. try {
  41. (0, _primordials.SharedArrayBufferPrototypeGetByteLength)(value);
  42. return true;
  43. } catch (e) {
  44. return false;
  45. }
  46. }
  47. function isOrdinaryArray(value) {
  48. if (!(0, _primordials.ArrayIsArray)(value)) {
  49. return false;
  50. }
  51. return value[_primordials.SymbolIterator] === _primordials.NativeArrayPrototypeSymbolIterator && _primordials.ArrayIteratorPrototype.next === _primordials.ArrayIteratorPrototypeNext;
  52. }
  53. function isOrdinaryNativeTypedArray(value) {
  54. if (!isNativeTypedArray(value)) {
  55. return false;
  56. }
  57. return value[_primordials.SymbolIterator] === _primordials.NativeTypedArrayPrototypeSymbolIterator && _primordials.ArrayIteratorPrototype.next === _primordials.ArrayIteratorPrototypeNext;
  58. }
  59. function isCanonicalIntegerIndexString(value) {
  60. if (typeof value !== "string") {
  61. return false;
  62. }
  63. const number = +value;
  64. if (value !== number + "") {
  65. return false;
  66. }
  67. if (!(0, _primordials.NumberIsFinite)(number)) {
  68. return false;
  69. }
  70. return number === (0, _primordials.MathTrunc)(number);
  71. }