json-schema-library
Version:
Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
25 lines (24 loc) • 647 B
JavaScript
import ucs2decode from "../utils/punycode.ucs2decode";
export const minLengthKeyword = {
id: "minLength",
keyword: "minLength",
addValidate: ({ schema }) => !isNaN(schema.minLength),
validate: validateMinLength
};
function validateMinLength({ node, data, pointer = "#" }) {
if (typeof data !== "string") {
return;
}
const { schema } = node;
const length = ucs2decode(data).length;
if (schema.minLength <= length) {
return;
}
return node.createError("min-length-error", {
minLength: schema.minLength,
length,
pointer,
schema,
value: data
});
}