@esfx/indexed-object Package

    Provides a base class for custom integer-indexed collections.

    The underlying implementation uses a Proxy to trap integer indexes in a fashion similar to the Integer-Indexed Exotic Object in the ECMAScript specification.

    Installation

    npm i @esfx/indexed-object
    

    Usage

    • TypeScript
    • JavaScript (CommonJS)
    import { IntegerIndexedObject } from "@esfx/indexed-object";
    
    class BooleansCollection extends IntegerIndexedObject<boolean> {
        protected getLength() {
            return 2;
        }
        protected getIndex(index: number) {
            switch (index) {
                case 0: return false;
                case 1: return true;
                default: return undefined;
            }
        }
        // hasIndex(index): boolean
        // setIndex(index, value): boolean
        // deleteIndex(index): boolean
    }
    
    const booleans = new BooleansCollection();
    console.log(booleans[0]); // false
    console.log(booleans[1]); // true
    
    const { IntegerIndexedObject } = require("@esfx/indexed-object");
    
    class BooleansCollection extends IntegerIndexedObject {
        /** @protected */
        getLength() {
            return 2;
        }
        /** @protected */
        getIndex(index) {
            switch (index) {
                case 0: return false;
                case 1: return true;
                default: return undefined;
            }
        }
        // hasIndex(index): boolean
        // setIndex(index, value): boolean
        // deleteIndex(index): boolean
    }
    
    const booleans = new BooleansCollection();
    console.log(booleans[0]); // false
    console.log(booleans[1]); // true
    

    Classes

    IntegerIndexedObject

    Represents an object that can be indexed by an integer value similar to a native Array or TypedArray.

    • Improve this Doc
    Generated by DocFX