Skip to content
On this page

Function: latestByCoordinate()

TypeScript
function latestByCoordinate<T>(events: readonly T[]): T[];

Defined in: index.ts:822 (opens in a new tab)

Keep only the latest version of each replaceable event, as NIP-01 says a relay should: per (kind, pubkey, d tag) for addressable kinds 30000–39999, per (kind, pubkey) for kinds 0, 3 and 10000–19999. The highest created_at wins; a tie goes to the lowest id. Other events pass through.

queryEvents de-duplicates by id only, so when relays disagree an old and a new version of the same record arrive side by side. Use this wherever a reader wants the current version.

Type ParametersLink to this section

Type Parameter
T extends NostrEvent

ParametersLink to this section

ParameterType
eventsreadonly T[]

ReturnsLink to this section

T[]