import { type } from "arktype";
const formScope = type.scope({
"form.number": "string.numeric.parse",
"form.integer": "string.integer.parse",
"form.string": "string > 0",
"form.checkbox": type("true|false|undefined", "=>", (c) => (c === undefined ? false : c)),
"form.date": /^\d{2}\.\d{2}\.\d{4}$/,
"form.year": type(/^\d{4}$/, "=>", (c) => Number.parseInt(c, 10)),
"form.yearmonth": /^\d{2}\/\d{4}$/ ,
"form.yesno.yes": "'yes'",
"form.yesno.no": "'no'",
"form.yesno": ["form.yesno.yes | form.yesno.no", "=>", (c) => c === "yes"],
});
const arkScope = type.scope({
...formScope.export(),
});
const ark = arkScope;
const Thing = ark.type
.or(
ark.type
.or(
{
hasWorkPermit: "form.yesno.yes",
workPermit: {
validUntil: "form.yearmonth",
},
},
{
hasWorkPermit: "form.yesno.no",
},
)
.and({
hasTemporaryResidence: "form.yesno.yes",
temporaryResidence: {
validUntil: "form.yearmonth",
},
}),
{
hasTemporaryResidence: "form.yesno.no",
},
)
.and({
inGermanySince: "form.yearmonth",
});
const out = Thing({})
import { type } from "arktype";
const formScope = type.scope({
"form.number": "string.numeric.parse",
"form.integer": "string.integer.parse",
"form.string": "string > 0",
"form.checkbox": type("true|false|undefined", "=>", (c) => (c === undefined ? false : c)),
"form.date": /^\d{2}\.\d{2}\.\d{4}$/,
"form.year": type(/^\d{4}$/, "=>", (c) => Number.parseInt(c, 10)),
"form.yearmonth": /^\d{2}\/\d{4}$/ ,
"form.yesno.yes": "'yes'",
"form.yesno.no": "'no'",
"form.yesno": ["form.yesno.yes | form.yesno.no", "=>", (c) => c === "yes"],
});
const arkScope = type.scope({
...formScope.export(),
});
const ark = arkScope;
const Thing = ark.type
.or(
ark.type
.or(
{
hasWorkPermit: "form.yesno.yes",
workPermit: {
validUntil: "form.yearmonth",
},
},
{
hasWorkPermit: "form.yesno.no",
},
)
.and({
hasTemporaryResidence: "form.yesno.yes",
temporaryResidence: {
validUntil: "form.yearmonth",
},
}),
{
hasTemporaryResidence: "form.yesno.no",
},
)
.and({
inGermanySince: "form.yearmonth",
});
const out = Thing({})