mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-24 08:23:12 +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
|
* Item database
|
||||||
@@ -238,6 +243,7 @@ export class ItemDatabase {
|
|||||||
*/
|
*/
|
||||||
getItemCount(name: string, quality: string): number {
|
getItemCount(name: string, quality: string): number {
|
||||||
checkName(name);
|
checkName(name);
|
||||||
|
checkQuality(quality);
|
||||||
|
|
||||||
if (!this._items.get(name)?.[quality]) {
|
if (!this._items.get(name)?.[quality]) {
|
||||||
return 0;
|
return 0;
|
||||||
@@ -258,6 +264,7 @@ export class ItemDatabase {
|
|||||||
addItem(name: string, count: number, quality: string) {
|
addItem(name: string, count: number, quality: string) {
|
||||||
checkName(name);
|
checkName(name);
|
||||||
checkCount(count);
|
checkCount(count);
|
||||||
|
checkQuality(quality);
|
||||||
|
|
||||||
if (!this._items.has(name)) {
|
if (!this._items.has(name)) {
|
||||||
this._items.set(name, { [quality]: count });
|
this._items.set(name, { [quality]: count });
|
||||||
|
|||||||
Reference in new issue
Block a user