<< All versions
Skill v1.0.0
currentLLM-judged scan90/100senrecep/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 orderingOrd.number.compare(1, 2); // -1Ord.string.compare('b', 'a'); // 1Ord.boolean.compare(false, true); // -1 (false < true)Ord.date.compare(d1, d2); // chronological// Reverse orderingconst desc = Ord.reverse(Ord.number);// Project before comparinginterface 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 arraysortBy([3, 1, 4], Ord.number); // [1, 3, 4]// Min / maxmin(Ord.number, 1, 2); // 1max(Ord.number, 1, 2); // 2// Range checksclamp(Ord.number, 0, 10, 15); // 10between(Ord.number, 0, 10, 5); // true
Patterns
- Use
Ord.contramapto sort arrays of objects by a specific field. - Use
Ord.structfor lexicographic multi-field ordering (compares fields in order, short-circuits on first difference). - Use
clampto ensure values stay within bounds.