Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995834
config-manager.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
config-manager.ts
View Options
import
{
getProperty
,
setProperty
}
from
"dot-prop"
;
import
merge
from
"deepmerge"
;
import
type
Config
from
"./config.js"
;
type
ConfigObject
=
{
[
key
:
string
]
:
any
};
export
default
class
ConfigManager
{
DEFAULT_CONFIG
:
ConfigObject
;
CUSTOM_CONFIG
:
ConfigObject
;
isLocked
:
boolean
;
constructor
()
{
this
.
DEFAULT_CONFIG
=
{};
this
.
CUSTOM_CONFIG
=
{};
this
.
isLocked
=
false
;
}
setDefault
(
key
:
string
,
value
:
any
)
{
this
.
_setGivenConfig
(
this
.
DEFAULT_CONFIG
,
key
,
value
);
}
getDefaultConfig
(
key
:
string
)
{
return
getProperty
(
this
.
DEFAULT_CONFIG
,
key
);
}
set
(
key
:
string
,
value
:
any
)
{
this
.
_setGivenConfig
(
this
.
CUSTOM_CONFIG
,
key
,
value
);
}
_setGivenConfig
(
config
:
ConfigObject
,
key
:
string
,
value
:
any
)
{
this
.
_warnIfLocked
();
setProperty
(
config
,
key
,
value
);
}
_warnIfLocked
()
{
if
(
this
.
isLocked
)
{
console
.
warn
(
"Warning: "
+
"you shouldn't change config after ConfigManager was locked"
);
}
}
setRoot
(
params
:
ConfigObject
)
{
this
.
_warnIfLocked
();
this
.
CUSTOM_CONFIG
=
merge
(
this
.
CUSTOM_CONFIG
,
params
);
}
get
<
Key
extends
keyof
Config
>
(
key
:
Key
)
:
Config
[
Key
]
{
return
getProperty
(
merge
(
this
.
DEFAULT_CONFIG
,
this
.
CUSTOM_CONFIG
),
key
)
as
Config
[
Key
];
}
lock
()
{
this
.
isLocked
=
true
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Mon, Dec 23, 21:35 (1 d, 4 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
555733
Default Alt Text
config-manager.ts (1 KB)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment