index.js 844 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. 'use strict';
  2. var hasBigInts = require('has-bigints')();
  3. if (hasBigInts) {
  4. var bigIntValueOf = BigInt.prototype.valueOf;
  5. /** @type {(value: object) => value is BigInt} */
  6. var tryBigInt = function tryBigIntObject(value) {
  7. try {
  8. bigIntValueOf.call(value);
  9. return true;
  10. } catch (e) {
  11. }
  12. return false;
  13. };
  14. /** @type {import('.')} */
  15. module.exports = function isBigInt(value) {
  16. if (
  17. value === null
  18. || typeof value === 'undefined'
  19. || typeof value === 'boolean'
  20. || typeof value === 'string'
  21. || typeof value === 'number'
  22. || typeof value === 'symbol'
  23. || typeof value === 'function'
  24. ) {
  25. return false;
  26. }
  27. if (typeof value === 'bigint') {
  28. return true;
  29. }
  30. return tryBigInt(value);
  31. };
  32. } else {
  33. /** @type {import('.')} */
  34. module.exports = function isBigInt(value) {
  35. return false && value;
  36. };
  37. }