1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const code_1 = require("../code");
|
4 | const codegen_1 = require("../../compile/codegen");
|
5 | const error = {
|
6 | message: ({ schemaCode }) => (0, codegen_1.str) `must match pattern "${schemaCode}"`,
|
7 | params: ({ schemaCode }) => (0, codegen_1._) `{pattern: ${schemaCode}}`,
|
8 | };
|
9 | const 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 |
|
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 | };
|
23 | exports.default = def;
|
24 |
|
\ | No newline at end of file |