All files / tcb-admin-node/src/database/utils symbol.ts

85.71% Statements 12/14
50% Branches 2/4
100% Functions 3/3
85.71% Lines 12/14
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 493x 3x         21x                     3x     21x       21x         21x 63x         21x   21x         21x       3x    
const _symbols: { target: any, instance: InternalSymbol }[] = []
const __internalMark__ = {}
 
class HiddenSymbol {
 
  constructor(target: any) {
    Object.defineProperties(this, {
      target: {
        enumerable: false,
        writable: false,
        configurable: false,
        value: target,
      },
    })
  }
}
 
export class InternalSymbol extends HiddenSymbol {
 
  constructor(target: any, __mark__: any) {
    Iif (__mark__ !== __internalMark__) {
      throw new TypeError('InternalSymbol cannot be constructed with new operator')
    }
 
    super(target)
  }
 
  static for(target: any) {
 
    for (let i = 0, len = _symbols.length; i < len; i++) {
      Iif (_symbols[i].target === target) {
        return _symbols[i].instance
      }
    }
 
    const symbol = new InternalSymbol(target, __internalMark__)
 
    _symbols.push({
      target, 
      instance: symbol,
    })
 
    return symbol
  }
}
 
export default InternalSymbol