1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', {
|
4 | value: true
|
5 | });
|
6 | exports.default = exports.serialize = exports.test = void 0;
|
7 |
|
8 | var _collections = require('../collections');
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | const SPACE = ' ';
|
19 | const OBJECT_NAMES = ['DOMStringMap', 'NamedNodeMap'];
|
20 | const ARRAY_REGEXP = /^(HTML\w*Collection|NodeList)$/;
|
21 |
|
22 | const testName = name =>
|
23 | OBJECT_NAMES.indexOf(name) !== -1 || ARRAY_REGEXP.test(name);
|
24 |
|
25 | const test = val =>
|
26 | val &&
|
27 | val.constructor &&
|
28 | !!val.constructor.name &&
|
29 | testName(val.constructor.name);
|
30 |
|
31 | exports.test = test;
|
32 |
|
33 | const isNamedNodeMap = collection =>
|
34 | collection.constructor.name === 'NamedNodeMap';
|
35 |
|
36 | const serialize = (collection, config, indentation, depth, refs, printer) => {
|
37 | const name = collection.constructor.name;
|
38 |
|
39 | if (++depth > config.maxDepth) {
|
40 | return '[' + name + ']';
|
41 | }
|
42 |
|
43 | return (
|
44 | (config.min ? '' : name + SPACE) +
|
45 | (OBJECT_NAMES.indexOf(name) !== -1
|
46 | ? '{' +
|
47 | (0, _collections.printObjectProperties)(
|
48 | isNamedNodeMap(collection)
|
49 | ? Array.from(collection).reduce((props, attribute) => {
|
50 | props[attribute.name] = attribute.value;
|
51 | return props;
|
52 | }, {})
|
53 | : {...collection},
|
54 | config,
|
55 | indentation,
|
56 | depth,
|
57 | refs,
|
58 | printer
|
59 | ) +
|
60 | '}'
|
61 | : '[' +
|
62 | (0, _collections.printListItems)(
|
63 | Array.from(collection),
|
64 | config,
|
65 | indentation,
|
66 | depth,
|
67 | refs,
|
68 | printer
|
69 | ) +
|
70 | ']')
|
71 | );
|
72 | };
|
73 |
|
74 | exports.serialize = serialize;
|
75 | const plugin = {
|
76 | serialize,
|
77 | test
|
78 | };
|
79 | var _default = plugin;
|
80 | exports.default = _default;
|