UNPKG

known-symbols

Version:

A little library for working with well-known symbols.

43 lines (42 loc) 1.2 kB
/* MAIN */ class Symbols { /* CONSTRUCTOR */ constructor() { /* VARIABLES */ this.name2symbol = {}; this.symbol2name = {}; this.names = []; this.symbols = []; /* API */ this.getNames = () => { return this.names; }; this.getSymbols = () => { return this.symbols; }; this.getName = (symbol) => { return this.symbol2name[symbol]; }; this.getSymbol = (name) => { return this.name2symbol[name]; }; this.hasName = (name) => { return name in this.name2symbol; }; this.hasSymbol = (symbol) => { return symbol in this.symbol2name; }; const descriptors = Object.getOwnPropertyDescriptors(Symbol); for (const name in descriptors) { const value = descriptors[name].value; if (typeof value !== 'symbol') continue; this.name2symbol[name] = value; this.symbol2name[value] = name; this.names.push(name); this.symbols.push(value); } } } /* EXPORT */ export default new Symbols();