.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / pretty-format / build / collections.js
1 'use strict';
2
3 Object.defineProperty(exports, '__esModule', {
4   value: true
5 });
6 exports.printIteratorEntries = printIteratorEntries;
7 exports.printIteratorValues = printIteratorValues;
8 exports.printListItems = printListItems;
9 exports.printObjectProperties = printObjectProperties;
10
11 const getSymbols = Object.getOwnPropertySymbols || (obj => []);
12 /**
13  * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
14  *
15  * This source code is licensed under the MIT license found in the
16  * LICENSE file in the root directory of this source tree.
17  *
18  *
19  */
20
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]';
24
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
31   iterator,
32   config,
33   indentation,
34   depth,
35   refs,
36   printer
37 ) {
38   let separator =
39     arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : ': ';
40
41   let result = '';
42   let current = iterator.next();
43
44   if (!current.done) {
45     result += config.spacingOuter;
46
47     const indentationNext = indentation + config.indent;
48
49     while (!current.done) {
50       const name = printer(
51         current.value[0],
52         config,
53         indentationNext,
54         depth,
55         refs
56       );
57       const value = printer(
58         current.value[1],
59         config,
60         indentationNext,
61         depth,
62         refs
63       );
64
65       result += indentationNext + name + separator + value;
66
67       current = iterator.next();
68
69       if (!current.done) {
70         result += ',' + config.spacingInner;
71       } else if (!config.min) {
72         result += ',';
73       }
74     }
75
76     result += config.spacingOuter + indentation;
77   }
78
79   return result;
80 }
81
82 // Return values (for example, of a set)
83 // with spacing, indentation, and comma
84 // without surrounding punctuation (braces or brackets)
85 function printIteratorValues(
86   iterator,
87   config,
88   indentation,
89   depth,
90   refs,
91   printer
92 ) {
93   let result = '';
94   let current = iterator.next();
95
96   if (!current.done) {
97     result += config.spacingOuter;
98
99     const indentationNext = indentation + config.indent;
100
101     while (!current.done) {
102       result +=
103         indentationNext +
104         printer(current.value, config, indentationNext, depth, refs);
105
106       current = iterator.next();
107
108       if (!current.done) {
109         result += ',' + config.spacingInner;
110       } else if (!config.min) {
111         result += ',';
112       }
113     }
114
115     result += config.spacingOuter + indentation;
116   }
117
118   return result;
119 }
120
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) {
125   let result = '';
126
127   if (list.length) {
128     result += config.spacingOuter;
129
130     const indentationNext = indentation + config.indent;
131
132     for (let i = 0; i < list.length; i++) {
133       result +=
134         indentationNext +
135         printer(list[i], config, indentationNext, depth, refs);
136
137       if (i < list.length - 1) {
138         result += ',' + config.spacingInner;
139       } else if (!config.min) {
140         result += ',';
141       }
142     }
143
144     result += config.spacingOuter + indentation;
145   }
146
147   return result;
148 }
149
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) {
154   let result = '';
155   let keys = Object.keys(val).sort();
156   const symbols = getSymbols(val);
157
158   if (symbols.length) {
159     keys = keys.filter(key => !isSymbol(key)).concat(symbols);
160   }
161
162   if (keys.length) {
163     result += config.spacingOuter;
164
165     const indentationNext = indentation + config.indent;
166
167     for (let i = 0; i < keys.length; i++) {
168       const key = keys[i];
169       const name = printer(key, config, indentationNext, depth, refs);
170       const value = printer(val[key], config, indentationNext, depth, refs);
171
172       result += indentationNext + name + ': ' + value;
173
174       if (i < keys.length - 1) {
175         result += ',' + config.spacingInner;
176       } else if (!config.min) {
177         result += ',';
178       }
179     }
180
181     result += config.spacingOuter + indentation;
182   }
183
184   return result;
185 }