UNPKG

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