to-big-int.js 405 B

123456789101112
  1. var toPrimitive = require('../internals/to-primitive');
  2. var $TypeError = TypeError;
  3. // `ToBigInt` abstract operation
  4. // https://tc39.es/ecma262/#sec-tobigint
  5. module.exports = function (argument) {
  6. var prim = toPrimitive(argument, 'number');
  7. if (typeof prim == 'number') throw $TypeError("Can't convert number to bigint");
  8. // eslint-disable-next-line es/no-bigint -- safe
  9. return BigInt(prim);
  10. };