.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / pretty-format / build / plugins / dom_collection.js
1 'use strict';
2
3 Object.defineProperty(exports, '__esModule', {
4   value: true
5 });
6 exports.serialize = exports.test = undefined;
7
8 var _collections = require('../collections');
9
10 /**
11  * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
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  *
17  */
18
19 const SPACE = ' ';
20
21 const COLLECTION_NAMES = ['DOMStringMap', 'NamedNodeMap'];
22
23 const test = (exports.test = val =>
24   val &&
25   val.constructor &&
26   COLLECTION_NAMES.indexOf(val.constructor.name) !== -1);
27
28 const convertCollectionToObject = collection => {
29   let result = {};
30
31   if (collection.constructor.name === 'NamedNodeMap') {
32     for (let i = 0; i < collection.length; i++) {
33       result[collection[i].name] = collection[i].value;
34     }
35   } else {
36     result = Object.assign({}, collection);
37   }
38
39   return result;
40 };
41
42 const serialize = (exports.serialize = (
43   collection,
44   config,
45   indentation,
46   depth,
47   refs,
48   printer
49 ) => {
50   if (++depth > config.maxDepth) {
51     return '[' + collection.constructor.name + ']';
52   }
53
54   return (
55     collection.constructor.name +
56     SPACE +
57     '{' +
58     (0, _collections.printObjectProperties)(
59       convertCollectionToObject(collection),
60       config,
61       indentation,
62       depth,
63       refs,
64       printer
65     ) +
66     '}'
67   );
68 });
69
70 exports.default = {serialize: serialize, test: test};