.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / lib / vocabularies / jtd / nullable.ts
1 import type {KeywordCxt} from "../../compile/validate"
2 import {_, not, nil, Code, Name} from "../../compile/codegen"
3
4 export function checkNullable(
5   {gen, data, parentSchema}: KeywordCxt,
6   cond: Code = nil
7 ): [Name, Code] {
8   const valid = gen.name("valid")
9   if (parentSchema.nullable) {
10     gen.let(valid, _`${data} === null`)
11     cond = not(valid)
12   } else {
13     gen.let(valid, false)
14   }
15   return [valid, cond]
16 }
17
18 export function checkNullableObject(cxt: KeywordCxt, cond: Code): [Name, Code] {
19   const [valid, cond_] = checkNullable(cxt, cond)
20   return [valid, _`${cond_} && typeof ${cxt.data} == "object" && !Array.isArray(${cxt.data})`]
21 }