38 lines
756 B
JavaScript
38 lines
756 B
JavaScript
'use strict';
|
|
|
|
class SharedResources{
|
|
constructor(){
|
|
this.dictionary = {};
|
|
}
|
|
|
|
set( key , val ){
|
|
this.dictionary[ key ] = val;
|
|
}
|
|
|
|
exists( key ){
|
|
return ( this.dictionary[ key ] != undefined );
|
|
}
|
|
|
|
get( key ){
|
|
if( ! this.exists( key ) ){
|
|
throw new Error( `Key [${key}] not defined!` );
|
|
}
|
|
return this.dictionary[ key ];
|
|
}
|
|
|
|
try_get( key ){
|
|
if( ! this.exists( key ) ){
|
|
return null;
|
|
}else{
|
|
return this.dictionary[ key ];
|
|
}
|
|
}
|
|
|
|
remove( key ){
|
|
if( this.exists(key) ){
|
|
delete this.dictionary[ key ];
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = new SharedResources(); |