import { shallowEqual } from "shallow-equal-object"; export abstract class ValueObject { protected readonly _value: T; protected constructor(value: T) { this._value = typeof value === "object" && value !== null ? Object.freeze(value) : value; Object.freeze(this); } equals(other: ValueObject): boolean { if (!(other instanceof ValueObject)) { return false; } if (other._value === undefined || other._value === null) { return false; } return shallowEqual(this._value, other._value); } getValue(): T { return this._value; } isEmpty(): boolean { return this._value === null || this._value === undefined; } toString(): string { return this._value !== null && this._value !== undefined ? String(this._value) : ""; } }