_to_primitive.js 750 B

123456789101112131415161718192021
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = _toPrimitive;
  6. var _typeOfMjs = _interopRequireDefault(require("./_type_of.js"));
  7. function _toPrimitive(input, hint) {
  8. if ((0, _typeOfMjs).default(input) !== "object" || input === null) return input;
  9. var prim = input[Symbol.toPrimitive];
  10. if (prim !== undefined) {
  11. var res = prim.call(input, hint || "default");
  12. if ((0, _typeOfMjs).default(res) !== "object") return res;
  13. throw new TypeError("@@toPrimitive must return a primitive value.");
  14. }
  15. return (hint === "string" ? String : Number)(input);
  16. }
  17. function _interopRequireDefault(obj) {
  18. return obj && obj.__esModule ? obj : {
  19. default: obj
  20. };
  21. }