UNPKG

905 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const code_1 = require("../code");
4const codegen_1 = require("../../compile/codegen");
5const error = {
6 message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
7 params: ({ schemaCode }) => (0, codegen_1._) `{pattern: ${schemaCode}}`,
8};
9const def = {
10 keyword: "pattern",
11 type: "string",
12 schemaType: "string",
13 $data: true,
14 error,
15 code(cxt) {
16 const { data, $data, schema, schemaCode, it } = cxt;
17 // TODO regexp should be wrapped in try/catchs
18 const u = it.opts.unicodeRegExp ? "u" : "";
19 const regExp = $data ? (0, codegen_1._) `(new RegExp(${schemaCode}, ${u}))` : (0, code_1.usePattern)(cxt, schema);
20 cxt.fail$data((0, codegen_1._) `!${regExp}.test(${data})`);
21 },
22};
23exports.default = def;
24//# sourceMappingURL=pattern.js.map
\No newline at end of file