UNPKG

1.45 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = inspect;
7
8function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
9
10/**
11 * Copyright (c) 2015-present, Facebook, Inc.
12 *
13 * This source code is licensed under the MIT license found in the
14 * LICENSE file in the root directory of this source tree.
15 *
16 * strict
17 */
18
19/**
20 * Used to print values in error messages.
21 */
22function inspect(value) {
23 switch (_typeof(value)) {
24 case 'string':
25 return JSON.stringify(value);
26
27 case 'function':
28 return value.name ? "[function ".concat(value.name, "]") : '[function]';
29
30 case 'object':
31 if (value) {
32 if (typeof value.inspect === 'function') {
33 return value.inspect();
34 } else if (Array.isArray(value)) {
35 return '[' + value.map(inspect).join(', ') + ']';
36 }
37
38 var properties = Object.keys(value).map(function (k) {
39 return "".concat(k, ": ").concat(inspect(value[k]));
40 }).join(', ');
41 return properties ? '{ ' + properties + ' }' : '{}';
42 }
43
44 return String(value);
45
46 default:
47 return String(value);
48 }
49}
\No newline at end of file