@atproto/syntax: validation helpers for identifier strings
Validation logic for atproto identifiers - DIDs, Handles, NSIDs, and AT URIs.
Usage
Handles
Syntax specification: https://atproto.com/specs/handle
import { isValidHandle, ensureValidHandle, isValidDid } from '@atproto/syntax'
isValidHandle('alice.test')
ensureValidHandle('alice.test')
isValidHandle('al!ce.test')
ensureValidHandle('al!ce.test')
ensureValidDid('did:method:val')
ensureValidDid(':did:method:val')
NameSpaced IDs (NSID)
Syntax specification: https://atproto.com/specs/nsid
import { NSID } from '@atproto/syntax'
const id1 = NSID.parse('com.example.foo')
id1.authority
id1.name
id1.toString()
const id2 = NSID.create('example.com', 'foo')
id2.authority
id2.name
id2.toString()
const id3 = NSID.create('example.com', 'someRecord')
id3.authority
id3.name
id3.toString()
NSID.isValid('com.example.foo')
NSID.isValid('com.example.someRecord')
NSID.isValid('example.com/foo')
NSID.isValid('foo')
AT URI
Syntax specification: https://atproto.com/specs/at-uri-scheme
import { AtUri } from '@atproto/syntax'
const uri = new AtUri('at://bob.com/com.example.post/1234')
uri.protocol
uri.origin
uri.hostname
uri.collection
uri.rkey
License
MIT