Skip to content

Introduction

@haskou/value-objects provides small immutable objects around primitive values.

A value object validates input at construction time, exposes a primitive through valueOf(), supports value equality through isEqual(), and usually provides small helpers specific to that value.

typescript
import { Email, PositiveNumber } from '@haskou/value-objects';

const email = new Email('user@example.com');
const amount = new PositiveNumber(10);

email.valueOf(); // 'user@example.com'
amount.isGreaterThan(5); // true

What the package contains

AreaClasses
BaseValueObject, NullObject, Enum
TextStringValueObject, Password, Email, Color
NumbersNumberValueObject, Integer, PositiveNumber
IDsShortId, UUID
TimeTimestamp, CalendarDay, Day, DayOfWeek, Duration, Hour, Month, MonthOfYear, TimestampInterval, Year
LocationLatitude, Longitude, Coordinates
HashesHash, MD5Hash, SHA256Hash, SHA512Hash
MediaMedia
CollectionsUniqueObjectArray
CryptoKey, PrivateKey, PublicKey, Signature, KeyPair, encrypted payload and key helpers

Design expectations

The package keeps the public API small:

  • Construct an object.
  • Let it validate itself.
  • Use valueOf(), toString(), or specific methods.
  • Catch specific errors when invalid input matters.

The library is not tied to one architecture. Use it anywhere validated values help: request parsing, config loading, persistence mapping, tests, scripts, CLI tools, or application code.

Released under the MIT License.