Skip to content

v1.1.0 — Equatable & Cloneable contracts

Choose a tag to compare

@cyberash-dev cyberash-dev released this 15 Apr 21:57
· 4 commits to main since this release

Highlights

Two new cross-cutting contracts for value-object types are introduced, and Point is the first to adopt them.

What's new

Equatable<T>

interface Equatable<T> {
  isEqualWith(other: T): boolean;
}

Purpose: explicit, type-safe value equality for immutable types.

Cloneable<T>

interface Cloneable<T> {
  clone(): T;
}

Purpose: request an independent copy of a value object without relying on structural tricks.

Point now implements both

const a = new Point(3, 5);
const b = a.clone();

a.isEqualWith(b); // true
a === b;          // false
  • Point.isEqualWith uses exact coordinate equality (===). No epsilon tolerance — this keeps behavior predictable; use toBeCloseTo in tests or a dedicated helper when floating-point slack is needed.
  • Point.clone() returns a brand-new Point instance with identical coordinates.

Public API additions

  • Equatable<T> — exported from the root of the package.
  • Cloneable<T> — exported from the root of the package.
  • Point.isEqualWith(other: Point): boolean
  • Point.clone(): Point

Internal changes

  • New directory src/contracts/ hosts cross-cutting interfaces. Re-exported via src/index.ts.
  • CI pipeline (.github/workflows/ci.yml) and publish pipeline (.github/workflows/publish.yml) added.
  • Biome rule style.useBlockStatements: error enabled.

Tests & coverage

  • Test count: 132 → 142 (9 new tests for isEqualWith / clone, plus one Polyline test tweak).
  • Coverage stays at 100% on statements, branches, functions, and lines.

Compatibility

  • Non-breaking. All prior APIs are unchanged.
  • Node.js >= 18, TypeScript >= 4.5.

What's next

  • Adopt Equatable / Cloneable on BoundingBox, Segment, Polyline, Rectangle, and ShapeGroup in a follow-up release.

Full changelog: v1.0.0...v1.1.0