function circularReplacer(options = { maxSafeObjectSize: Infinity }) {
	const seen = new WeakSet();
	return function (key, value) {
		if (typeof value === "object" && value !== null) {
			const objectType = (value.constructor && value.constructor.name) || typeof value;

			if (
				options.maxSafeObjectSize &&
				"length" in value &&
				value.length > options.maxSafeObjectSize
			) {
				return `[${objectType} ${value.length}]`;
			}

			if (
				options.maxSafeObjectSize &&
				"size" in value &&
				value.size > options.maxSafeObjectSize
			) {
				return `[${objectType} ${value.size}]`;
			}

			if (seen.has(value)) {
				//delete this[key];
				return;
			}
			seen.add(value);
		}
		return value;
	};
}
Circular replacing of unsafe properties in object

@param {Object=} options List of options to change circularReplacer behaviour
@param {number=} options.maxSafeObjectSize Maximum size of objects for safe object converting
@return {function(...[*]=)}