cerulea/lexicon
define atproto schemas in TypeScript
git clone https://git.t4t.associates/cerulea/lexicon
1945441
main
1export function assert ( value :unknown , message = "Assertion failed" ) : assertsvalue { 2if ( ! value ) throw new Error ( message ); 3} 4 5export function equal ( actual :unknown , expected :unknown ) :void { 6const canonical = ( value :unknown ) :string | undefined => 7JSON . stringify ( 8value , 9( _ , item ) => 10item !== null && typeof item === "object" && ! Array . isArray ( item ) 11 ?Object . fromEntries ( Object . entries ( item ). sort (([ a ], [ b ]) => a < b ?- 1 :a > b ?1 :0 )) 12 :item , 13); 14assert ( 15canonical ( actual ) === canonical ( expected ), 16`Expected:\n ${ Deno . inspect ( expected , { depth : Infinity })} \nReceived:\n ${ 17Deno . inspect ( actual , { depth : Infinity }) 18} ` , 19); 20} 21 22export function throws ( fn :() => unknown , message :string ) :void { 23try { 24fn (); 25} catch ( error ) { 26assert ( error instanceof Error && error . message . includes ( message ), `Unexpected error: ${ error } ` ); 27return ; 28} 29throw new Error ( `Expected an error containing ${ JSON . stringify ( message )} ` ); 30}