toPrimitive.js 407 B

123456789101112
  1. import _typeof from "./typeof.js";
  2. function toPrimitive(t, r) {
  3. if ("object" != _typeof(t) || !t) return t;
  4. var e = t[Symbol.toPrimitive];
  5. if (void 0 !== e) {
  6. var i = e.call(t, r || "default");
  7. if ("object" != _typeof(i)) return i;
  8. throw new TypeError("@@toPrimitive must return a primitive value.");
  9. }
  10. return ("string" === r ? String : Number)(t);
  11. }
  12. export { toPrimitive as default };