Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
28 lines
746 B
Plaintext
28 lines
746 B
Plaintext
import type {CodeKeywordDefinition, KeywordCxt} from "ajv"
|
|
import {_} from "ajv/dist/compile/codegen"
|
|
|
|
const TYPES = ["undefined", "string", "number", "object", "function", "boolean", "symbol"]
|
|
|
|
export default function getDef(): CodeKeywordDefinition {
|
|
return {
|
|
keyword: "typeof",
|
|
schemaType: ["string", "array"],
|
|
code(cxt: KeywordCxt) {
|
|
const {data, schema, schemaValue} = cxt
|
|
cxt.fail(
|
|
typeof schema == "string"
|
|
? _`typeof ${data} != ${schema}`
|
|
: _`${schemaValue}.indexOf(typeof ${data}) < 0`
|
|
)
|
|
},
|
|
metaSchema: {
|
|
anyOf: [
|
|
{type: "string", enum: TYPES},
|
|
{type: "array", items: {type: "string", enum: TYPES}},
|
|
],
|
|
},
|
|
}
|
|
}
|
|
|
|
module.exports = getDef
|