import { ReadonlyCollection , Collection , ReadonlyKeyedCollection , KeyedCollection , ReadonlyIndexedCollection , IndexedCollection , FixedSizeIndexedCollection } from "@esfx/collection-core" ; const accessorBase = { enumerable : false , configurable : true } ; const methodBase = { ... accessorBase , writable : true } ; declare global { interface ReadonlyArray < T > extends ReadonlyIndexedCollection < T > { } interface Array < T > extends IndexedCollection < T > { } } Object . defineProperties ( Array . prototype , { [ Collection . size ] : { ... accessorBase , get ( this ) { return this . length ; } } , [ Collection . has ] : { ... methodBase , value ( this , value ) { return this . includes ( value ) ; } } , [ Collection . add ] : { ... methodBase , value ( this , value ) { this . push ( value ) ; } } , [ Collection . delete ] : { ... methodBase , value ( this , value ) { const index = this . indexOf ( value ) ; if ( index >= 0 ) { this . splice ( index , 1 ) ; return true ; } return false ; } } , [ Collection . clear ] : { ... methodBase , value ( this ) { this . length = 0 ; } } , [ IndexedCollection . indexOf ] : { ... methodBase , value ( this , value , fromIndex ? ) { return this . indexOf ( value , fromIndex ) ; } } , [ IndexedCollection . getAt ] : { ... methodBase , value ( this , index ) { return this [ index ] ; } } , [ IndexedCollection . setAt ] : { ... methodBase , value ( this , index , value ) { this [ index ] = value ; return true ; } } , [ IndexedCollection . insertAt ] : { ... methodBase , value ( this , index , value ) { this . splice ( index , 0 , value ) ; } } , [ IndexedCollection . removeAt ] : { ... methodBase , value ( this , index ) { this . splice ( index , 1 ) ; } } , } ) ; declare global { interface Uint8Array extends FixedSizeIndexedCollection < number > { } interface Uint8ClampedArray extends FixedSizeIndexedCollection < number > { } interface Uint16Array extends FixedSizeIndexedCollection < number > { } interface Uint32Array extends FixedSizeIndexedCollection < number > { } interface Int8Array extends FixedSizeIndexedCollection < number > { } interface Int16Array extends FixedSizeIndexedCollection < number > { } interface Int32Array extends FixedSizeIndexedCollection < number > { } interface Float32Array extends FixedSizeIndexedCollection < number > { } interface Float64Array extends FixedSizeIndexedCollection < number > { } interface BigUint64Array extends FixedSizeIndexedCollection < bigint > { } interface BigInt64Array extends FixedSizeIndexedCollection < bigint > { } } const typedArrays = typeof Uint8Array !== "function" ? [ ] : [ Uint8Array , Uint8ClampedArray , Uint16Array , Uint32Array , Int8Array , Int16Array , Int32Array , Float32Array , Float64Array ] ; for ( const TypedArray of typedArrays ) { Object . defineProperties ( TypedArray . prototype , { [ Collection . size ] : { ... accessorBase , get ( this ) { return this . length ; } } , [ Collection . has ] : { ... methodBase , value ( this , value ) { return this . includes ( value ) ; } } , [ IndexedCollection . indexOf ] : { ... methodBase , value ( this , value , fromIndex ? ) { return this . indexOf ( value , fromIndex ) ; } } , [ IndexedCollection . getAt ] : { ... methodBase , value ( this , index ) { return this [ index ] ; } } , [ IndexedCollection . setAt ] : { ... methodBase , value ( this , index , value ) { if ( index >= 0 && index < this . length ) { this [ index ] = value ; return true ; } return false ; } } , } ) ; } const bigIntTypedArrays = typeof BigInt64Array !== "function" ? [ ] : [ BigUint64Array , BigInt64Array ] ; for ( const TypedArray of bigIntTypedArrays ) { Object . defineProperties ( TypedArray . prototype , { [ Collection . size ] : { ... accessorBase , get ( this ) { return this . length ; } } , [ Collection . has ] : { ... methodBase , value ( this , value ) { return this . includes ( value ) ; } } , [ IndexedCollection . indexOf ] : { ... methodBase , value ( this , value , fromIndex ? ) { return this . indexOf ( value , fromIndex ) ; } } , [ IndexedCollection . getAt ] : { ... methodBase , value ( this , index ) { return this [ index ] ; } } , [ IndexedCollection . setAt ] : { ... methodBase , value ( this , index , value ) { if ( index >= 0 && index < this . length ) { this [ index ] = value ; return true ; } return false ; } } , } ) ; } declare global { interface ReadonlySet < T > extends ReadonlyCollection < T > { } interface Set < T > extends Collection < T > { } } if ( typeof Set === "function" ) { Object . defineProperties ( Set . prototype , { [ Collection . size ] : { ... accessorBase , get ( this ) { return this . size ; } } , [ Collection . has ] : { ... methodBase , value ( this , value ) { return this . has ( value ) ; } } , [ Collection . add ] : { ... methodBase , value ( this , value ) { this . add ( value ) ; } } , [ Collection . delete ] : { ... methodBase , value ( this , value ) { return this . delete ( value ) ; } } , [ Collection . clear ] : { ... methodBase , value ( this ) { this . clear ( ) ; } } } ) ; } declare global { interface ReadonlyMap < K , V > extends ReadonlyKeyedCollection < K , V > { } interface Map < K , V > extends KeyedCollection < K , V > { } } if ( typeof Map === "function" ) { Object . defineProperties ( Map . prototype , { [ KeyedCollection . size ] : { ... accessorBase , get ( this ) { return this . size ; } } , [ KeyedCollection . has ] : { ... methodBase , value ( this , key ) { return this . has ( key ) ; } } , [ KeyedCollection . get ] : { ... methodBase , value ( this , key ) { return this . get ( key ) ; } } , [ KeyedCollection . keys ] : { ... methodBase , value ( this ) { return this . keys ( ) ; } } , [ KeyedCollection . values ] : { ... methodBase , value ( this ) { return this . values ( ) ; } } , [ KeyedCollection . set ] : { ... methodBase , value ( this , key , value ) { this . set ( key , value ) ; } } , [ KeyedCollection . delete ] : { ... methodBase , value ( this , key ) { return this . delete ( key ) ; } } , [ KeyedCollection . clear ] : { ... methodBase , value ( this ) { this . clear ( ) ; } } , } ) ; }