All files util.ts

92.86% Statements 13/14
66.67% Branches 4/6
100% Functions 3/3
92.31% Lines 12/13

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33              1x         1x 1x   1x 4x 4x         1x 367x   367x 135x     232x   1x  
// A good case for generics, but javascript has strict
// requirements on what consists of a hashable type.
// It's not even worth it tbh
interface StringHashMap {
    [index: string]: string;
}
 
export class Inverter {
    private obj: StringHashMap;
    private rev_obj: StringHashMap;
 
    constructor(obj: object) {
        this.obj = obj as StringHashMap;
        this.rev_obj = {} as StringHashMap;
 
        for (const attr in obj) {
            Eif (obj.hasOwnProperty(attr)) {
                this.rev_obj[obj[attr]] = attr;
            }
        }
    }
 
    public get(key: string): string {
        Iif (this.obj[key] !== undefined) {
            return this.obj[key];
        } else if (this.rev_obj[key] !== undefined) {
            return this.rev_obj[key];
        }
 
        return undefined;
    }
}