mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-14 23:24:52 +09:00
Validate quality parameter
This commit is contained in:
1 parent
19336cdd3b
commit
f907455620
1 file changed
+7
@@ -154,6 +154,11 @@ function checkCount(count: unknown): asserts count is number {
|
||||
}
|
||||
}
|
||||
|
||||
function checkQuality(quality: unknown): asserts quality is string {
|
||||
if (typeof quality !== "string") {
|
||||
throw new Error("quality must be a string");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item database
|
||||
@@ -238,6 +243,7 @@ export class ItemDatabase {
|
||||
*/
|
||||
getItemCount(name: string, quality: string): number {
|
||||
checkName(name);
|
||||
checkQuality(quality);
|
||||
|
||||
if (!this._items.get(name)?.[quality]) {
|
||||
return 0;
|
||||
@@ -258,6 +264,7 @@ export class ItemDatabase {
|
||||
addItem(name: string, count: number, quality: string) {
|
||||
checkName(name);
|
||||
checkCount(count);
|
||||
checkQuality(quality);
|
||||
|
||||
if (!this._items.has(name)) {
|
||||
this._items.set(name, { [quality]: count });
|
||||
|
||||
Reference in new issue
Block a user