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.

15 lines
482 B

4 years ago
  1. var _typeof = require("../helpers/typeof");
  2. function _toPrimitive(input, hint) {
  3. if (_typeof(input) !== "object" || input === null) return input;
  4. var prim = input[Symbol.toPrimitive];
  5. if (prim !== undefined) {
  6. var res = prim.call(input, hint || "default");
  7. if (_typeof(res) !== "object") return res;
  8. throw new TypeError("@@toPrimitive must return a primitive value.");
  9. }
  10. return (hint === "string" ? String : Number)(input);
  11. }
  12. module.exports = _toPrimitive;