hz-zhhq-web/node_modules/pretty-format/build/plugins/dom_collection.js

71 lines
1.4 KiB
JavaScript
Raw Normal View History

2025-02-25 13:46:30 +08:00
'use strict';
Object.defineProperty(exports, '__esModule', {
value: true
});
exports.serialize = exports.test = undefined;
var _collections = require('../collections');
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
const SPACE = ' ';
const COLLECTION_NAMES = ['DOMStringMap', 'NamedNodeMap'];
const test = (exports.test = val =>
val &&
val.constructor &&
COLLECTION_NAMES.indexOf(val.constructor.name) !== -1);
const convertCollectionToObject = collection => {
let result = {};
if (collection.constructor.name === 'NamedNodeMap') {
for (let i = 0; i < collection.length; i++) {
result[collection[i].name] = collection[i].value;
}
} else {
result = Object.assign({}, collection);
}
return result;
};
const serialize = (exports.serialize = (
collection,
config,
indentation,
depth,
refs,
printer
) => {
if (++depth > config.maxDepth) {
return '[' + collection.constructor.name + ']';
}
return (
collection.constructor.name +
SPACE +
'{' +
(0, _collections.printObjectProperties)(
convertCollectionToObject(collection),
config,
indentation,
depth,
refs,
printer
) +
'}'
);
});
exports.default = {serialize: serialize, test: test};