CharacterIdMap.js 670 B

1234567
  1. export class CharacterIdMap{constructor(){this._elementToCharacter=new Map();this._characterToElement=new Map();this._charCode=33;}
  2. toChar(object){let character=this._elementToCharacter.get(object);if(!character){if(this._charCode>=0xFFFF){throw new Error('CharacterIdMap ran out of capacity!');}
  3. character=String.fromCharCode(this._charCode++);this._elementToCharacter.set(object,character);this._characterToElement.set(character,object);}
  4. return character;}
  5. fromChar(character){const object=this._characterToElement.get(character);if(object===undefined){return null;}
  6. return object;}}
  7. self.Common=self.Common||{};Common=Common||{};Common.CharacterIdMap=CharacterIdMap;