UNPKG

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