UNPKG

ts-buildkit

Version:

Typescript Build Kit, this is generic build kit package created by Ahsan Mahmood (https://aoneahsan.com), this package is generic and contains code which will work both on frontend (ReactJs/typescript/etc) as well as on backend (nodejs/typescript/etc). pl

1 lines 975 B
{"version":3,"sources":["../../../src/require-package/zod/index.ts"],"names":["numericEnum","values","ZOD","val","ctx"],"mappings":"qDAQO,SAASA,EACdC,CACA,CAAA,CACA,OAAOC,CAAAA,CAAI,QAAS,CAAA,WAAA,CAAY,CAACC,CAAAA,CAAKC,IAAQ,CACvCH,CAAAA,CAAO,QAASE,CAAAA,CAAG,GACtBC,CAAI,CAAA,QAAA,CAAS,CACX,IAAA,CAAM,gBACN,MAAQ,CAAA,CAAC,GAAGH,CAAM,EAClB,KAAOE,CAAAA,CACT,CAAC,EAEL,CAAC,CACH","file":"index.mjs","sourcesContent":["import { z as ZOD, ZodType } from 'zod';\n\n/**\n * Create a Zod type for a numeric enum.\n *\n * @param {TValues} values - The values of the enum.\n * @returns {ZodType<TValues[number]>} The Zod type for the enum.\n */\nexport function numericEnum<TValues extends readonly number[]>(\n values: TValues\n) {\n return ZOD.number().superRefine((val, ctx) => {\n if (!values.includes(val)) {\n ctx.addIssue({\n code: 'invalid_value',\n values: [...values],\n input: val,\n });\n }\n }) as ZodType<TValues[number]>;\n}\n"]}