char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
44fe2c6
main
1import { 2Error , 3ObjectCreate , 4ObjectSetPrototypeOf , 5String , 6StringPrototypeToWellFormed , 7TypeError , 8uncurryThis , 9WeakMapPrototypeGet , 10} from "ext:core/primordials" ; 11 12const charCode = uncurryThis ( String . prototype . charCodeAt ); 13 14export function string ( value :unknown ) :string { 15if ( typeof value === "symbol" ) { 16throw new TypeError ( "Cannot convert a Symbol to a string" ); 17} 18return String ( value ); 19} 20export function usv ( value :unknown ) :string { 21return StringPrototypeToWellFormed ( string ( value )); 22} 23export function byteString ( value :unknown ) :string { 24const result = string ( value ); 25for ( let i = 0 ; i < result . length ; i ++ ) { 26if ( charCode ( result , i ) > 255 ) { 27throw new TypeError ( "Expected a ByteString" ); 28} 29} 30return result ; 31} 32export function dictionary ( value :unknown ) :Record < PropertyKey , unknown > { 33if ( value === undefined || value === null ) return ObjectCreate ( null ); 34if ( typeof value !== "object" && typeof value !== "function" ) { 35throw new TypeError ( "Expected an options dictionary" ); 36} 37return value as Record < PropertyKey , unknown >; 38} 39export function isObject ( 40value :unknown , 41) :value isRecord < PropertyKey , unknown > { 42return value !== null && 43( typeof value === "object" || typeof value === "function" ); 44} 45export function required ( count :number , minimum :number ) :void { 46if ( count < minimum ) { 47throw new TypeError ( `Expected at least ${ minimum } argument(s)` ); 48} 49} 50export function state < K extends WeakKey , V > ( 51map :WeakMap < K , V >, 52receiver :unknown , 53) :NonNullable < V > { 54const value = WeakMapPrototypeGet ( map , receiver ); 55if ( ! value ) throw new TypeError ( "Illegal invocation" ); 56return value ; 57} 58export function array < T = unknown > () :T [] { 59const value :T [] = []; 60ObjectSetPrototypeOf ( value , null ); 61return value ; 62} 63export function missing ( feature :string ) :never { 64throw new Error ( `not yet implemented: ${ feature } ` ); 65}