@serenity-js/core
Version:
The core Serenity/JS framework, providing the Screenplay Pattern interfaces, as well as the test reporting and integration infrastructure
28 lines • 1.14 kB
JavaScript
import util from 'node:util';
import { ValueInspector } from './reflection/index.js';
export function inspectedObject(value, allowFields) {
return function (depth, options, inspect = util.inspect) {
const typeName = options.stylize(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