Skip to main content

Function: toAtUri()

toAtUri(uri): null | AtUri

Defined in: src/types/atproto-validators.ts:48

Validates and brands an AT URI string.

Parameters

uri

string

Potential AT URI string

Returns

null | AtUri

Branded AtUri if valid, null otherwise

Remarks

AT URI format: at://did/collection/rkey

Validation rules:

  • Must start with at://
  • DID must be valid (did:method:identifier)
  • Collection must be valid NSID
  • Record key must be non-empty, alphanumeric with periods, underscores, hyphens

This function performs format validation only. It does not verify that the DID exists or that the record is retrievable.

Example

const valid = toAtUri('at://did:plc:abc123/pub.chive.preprint.submission/xyz789');
console.log(valid); // 'at://did:plc:abc123/pub.chive.preprint.submission/xyz789'

const invalid = toAtUri('https://example.com');
console.log(invalid); // null