3 Object.defineProperty(exports, '__esModule', {
6 exports.printIteratorEntries = printIteratorEntries;
7 exports.printIteratorValues = printIteratorValues;
8 exports.printListItems = printListItems;
9 exports.printObjectProperties = printObjectProperties;
11 const getSymbols = Object.getOwnPropertySymbols || (obj => []);
13 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
15 * This source code is licensed under the MIT license found in the
16 * LICENSE file in the root directory of this source tree.
21 const isSymbol = key =>
22 // $FlowFixMe string literal `symbol`. This value is not a valid `typeof` return value
23 typeof key === 'symbol' || toString.call(key) === '[object Symbol]';
25 // Return entries (for example, of a map)
26 // with spacing, indentation, and comma
27 // without surrounding punctuation (for example, braces)
28 function printIteratorEntries(
29 // Flow 0.51.0: property `@@iterator` of $Iterator not found in Object
30 // To allow simplistic getRecordIterator in immutable.js
39 arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : ': ';
42 let current = iterator.next();
45 result += config.spacingOuter;
47 const indentationNext = indentation + config.indent;
49 while (!current.done) {
57 const value = printer(
65 result += indentationNext + name + separator + value;
67 current = iterator.next();
70 result += ',' + config.spacingInner;
71 } else if (!config.min) {
76 result += config.spacingOuter + indentation;
82 // Return values (for example, of a set)
83 // with spacing, indentation, and comma
84 // without surrounding punctuation (braces or brackets)
85 function printIteratorValues(
94 let current = iterator.next();
97 result += config.spacingOuter;
99 const indentationNext = indentation + config.indent;
101 while (!current.done) {
104 printer(current.value, config, indentationNext, depth, refs);
106 current = iterator.next();
109 result += ',' + config.spacingInner;
110 } else if (!config.min) {
115 result += config.spacingOuter + indentation;
121 // Return items (for example, of an array)
122 // with spacing, indentation, and comma
123 // without surrounding punctuation (for example, brackets)
124 function printListItems(list, config, indentation, depth, refs, printer) {
128 result += config.spacingOuter;
130 const indentationNext = indentation + config.indent;
132 for (let i = 0; i < list.length; i++) {
135 printer(list[i], config, indentationNext, depth, refs);
137 if (i < list.length - 1) {
138 result += ',' + config.spacingInner;
139 } else if (!config.min) {
144 result += config.spacingOuter + indentation;
150 // Return properties of an object
151 // with spacing, indentation, and comma
152 // without surrounding punctuation (for example, braces)
153 function printObjectProperties(val, config, indentation, depth, refs, printer) {
155 let keys = Object.keys(val).sort();
156 const symbols = getSymbols(val);
158 if (symbols.length) {
159 keys = keys.filter(key => !isSymbol(key)).concat(symbols);
163 result += config.spacingOuter;
165 const indentationNext = indentation + config.indent;
167 for (let i = 0; i < keys.length; i++) {
169 const name = printer(key, config, indentationNext, depth, refs);
170 const value = printer(val[key], config, indentationNext, depth, refs);
172 result += indentationNext + name + ': ' + value;
174 if (i < keys.length - 1) {
175 result += ',' + config.spacingInner;
176 } else if (!config.min) {
181 result += config.spacingOuter + indentation;