@serenity-js/core
Version:
The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure
34 lines • 1.44 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.inspectedObject = inspectedObject;
const node_util_1 = __importDefault(require("node:util"));
const reflection_1 = require("./reflection");
function inspectedObject(value, allowFields) {
return function (depth, options, inspect = node_util_1.default.inspect) {
const typeName = options.stylize(reflection_1.ValueInspector.typeOf(value), 'special');
if (depth < 0) {
return typeName;
}
const fields = Object.getOwnPropertyNames(value)
.filter(field => typeof value[field] !== 'function')
.filter(field => allowFields ? allowFields.includes(field) : true)
.sort();
if (fields.length === 0) {
return `${typeName} { }`;
}
const newOptions = Object.assign({}, options, {
depth: options?.depth > 0
? options.depth - 1
: undefined,
});
const padding = ' '.repeat(2);
const lines = fields.flatMap(field => `${field}: ${inspect(value[field], newOptions)}`
.split('\n')
.map(line => `${padding}${line}`)).join('\n');
return `${typeName} {\n${lines}\n}`;
};
}
//# sourceMappingURL=inspectedObject.js.map
;