@zsnout/ithkuil
Version:
A set of tools which can generate and parse romanized Ithkuil text and which can generate Ithkuil script from text and JSON data.
30 lines (29 loc) • 679 B
JavaScript
import { ZodType } from "zod";
/** A `ZodType` matching a specific enumerated set of literals. */
export class Enum extends ZodType {
items;
/**
* Constructs an `Enum`.
*
* @param items The items to match against.
* @returns The constructed `Enum`.
*/
constructor(items) {
super({});
this.items = items;
// Object.freeze(this)
}
_parse(input) {
if (this.items.includes(input.data)) {
return {
status: "valid",
value: input.data,
};
}
else {
return {
status: "aborted",
};
}
}
}