UNPKG

1.13 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const util_1 = require("../../compile/util");
5const ucs2length_1 = require("../../runtime/ucs2length");
6const error = {
7 message({ keyword, schemaCode }) {
8 const comp = keyword === "maxLength" ? "more" : "fewer";
9 return (0, codegen_1.str) `must NOT have ${comp} than ${schemaCode} characters`;
10 },
11 params: ({ schemaCode }) => (0, codegen_1._) `{limit: ${schemaCode}}`,
12};
13const def = {
14 keyword: ["maxLength", "minLength"],
15 type: "string",
16 schemaType: "number",
17 $data: true,
18 error,
19 code(cxt) {
20 const { keyword, data, schemaCode, it } = cxt;
21 const op = keyword === "maxLength" ? codegen_1.operators.GT : codegen_1.operators.LT;
22 const len = it.opts.unicode === false ? (0, codegen_1._) `${data}.length` : (0, codegen_1._) `${(0, util_1.useFunc)(cxt.gen, ucs2length_1.default)}(${data})`;
23 cxt.fail$data((0, codegen_1._) `${len} ${op} ${schemaCode}`);
24 },
25};
26exports.default = def;
27//# sourceMappingURL=limitLength.js.map
\No newline at end of file