defineToJSON.js 804 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = defineToJSON;
  6. var _nodejsCustomInspectSymbol = _interopRequireDefault(require("./nodejsCustomInspectSymbol"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. /**
  9. * The `defineToJSON()` function defines toJSON() and inspect() prototype
  10. * methods, if no function provided they become aliases for toString().
  11. */
  12. function defineToJSON(classObject) {
  13. var fn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : classObject.prototype.toString;
  14. classObject.prototype.toJSON = fn;
  15. classObject.prototype.inspect = fn;
  16. if (_nodejsCustomInspectSymbol.default) {
  17. classObject.prototype[_nodejsCustomInspectSymbol.default] = fn;
  18. }
  19. }