zod-opts
Version:
node.js CLI option parser / validator using Zod
37 lines • 1.08 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const zod_1 = require("zod");
// import { parser } from "zod-opts";
const index_1 = require("../src/index");
const parsed = (0, index_1.parser)()
.options({
option1: {
type: zod_1.z.enum(["a", "b"]), // required option. type is "a"|"b"
},
option2: {
type: zod_1.z.enum(["a", "b"]).default("b"), // optional option. type is "a"|"b"
},
option3: {
type: zod_1.z.enum(["a", "b"]).optional(), // optional option. type is "a"|"b"|undefined
},
option4: {
type: zod_1.z.enum(["a", "b"]).default("b").optional(), // optional option. type is "a"|"b"|undefined
},
})
.args([
{
name: "position1",
type: zod_1.z.enum(["a", "b"]), // required arg. type is "a"|"b"
},
])
.parse();
// parsed is inferred as below:
// const parsed: {
// option1: "a" | "b";
// option2: "a" | "b";
// option3?: "a" | "b";
// option4?: "a" | "b";
// position1: "a" | "b";
// };
console.log(parsed);
//# sourceMappingURL=enum.js.map