Things and støff

This commit is contained in:
Kim Ravn Hansen
2025-09-14 20:43:06 +02:00
parent ed91a7f2f7
commit aeb9d776fc
25 changed files with 688 additions and 591 deletions

View File

@@ -12,8 +12,14 @@ export function mustBe(value, ...types) {
return value;
}
const isArray = Array.isArray(value);
if (isArray && (types.includes("any[]") || types.includes("array"))) {
return value;
}
// NOTE: only checks first element of array if it's a string.
if (types.includes("strings[]") && Array.isArray(value) && (value.length === 0 || typeof value[0] === "string")) {
if (isArray && types.includes("strings[]") && (value.length === 0 || typeof value[0] === "string")) {
return value;
}
@@ -24,12 +30,6 @@ export function mustBeString(value) {
return mustBe(value, "string");
}
export function mustBeInteger(value) {
if (typeof value === "number" && Number.isSafeInteger(value)) {
return value;
}
}
/**
*
* @param {string} str