<< All versions

Skill v1.0.0

currentLLM-judged scan90/100
senrecep/tsentials/tsentials-ord
──Details
PublishedOctober 17, 2026 at 05:13 AM
Content Hashsha256:6b873d4deae8380c...
Git SHA6d0b493b3193
──Files
Files (1 file, 1.3 KB)
SKILL.md1.3 KBactive
SKILL.md · 47 lines · 1.3 KB

version: "1.0.0"


tsentials/ord — Skill

Use when you need type-safe sorting, min/max, or range clamping.

API

typescript
import { Ord, sortBy, min, max, clamp, between } from 'tsentials/ord';
import type { Ordering } from 'tsentials/ord'; // -1 | 0 | 1
// Primitive ordering
Ord.number.compare(1, 2); // -1
Ord.string.compare('b', 'a'); // 1
Ord.boolean.compare(false, true); // -1 (false < true)
Ord.date.compare(d1, d2); // chronological
// Reverse ordering
const desc = Ord.reverse(Ord.number);
// Project before comparing
interface User { readonly name: string; readonly age: number; }
const byAge = Ord.contramap(Ord.number, (u: User) => u.age);
// Struct ordering (multi-field, lexicographic)
const byNameThenAge = Ord.struct<User>({ name: Ord.string, age: Ord.number });
// Sort an array
sortBy([3, 1, 4], Ord.number); // [1, 3, 4]
// Min / max
min(Ord.number, 1, 2); // 1
max(Ord.number, 1, 2); // 2
// Range checks
clamp(Ord.number, 0, 10, 15); // 10
between(Ord.number, 0, 10, 5); // true

Patterns

  • Use Ord.contramap to sort arrays of objects by a specific field.
  • Use Ord.struct for lexicographic multi-field ordering (compares fields in order, short-circuits on first difference).
  • Use clamp to ensure values stay within bounds.
All versions