File size: 3,235 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Object.defineProperty(exports, "__esModule", {
  value: true,
});

var _typeof =
  typeof Symbol === "function" && typeof Symbol.iterator === "symbol"
    ? function(obj) {
        return typeof obj;
      }
    : function(obj) {
        return obj &&
          typeof Symbol === "function" &&
          obj.constructor === Symbol &&
          obj !== Symbol.prototype
          ? "symbol"
          : typeof obj;
      };

var _isPlainObject = require("is-plain-object");

var _isPlainObject2 = _interopRequireDefault(_isPlainObject);

var _react = require("react");

var _formatComplexDataStructure = require("./formatComplexDataStructure");

var _formatComplexDataStructure2 = _interopRequireDefault(
  _formatComplexDataStructure
);

var _formatTreeNode = require("./formatTreeNode");

var _formatTreeNode2 = _interopRequireDefault(_formatTreeNode);

var _parseReactElement = require("./../parser/parseReactElement");

var _parseReactElement2 = _interopRequireDefault(_parseReactElement);

function _interopRequireDefault(obj) {
  return obj && obj.__esModule ? obj : { default: obj };
}

var noRefCheck = function noRefCheck() {};
var escape = function escape(s) {
  return s.replace(/"/g, """);
};

var defaultFunctionValue = function defaultFunctionValue(fn) {
  return fn;
};

var formatPropValue = function formatPropValue(
  propValue,
  inline,
  lvl,
  options
) {
  if (typeof propValue === "number") {
    return "{" + String(propValue) + "}";
  }

  if (typeof propValue === "string") {
    return '"' + escape(propValue) + '"';
  }

  // > "Symbols (new in ECMAScript 2015, not yet supported in Flow)"
  // @see: https://flow.org/en/docs/types/primitives/
  // $FlowFixMe: Flow does not support Symbol
  if (
    (typeof propValue === "undefined" ? "undefined" : _typeof(propValue)) ===
    "symbol"
  ) {
    var symbolDescription = propValue
      .valueOf()
      .toString()
      .replace(/Symbol\((.*)\)/, "$1");

    if (!symbolDescription) {
      return "{Symbol()}";
    }

    return "{Symbol('" + symbolDescription + "')}";
  }

  if (typeof propValue === "function") {
    var _options$functionValu = options.functionValue,
      functionValue =
        _options$functionValu === undefined
          ? defaultFunctionValue
          : _options$functionValu,
      showFunctions = options.showFunctions;

    if (!showFunctions && functionValue === defaultFunctionValue) {
      return "{" + functionValue(noRefCheck) + "}";
    }

    return "{" + functionValue(propValue) + "}";
  }

  if ((0, _react.isValidElement)(propValue)) {
    return (
      "{" +
      (0, _formatTreeNode2.default)(
        (0, _parseReactElement2.default)(propValue, options),
        true,
        lvl,
        options
      ) +
      "}"
    );
  }

  if (propValue instanceof Date) {
    return '{new Date("' + propValue.toISOString() + '")}';
  }

  if ((0, _isPlainObject2.default)(propValue) || Array.isArray(propValue)) {
    return (
      "{" +
      (0, _formatComplexDataStructure2.default)(
        propValue,
        inline,
        lvl,
        options
      ) +
      "}"
    );
  }

  return "{" + String(propValue) + "}";
};

exports.default = formatPropValue;
//# sourceMappingURL=formatPropValue.js.map